home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / compresn / jpegv3sr / ckconfig.c < prev    next >
C/C++ Source or Header  |  1992-03-07  |  13KB  |  404 lines

  1. /*
  2.  * ckconfig.c
  3.  *
  4.  * Copyright (C) 1991, 1992, 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 tell you how to set the various
  15.  * switches in jconfig.h and in your Makefile.
  16.  *
  17.  * This could all be done automatically if we could assume we were on a Unix
  18.  * system, but we don't want to assume that, so you'll have to edit and
  19.  * recompile this program until it works.
  20.  *
  21.  * As a general rule, each time you try to compile this program,
  22.  * pay attention only to the *first* error message you get from the compiler.
  23.  * Many C compilers will issue lots of spurious error messages once they
  24.  * have gotten confused.  Go to the line indicated in the first error message,
  25.  * and read the comments preceding that line to see what to change.
  26.  *
  27.  * Almost all of the edits you may need to make to this program consist of
  28.  * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL",
  29.  * or vice versa.  This is called defining or undefining that symbol.
  30.  */
  31.  
  32.  
  33. /* First we must see if your system has the include files we need.
  34.  * We start out with the assumption that your system follows the ANSI
  35.  * conventions for include files.  If you get any error in the next dozen
  36.  * lines, undefine INCLUDES_ARE_ANSI.
  37.  */
  38.  
  39. #define INCLUDES_ARE_ANSI    /* replace 'define' by 'undef' if error here */
  40.  
  41. #ifdef INCLUDES_ARE_ANSI    /* this will be skipped if you undef... */
  42. #include <stdio.h>        /* If you ain't got this, you ain't got C. */
  43. #ifdef __SASC            /* Amiga SAS C provides size_t in stddef.h. */
  44. #include <stddef.h>        /* (They are wrong...) */
  45. #endif
  46. #include <string.h>        /* size_t might be here too. */
  47. typedef size_t my_size_t;    /* The payoff: do we have size_t now? */
  48. #include <stdlib.h>        /* Check other ANSI includes we use. */
  49. #endif
  50.  
  51.  
  52. /* If your system doesn't follow the ANSI conventions, we have to figure out
  53.  * what it does follow.  If you didn't get an error before this line, you can
  54.  * ignore everything down to "#define HAVE_ANSI_DEFINITIONS".
  55.  */
  56.  
  57. #ifndef INCLUDES_ARE_ANSI    /* skip these tests if INCLUDES_ARE_ANSI */
  58.  
  59. #include <stdio.h>        /* If you ain't got this, you ain't got C. */
  60.  
  61. /* jinclude.h will try to include <sys/types.h> if you don't set
  62.  * INCLUDES_ARE_ANSI.  We need to test whether that include file is provided.
  63.  * If you get an error here, undefine HAVE_TYPES_H.
  64.  */
  65.  
  66. #define HAVE_TYPES_H
  67.  
  68. #ifdef HAVE_TYPES_H
  69. #include <sys/types.h>
  70. #endif
  71.  
  72. /* We have to see if your string functions are defined by
  73.  * strings.h (BSD convention) or string.h (everybody else).
  74.  * We try the non-BSD convention first; define BSD if the compiler
  75.  * says it can't find string.h.
  76.  */
  77.  
  78. #undef BSD
  79.  
  80. #ifdef BSD
  81. #include <strings.h>
  82. #else
  83. #include <string.h>
  84. #endif
  85.  
  86. /* Usually size_t is defined in stdio.h, sys/types.h, and/or string.h.
  87.  * If not, you'll get an error on the "typedef size_t my_size_t;" line below.
  88.  * In that case, you'll have to search through your system library to
  89.  * figure out which include file defines "size_t".  Look for a line that
  90.  * says "typedef something-or-other size_t;" (stddef.h and stdlib.h are
  91.  * good places to look first).  Then, change the line below that says
  92.  * "#include <someincludefile.h>" to instead include the file
  93.  * you found size_t in, and define NEED_SPECIAL_INCLUDE.
  94.  */
  95.  
  96. #undef NEED_SPECIAL_INCLUDE    /* assume we DON'T need it, for starters */
  97.  
  98. #ifdef NEED_SPECIAL_INCLUDE
  99. #include <someincludefile.h>
  100. #endif
  101.  
  102. typedef size_t my_size_t;    /* The payoff: do we have size_t now? */
  103.  
  104.  
  105. #endif /* INCLUDES_ARE_ANSI */
  106.  
  107.  
  108.  
  109. /* The next question is whether your compiler supports ANSI-style function
  110.  * definitions.  You need to know this in order to choose between using
  111.  * makefile.ansi and using makefile.unix.
  112.  * The #define line below is set to assume you have ANSI function definitions.
  113.  * If you get an error in this group of lines, undefine HAVE_ANSI_DEFINITIONS.
  114.  */
  115.  
  116. #define HAVE_ANSI_DEFINITIONS
  117.  
  118. #ifdef HAVE_ANSI_DEFINITIONS
  119. int testfunction (int arg1, int * arg2); /* check prototypes */
  120.  
  121. struct methods_struct {        /* check method-pointer declarations */
  122.   int (*error_exit) (char *msgtext);
  123.   int (*trace_message) (char *msgtext);
  124.   int (*another_method) (void);
  125. };
  126.  
  127. int testfunction (int arg1, int * arg2) /* check definitions */
  128. {
  129.   return arg2[arg1];
  130. }
  131.  
  132. int testfunction1 (void)    /* check void arg list */
  133. {
  134.   return 0;
  135. }
  136. #endif
  137.  
  138.  
  139. /* Now we want to find out if your compiler knows what "unsigned char" means.
  140.  * If you get an error on the "unsigned char un_char;" line,
  141.  * then undefine HAVE_UNSIGNED_CHAR.
  142.  */
  143.  
  144. #define HAVE_UNSIGNED_CHAR
  145.  
  146. #ifdef HAVE_UNSIGNED_CHAR
  147. unsigned char un_char;
  148. #endif
  149.  
  150.  
  151. /* Now we want to find out if your compiler knows what "unsigned short" means.
  152.  * If you get an error on the "unsigned short un_short;" line,
  153.  * then undefine HAVE_UNSIGNED_SHORT.
  154.  */
  155.  
  156. #define HAVE_UNSIGNED_SHORT
  157.  
  158. #ifdef HAVE_UNSIGNED_SHORT
  159. unsigned short un_short;
  160. #endif
  161.  
  162.  
  163. /* Now we want to find out if your compiler understands type "void".
  164.  * If you get an error anywhere in here, undefine HAVE_VOID.
  165.  */
  166.  
  167. #define HAVE_VOID
  168.  
  169. #ifdef HAVE_VOID
  170. typedef void * void_ptr;    /* check void * */
  171. typedef void (*void_func) ();    /* check ptr to function returning void */
  172.  
  173. void testfunction2 (arg1, arg2)    /* check void function result */
  174.      void_ptr arg1;
  175.      void_func arg2;
  176. {
  177.   char * locptr = (char *) arg1; /* check casting to and from void * */
  178.   arg1 = (void *) locptr;
  179.   (*arg2) (1, 2);        /* check call of fcn returning void */
  180. }
  181. #endif
  182.  
  183.  
  184. /* Now we want to find out if your compiler knows what "const" means.
  185.  * If you get an error here, undefine HAVE_CONST.
  186.  */
  187.  
  188. #define HAVE_CONST
  189.  
  190. #ifdef HAVE_CONST
  191. static const int carray[3] = {1, 2, 3};
  192.  
  193. int testfunction3 (arg1)
  194.      const int arg1;
  195. {
  196.   return carray[arg1];
  197. }
  198. #endif
  199.  
  200.  
  201.  
  202. /************************************************************************
  203.  *  OK, that's it.  You should not have to change anything beyond this
  204.  *  point in order to compile and execute this program.  (You might get
  205.  *  some warnings, but you can ignore them.)
  206.  *  When you run the program, it will make a couple more tests that it
  207.  *  can do automatically, and then it will print out a summary of the changes
  208.  *  that you need to make to the makefile and jconfig.h.
  209.  ************************************************************************
  210.  */
  211.  
  212.  
  213. static int any_changes = 0;
  214.  
  215. int new_change ()
  216. {
  217.   if (! any_changes) {
  218.     printf("\nMost of the changes recommended by this program can be made either\n");
  219.     printf("by editing jconfig.h, or by adding -Dsymbol switches to the CFLAGS\n");
  220.     printf("line in your Makefile.  (Some PC compilers expect /Dsymbol instead.)\n");
  221.     printf("The CFLAGS method is simpler, but if your system doesn't use makefiles,\n");
  222.     printf("or if your compiler doesn't support -D, then you must change jconfig.h.\n");
  223.     any_changes = 1;
  224.   }
  225.   printf("\n");            /* blank line before each problem report */
  226.   return 0;
  227. }
  228.  
  229.  
  230. int test_char_sign (arg)
  231.      int arg;
  232. {
  233.   if (arg == 189) {        /* expected result for unsigned char */
  234.     new_change();
  235.     printf("You should add -DCHAR_IS_UNSIGNED to CFLAGS,\n");
  236.     printf("or else remove the /* */ comment marks from the line\n");
  237.     printf("/* #define CHAR_IS_UNSIGNED */  in jconfig.h.\n");
  238.     printf("(Be sure to delete the space before the # character too.)\n");
  239.   }
  240.   else if (arg != -67) {    /* expected result for signed char */
  241.     new_change();
  242.     printf("Hmm, it seems 'char' is less than eight bits wide on your machine.\n");
  243.     printf("I fear the JPEG software will not work at all.\n");
  244.   }
  245.   return 0;
  246. }
  247.  
  248.  
  249. int test_shifting (arg)
  250.      long arg;
  251. /* See whether right-shift on a long is signed or not. */
  252. {
  253.   long res = arg >> 4;
  254.  
  255.   if (res == 0x80817F4L) {    /* expected result for unsigned */
  256.     new_change();
  257.     printf("You must add -DRIGHT_SHIFT_IS_UNSIGNED to CFLAGS,\n");
  258.     printf("or else remove the /* */ comment marks from the line\n");
  259.     printf("/* #define RIGHT_SHIFT_IS_UNSIGNED */  in jconfig.h.\n");
  260.   }
  261.   else if (res != -0x7F7E80CL) { /* expected result for signed */
  262.     new_change();
  263.     printf("Right shift isn't acting as I expect it to.\n");
  264.     printf("I fear the JPEG software will not work at all.\n");
  265.   }
  266.   return 0;
  267. }
  268.  
  269.  
  270. int main (argc, argv)
  271.      int argc;
  272.      char ** argv;
  273. {
  274.   char signed_char_check = (char) (-67);
  275.  
  276.   printf("Results of configuration check for Independent JPEG Group's software:\n");
  277.   printf("\nIf there's not a specific makefile provided for your compiler,\n");
  278. #ifdef HAVE_ANSI_DEFINITIONS
  279.   printf("you should use makefile.ansi as the starting point for your Makefile.\n");
  280. #else
  281.   printf("you should use makefile.unix as the starting point for your Makefile.\n");
  282. #endif
  283.  
  284.   /* Check whether we have all the ANSI features, */
  285.   /* and whether this agrees with __STDC__ being predefined. */
  286. #ifdef __STDC__
  287. #define HAVE_STDC    /* ANSI compilers won't allow redefining __STDC__ */
  288. #endif
  289.  
  290. #ifdef HAVE_ANSI_DEFINITIONS
  291. #ifdef HAVE_UNSIGNED_CHAR
  292. #ifdef HAVE_UNSIGNED_SHORT
  293. #ifdef HAVE_CONST
  294. #define HAVE_ALL_ANSI_FEATURES
  295. #endif
  296. #endif
  297. #endif
  298. #endif
  299.  
  300. #ifdef HAVE_ALL_ANSI_FEATURES
  301. #ifndef HAVE_STDC
  302.   new_change();
  303.   printf("Your compiler doesn't claim to be ANSI-compliant, but it is close enough\n");
  304.   printf("for me.  Either add -DHAVE_STDC to CFLAGS, or add #define HAVE_STDC at the\n");
  305.   printf("beginning of jconfig.h.\n");
  306. #define HAVE_STDC
  307. #endif
  308. #else /* !HAVE_ALL_ANSI_FEATURES */
  309. #ifdef HAVE_STDC
  310.   new_change();
  311.   printf("Your compiler claims to be ANSI-compliant, but it is lying!\n");
  312.   printf("Delete the line  #define HAVE_STDC  near the beginning of jconfig.h.\n");
  313. #undef HAVE_STDC
  314. #endif
  315. #endif /* HAVE_ALL_ANSI_FEATURES */
  316.  
  317. #ifndef HAVE_STDC
  318.  
  319. #ifdef HAVE_ANSI_DEFINITIONS
  320.   new_change();
  321.   printf("You should add -DPROTO to CFLAGS, or else take out the several\n");
  322.   printf("#ifdef/#else/#endif lines surrounding #define PROTO in jconfig.h.\n");
  323.   printf("(Leave only one #define PROTO line.)\n");
  324. #endif
  325.  
  326. #ifdef HAVE_UNSIGNED_CHAR
  327. #ifdef HAVE_UNSIGNED_SHORT
  328.   new_change();
  329.   printf("You should add -DHAVE_UNSIGNED_CHAR and -DHAVE_UNSIGNED_SHORT\n");
  330.   printf("to CFLAGS, or else take out the #ifdef HAVE_STDC/#endif lines\n");
  331.   printf("surrounding #define HAVE_UNSIGNED_CHAR and #define HAVE_UNSIGNED_SHORT\n");
  332.   printf("in jconfig.h.\n");
  333. #else /* only unsigned char */
  334.   new_change();
  335.   printf("You should add -DHAVE_UNSIGNED_CHAR to CFLAGS,\n");
  336.   printf("or else move #define HAVE_UNSIGNED_CHAR outside the\n");
  337.   printf("#ifdef HAVE_STDC/#endif lines surrounding it in jconfig.h.\n");
  338. #endif
  339. #else /* !HAVE_UNSIGNED_CHAR */
  340. #ifdef HAVE_UNSIGNED_SHORT
  341.   new_change();
  342.   printf("You should add -DHAVE_UNSIGNED_SHORT to CFLAGS,\n");
  343.   printf("or else move #define HAVE_UNSIGNED_SHORT outside the\n");
  344.   printf("#ifdef HAVE_STDC/#endif lines surrounding it in jconfig.h.\n");
  345. #endif
  346. #endif /* HAVE_UNSIGNED_CHAR */
  347.  
  348. #ifdef HAVE_CONST
  349.   new_change();
  350.   printf("You should delete the  #define const  line from jconfig.h.\n");
  351. #endif
  352.  
  353. #endif /* HAVE_STDC */
  354.  
  355.   test_char_sign((int) signed_char_check);
  356.  
  357.   test_shifting(-0x7F7E80B1L);
  358.  
  359. #ifndef HAVE_VOID
  360.   new_change();
  361.   printf("You should add -Dvoid=char to CFLAGS,\n");
  362.   printf("or else remove the /* */ comment marks from the line\n");
  363.   printf("/* #define void char */  in jconfig.h.\n");
  364.   printf("(Be sure to delete the space before the # character too.)\n");
  365. #endif
  366.  
  367. #ifdef INCLUDES_ARE_ANSI
  368. #ifndef __STDC__
  369.   new_change();
  370.   printf("You should add -DINCLUDES_ARE_ANSI to CFLAGS, or else add\n");
  371.   printf("#define INCLUDES_ARE_ANSI at the beginning of jinclude.h (NOT jconfig.h).\n");
  372. #endif
  373. #else /* !INCLUDES_ARE_ANSI */
  374. #ifdef __STDC__
  375.   new_change();
  376.   printf("You should add -DNONANSI_INCLUDES to CFLAGS, or else add\n");
  377.   printf("#define NONANSI_INCLUDES at the beginning of jinclude.h (NOT jconfig.h).\n");
  378. #endif
  379. #ifdef NEED_SPECIAL_INCLUDE
  380.   new_change();
  381.   printf("In jinclude.h, change the line reading #include <sys/types.h>\n");
  382.   printf("to instead include the file you found size_t in.\n");
  383. #else /* !NEED_SPECIAL_INCLUDE */
  384. #ifndef HAVE_TYPES_H
  385.   new_change();
  386.   printf("In jinclude.h, delete the line reading #include <sys/types.h>.\n");
  387. #endif
  388. #endif /* NEED_SPECIAL_INCLUDE */
  389. #ifdef BSD
  390.   new_change();
  391.   printf("You should add -DBSD to CFLAGS, or else add\n");
  392.   printf("#define BSD at the beginning of jinclude.h (NOT jconfig.h).\n");
  393. #endif
  394. #endif /* INCLUDES_ARE_ANSI */
  395.  
  396.   if (any_changes) {
  397.     printf("\nI think that's everything...\n");
  398.   } else {
  399.     printf("\nI think jconfig.h is OK as distributed.\n");
  400.   }
  401.  
  402.   return any_changes;
  403. }
  404.