blob: 34baf795b00957f4a48f28b0f5797fe9734d86a2 [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001/*
2 * ckconfig.c
3 *
4 * Copyright (C) 1991-1994, Thomas G. Lane.
5 * This file is part of the Independent JPEG Group's software.
6 * For conditions of distribution and use, see the accompanying README file.
7 */
8
9/*
10 * This program is intended to help you determine how to configure the JPEG
11 * software for installation on a particular system. The idea is to try to
12 * compile and execute this program. If your compiler fails to compile the
13 * program, make changes as indicated in the comments below. Once you can
14 * compile the program, run it, and it will produce a "jconfig.h" file for
15 * your system.
16 *
17 * As a general rule, each time you try to compile this program,
18 * pay attention only to the *first* error message you get from the compiler.
19 * Many C compilers will issue lots of spurious error messages once they
20 * have gotten confused. Go to the line indicated in the first error message,
21 * and read the comments preceding that line to see what to change.
22 *
23 * Almost all of the edits you may need to make to this program consist of
24 * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL",
25 * or vice versa. This is called defining or undefining that symbol.
26 */
27
28
29/* First we must see if your system has the include files we need.
30 * We start out with the assumption that your system has all the ANSI-standard
31 * include files. If you get any error trying to include one of these files,
32 * undefine the corresponding HAVE_xxx symbol.
33 */
34
35#define HAVE_STDDEF_H /* replace 'define' by 'undef' if error here */
36#ifdef HAVE_STDDEF_H /* next line will be skipped if you undef... */
37#include <stddef.h>
38#endif
39
40#define HAVE_STDLIB_H /* same thing for stdlib.h */
41#ifdef HAVE_STDLIB_H
42#include <stdlib.h>
43#endif
44
45#include <stdio.h> /* If you ain't got this, you ain't got C. */
46
47/* We have to see if your string functions are defined by
48 * strings.h (old BSD convention) or string.h (everybody else).
49 * We try the non-BSD convention first; define NEED_BSD_STRINGS
50 * if the compiler says it can't find string.h.
51 */
52
53#undef NEED_BSD_STRINGS
54
55#ifdef NEED_BSD_STRINGS
56#include <strings.h>
57#else
58#include <string.h>
59#endif
60
61/* On some systems (especially older Unix machines), type size_t is
62 * defined only in the include file <sys/types.h>. If you get a failure
63 * on the size_t test below, try defining NEED_SYS_TYPES_H.
64 */
65
66#undef NEED_SYS_TYPES_H /* start by assuming we don't need it */
67#ifdef NEED_SYS_TYPES_H
68#include <sys/types.h>
69#endif
70
71
72/* Usually type size_t is defined in one of the include files we've included
73 * above. If not, you'll get an error on the "typedef size_t my_size_t;" line.
74 * In that case, first try defining NEED_SYS_TYPES_H just above.
75 * If that doesn't work, you'll have to search through your system library
76 * to figure out which include file defines "size_t". Look for a line that
77 * says "typedef something-or-other size_t;". Then, change the line below
78 * that says "#include <someincludefile.h>" to instead include the file
79 * you found size_t in, and define NEED_SPECIAL_INCLUDE. If you can't find
80 * type size_t anywhere, try replacing "#include <someincludefile.h>" with
81 * "typedef unsigned int size_t;".
82 */
83
84#undef NEED_SPECIAL_INCLUDE /* assume we DON'T need it, for starters */
85
86#ifdef NEED_SPECIAL_INCLUDE
87#include <someincludefile.h>
88#endif
89
90typedef size_t my_size_t; /* The payoff: do we have size_t now? */
91
92
93/* The next question is whether your compiler supports ANSI-style function
94 * prototypes. You need to know this in order to choose between using
95 * makefile.ansi and using makefile.unix.
96 * The #define line below is set to assume you have ANSI function prototypes.
97 * If you get an error in this group of lines, undefine HAVE_PROTOTYPES.
98 */
99
100#define HAVE_PROTOTYPES
101
102#ifdef HAVE_PROTOTYPES
103int testfunction (int arg1, int * arg2); /* check prototypes */
104
105struct methods_struct { /* check method-pointer declarations */
106 int (*error_exit) (char *msgtext);
107 int (*trace_message) (char *msgtext);
108 int (*another_method) (void);
109};
110
111int testfunction (int arg1, int * arg2) /* check definitions */
112{
113 return arg2[arg1];
114}
115
116int test2function (void) /* check void arg list */
117{
118 return 0;
119}
120#endif
121
122
123/* Now we want to find out if your compiler knows what "unsigned char" means.
124 * If you get an error on the "unsigned char un_char;" line,
125 * then undefine HAVE_UNSIGNED_CHAR.
126 */
127
128#define HAVE_UNSIGNED_CHAR
129
130#ifdef HAVE_UNSIGNED_CHAR
131unsigned char un_char;
132#endif
133
134
135/* Now we want to find out if your compiler knows what "unsigned short" means.
136 * If you get an error on the "unsigned short un_short;" line,
137 * then undefine HAVE_UNSIGNED_SHORT.
138 */
139
140#define HAVE_UNSIGNED_SHORT
141
142#ifdef HAVE_UNSIGNED_SHORT
143unsigned short un_short;
144#endif
145
146
147/* Now we want to find out if your compiler understands type "void".
148 * If you get an error anywhere in here, undefine HAVE_VOID.
149 */
150
151#define HAVE_VOID
152
153#ifdef HAVE_VOID
154/* Caution: a C++ compiler will insist on complete prototypes */
155typedef void * void_ptr; /* check void * */
156#ifdef HAVE_PROTOTYPES /* check ptr to function returning void */
157typedef void (*void_func) (int a, int b);
158#else
159typedef void (*void_func) ();
160#endif
161
162#ifdef HAVE_PROTOTYPES /* check void function result */
163void test3function (void_ptr arg1, void_func arg2)
164#else
165void test3function (arg1, arg2)
166 void_ptr arg1;
167 void_func arg2;
168#endif
169{
170 char * locptr = (char *) arg1; /* check casting to and from void * */
171 arg1 = (void *) locptr;
172 (*arg2) (1, 2); /* check call of fcn returning void */
173}
174#endif
175
176
177/* Now we want to find out if your compiler knows what "const" means.
178 * If you get an error here, undefine HAVE_CONST.
179 */
180
181#define HAVE_CONST
182
183#ifdef HAVE_CONST
184static const int carray[3] = {1, 2, 3};
185
186#ifdef HAVE_PROTOTYPES
187int test4function (const int arg1)
188#else
189int test4function (arg1)
190 const int arg1;
191#endif
192{
193 return carray[arg1];
194}
195#endif
196
197
198/* If you get an error or warning about this structure definition,
199 * define INCOMPLETE_TYPES_BROKEN.
200 */
201
202#undef INCOMPLETE_TYPES_BROKEN
203
204#ifndef INCOMPLETE_TYPES_BROKEN
205typedef struct undefined_structure * undef_struct_ptr;
206#endif
207
208
209/* If you get an error about duplicate names,
210 * define NEED_SHORT_EXTERNAL_NAMES.
211 */
212
213#undef NEED_SHORT_EXTERNAL_NAMES
214
215#ifndef NEED_SHORT_EXTERNAL_NAMES
216
217int possibly_duplicate_function ()
218{
219 return 0;
220}
221
222int possibly_dupli_function ()
223{
224 return 1;
225}
226
227#endif
228
229
230
231/************************************************************************
232 * OK, that's it. You should not have to change anything beyond this
233 * point in order to compile and execute this program. (You might get
234 * some warnings, but you can ignore them.)
235 * When you run the program, it will make a couple more tests that it
236 * can do automatically, and then it will create jconfig.h and print out
237 * any additional suggestions it has.
238 ************************************************************************
239 */
240
241
242#ifdef HAVE_PROTOTYPES
243int is_char_signed (int arg)
244#else
245int is_char_signed (arg)
246 int arg;
247#endif
248{
249 if (arg == 189) { /* expected result for unsigned char */
250 return 0; /* type char is unsigned */
251 }
252 else if (arg != -67) { /* expected result for signed char */
253 printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");
254 printf("I fear the JPEG software will not work at all.\n\n");
255 }
256 return 1; /* assume char is signed otherwise */
257}
258
259
260#ifdef HAVE_PROTOTYPES
261int is_shifting_signed (long arg)
262#else
263int is_shifting_signed (arg)
264 long arg;
265#endif
266/* See whether right-shift on a long is signed or not. */
267{
268 long res = arg >> 4;
269
270 if (res == -0x7F7E80CL) { /* expected result for signed shift */
271 return 1; /* right shift is signed */
272 }
273 /* see if unsigned-shift hack will fix it. */
274 /* we can't just test exact value since it depends on width of long... */
275 res |= (~0L) << (32-4);
276 if (res == -0x7F7E80CL) { /* expected result now? */
277 return 0; /* right shift is unsigned */
278 }
279 printf("Right shift isn't acting as I expect it to.\n");
280 printf("I fear the JPEG software will not work at all.\n\n");
281 return 0; /* try it with unsigned anyway */
282}
283
284
285#ifdef HAVE_PROTOTYPES
286int main (int argc, char ** argv)
287#else
288int main (argc, argv)
289 int argc;
290 char ** argv;
291#endif
292{
293 char signed_char_check = (char) (-67);
294 FILE *outfile;
295
296 /* Attempt to write jconfig.h */
297 if ((outfile = fopen("jconfig.h", "w")) == NULL) {
298 printf("Failed to write jconfig.h\n");
299 return 1;
300 }
301
302 /* Write out all the info */
303 fprintf(outfile, "/* jconfig.h --- generated by ckconfig.c */\n");
304 fprintf(outfile, "/* see jconfig.doc for explanations */\n\n");
305#ifdef HAVE_PROTOTYPES
306 fprintf(outfile, "#define HAVE_PROTOTYPES\n");
307#else
308 fprintf(outfile, "#undef HAVE_PROTOTYPES\n");
309#endif
310#ifdef HAVE_UNSIGNED_CHAR
311 fprintf(outfile, "#define HAVE_UNSIGNED_CHAR\n");
312#else
313 fprintf(outfile, "#undef HAVE_UNSIGNED_CHAR\n");
314#endif
315#ifdef HAVE_UNSIGNED_SHORT
316 fprintf(outfile, "#define HAVE_UNSIGNED_SHORT\n");
317#else
318 fprintf(outfile, "#undef HAVE_UNSIGNED_SHORT\n");
319#endif
320#ifdef HAVE_VOID
321 fprintf(outfile, "/* #define void char */\n");
322#else
323 fprintf(outfile, "#define void char\n");
324#endif
325#ifdef HAVE_CONST
326 fprintf(outfile, "/* #define const */\n");
327#else
328 fprintf(outfile, "#define const\n");
329#endif
330 if (is_char_signed((int) signed_char_check))
331 fprintf(outfile, "#undef CHAR_IS_UNSIGNED\n");
332 else
333 fprintf(outfile, "#define CHAR_IS_UNSIGNED\n");
334#ifdef HAVE_STDDEF_H
335 fprintf(outfile, "#define HAVE_STDDEF_H\n");
336#else
337 fprintf(outfile, "#undef HAVE_STDDEF_H\n");
338#endif
339#ifdef HAVE_STDLIB_H
340 fprintf(outfile, "#define HAVE_STDLIB_H\n");
341#else
342 fprintf(outfile, "#undef HAVE_STDLIB_H\n");
343#endif
344#ifdef NEED_BSD_STRINGS
345 fprintf(outfile, "#define NEED_BSD_STRINGS\n");
346#else
347 fprintf(outfile, "#undef NEED_BSD_STRINGS\n");
348#endif
349#ifdef NEED_SYS_TYPES_H
350 fprintf(outfile, "#define NEED_SYS_TYPES_H\n");
351#else
352 fprintf(outfile, "#undef NEED_SYS_TYPES_H\n");
353#endif
354 fprintf(outfile, "#undef NEED_FAR_POINTERS\n");
355#ifdef NEED_SHORT_EXTERNAL_NAMES
356 fprintf(outfile, "#define NEED_SHORT_EXTERNAL_NAMES\n");
357#else
358 fprintf(outfile, "#undef NEED_SHORT_EXTERNAL_NAMES\n");
359#endif
360#ifdef INCOMPLETE_TYPES_BROKEN
361 fprintf(outfile, "#define INCOMPLETE_TYPES_BROKEN\n");
362#else
363 fprintf(outfile, "#undef INCOMPLETE_TYPES_BROKEN\n");
364#endif
365 fprintf(outfile, "\n#ifdef JPEG_INTERNALS\n\n");
366 if (is_shifting_signed(-0x7F7E80B1L))
367 fprintf(outfile, "#undef RIGHT_SHIFT_IS_UNSIGNED\n");
368 else
369 fprintf(outfile, "#define RIGHT_SHIFT_IS_UNSIGNED\n");
370 fprintf(outfile, "\n#endif /* JPEG_INTERNALS */\n");
371 fprintf(outfile, "\n#ifdef JPEG_CJPEG_DJPEG\n\n");
372 fprintf(outfile, "#define BMP_SUPPORTED /* BMP image file format */\n");
373 fprintf(outfile, "#define GIF_SUPPORTED /* GIF image file format */\n");
374 fprintf(outfile, "#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */\n");
375 fprintf(outfile, "#undef RLE_SUPPORTED /* Utah RLE image file format */\n");
376 fprintf(outfile, "#define TARGA_SUPPORTED /* Targa image file format */\n\n");
377 fprintf(outfile, "#undef TWO_FILE_COMMANDLINE /* You may need this on non-Unix systems */\n");
378 fprintf(outfile, "#undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */\n");
379 fprintf(outfile, "#undef DONT_USE_B_MODE\n");
380 fprintf(outfile, "/* #define PROGRESS_REPORT */ /* optional */\n");
381 fprintf(outfile, "\n#endif /* JPEG_CJPEG_DJPEG */\n");
382
383 /* Close the jconfig.h file */
384 fclose(outfile);
385
386 /* User report */
387 printf("Configuration check for Independent JPEG Group's software done.\n");
388 printf("\nI have written the jconfig.h file for you.\n\n");
389#ifdef HAVE_PROTOTYPES
390 printf("You should use makefile.ansi as the starting point for your Makefile.\n");
391#else
392 printf("You should use makefile.unix as the starting point for your Makefile.\n");
393#endif
394
395#ifdef NEED_SPECIAL_INCLUDE
396 printf("\nYou'll need to change jconfig.h to include the system include file\n");
397 printf("that you found type size_t in, or add a direct definition of type\n");
398 printf("size_t if that's what you used. Just add it to the end.\n");
399#endif
400
401 return 0;
402}