ckconfig.c 12 KB

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