home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / jpeg / jpegv4a.tar / ckconfig.c < prev    next >
C/C++ Source or Header  |  1992-07-24  |  13KB  |  405 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 compiler doesn't support -D,\n");
  222.     printf("then you must change jconfig.h.  Also, it's best to change jconfig.h\n");
  223.     printf("if you plan to use the JPEG software as a library for other programs.\n");
  224.     any_changes = 1;
  225.   }
  226.   printf("\n");            /* blank line before each problem report */
  227.   return 0;
  228. }
  229.  
  230.  
  231. int test_char_sign (arg)
  232.      int arg;
  233. {
  234.   if (arg == 189) {        /* expected result for unsigned char */
  235.     new_change();
  236.     printf("You should add -DCHAR_IS_UNSIGNED to CFLAGS,\n");
  237.     printf("or else remove the /* */ comment marks from the line\n");
  238.     printf("/* #define CHAR_IS_UNSIGNED */  in jconfig.h.\n");
  239.     printf("(Be sure to delete the space before the # character too.)\n");
  240.   }
  241.   else if (arg != -67) {    /* expected result for signed char */
  242.     new_change();
  243.     printf("Hmm, it seems 'char' is less than eight bits wide on your machine.\n");
  244.     printf("I fear the JPEG software will not work at all.\n");
  245.   }
  246.   return 0;
  247. }
  248.  
  249.  
  250. int test_shifting (arg)
  251.      long arg;
  252. /* See whether right-shift on a long is signed or not. */
  253. {
  254.   long res = arg >> 4;
  255.  
  256.   if (res == 0x80817F4L) {    /* expected result for unsigned */
  257.     new_change();
  258.     printf("You must add -DRIGHT_SHIFT_IS_UNSIGNED to CFLAGS,\n");
  259.     printf("or else remove the /* */ comment marks from the line\n");
  260.     printf("/* #define RIGHT_SHIFT_IS_UNSIGNED */  in jconfig.h.\n");
  261.   }
  262.   else if (res != -0x7F7E80CL) { /* expected result for signed */
  263.     new_change();
  264.     printf("Right shift isn't acting as I expect it to.\n");
  265.     printf("I fear the JPEG software will not work at all.\n");
  266.   }
  267.   return 0;
  268. }
  269.  
  270.  
  271. int main (argc, argv)
  272.      int argc;
  273.      char ** argv;
  274. {
  275.   char signed_char_check = (char) (-67);
  276.  
  277.   printf("Results of configuration check for Independent JPEG Group's software:\n");
  278.   printf("\nIf there's not a specific makefile provided for your compiler,\n");
  279. #ifdef HAVE_ANSI_DEFINITIONS
  280.   printf("you should use makefile.ansi as the starting point for your Makefile.\n");
  281. #else
  282.   printf("you should use makefile.unix as the starting point for your Makefile.\n");
  283. #endif
  284.  
  285.   /* Check whether we have all the ANSI features, */
  286.   /* and whether this agrees with __STDC__ being predefined. */
  287. #ifdef __STDC__
  288. #define HAVE_STDC    /* ANSI compilers won't allow redefining __STDC__ */
  289. #endif
  290.  
  291. #ifdef HAVE_ANSI_DEFINITIONS
  292. #ifdef HAVE_UNSIGNED_CHAR
  293. #ifdef HAVE_UNSIGNED_SHORT
  294. #ifdef HAVE_CONST
  295. #define HAVE_ALL_ANSI_FEATURES
  296. #endif
  297. #endif
  298. #endif
  299. #endif
  300.  
  301. #ifdef HAVE_ALL_ANSI_FEATURES
  302. #ifndef HAVE_STDC
  303.   new_change();
  304.   printf("Your compiler doesn't claim to be ANSI-compliant, but it is close enough\n");
  305.   printf("for me.  Either add -DHAVE_STDC to CFLAGS, or add #define HAVE_STDC at the\n");
  306.   printf("beginning of jconfig.h.\n");
  307. #define HAVE_STDC
  308. #endif
  309. #else /* !HAVE_ALL_ANSI_FEATURES */
  310. #ifdef HAVE_STDC
  311.   new_change();
  312.   printf("Your compiler claims to be ANSI-compliant, but it is lying!\n");
  313.   printf("Delete the line  #define HAVE_STDC  near the beginning of jconfig.h.\n");
  314. #undef HAVE_STDC
  315. #endif
  316. #endif /* HAVE_ALL_ANSI_FEATURES */
  317.  
  318. #ifndef HAVE_STDC
  319.  
  320. #ifdef HAVE_ANSI_DEFINITIONS
  321.   new_change();
  322.   printf("You should add -DPROTO to CFLAGS, or else take out the several\n");
  323.   printf("#ifdef/#else/#endif lines surrounding #define PROTO in jconfig.h.\n");
  324.   printf("(Leave only one #define PROTO line.)\n");
  325. #endif
  326.  
  327. #ifdef HAVE_UNSIGNED_CHAR
  328. #ifdef HAVE_UNSIGNED_SHORT
  329.   new_change();
  330.   printf("You should add -DHAVE_UNSIGNED_CHAR and -DHAVE_UNSIGNED_SHORT\n");
  331.   printf("to CFLAGS, or else take out the #ifdef HAVE_STDC/#endif lines\n");
  332.   printf("surrounding #define HAVE_UNSIGNED_CHAR and #define HAVE_UNSIGNED_SHORT\n");
  333.   printf("in jconfig.h.\n");
  334. #else /* only unsigned char */
  335.   new_change();
  336.   printf("You should add -DHAVE_UNSIGNED_CHAR to CFLAGS,\n");
  337.   printf("or else move #define HAVE_UNSIGNED_CHAR outside the\n");
  338.   printf("#ifdef HAVE_STDC/#endif lines surrounding it in jconfig.h.\n");
  339. #endif
  340. #else /* !HAVE_UNSIGNED_CHAR */
  341. #ifdef HAVE_UNSIGNED_SHORT
  342.   new_change();
  343.   printf("You should add -DHAVE_UNSIGNED_SHORT to CFLAGS,\n");
  344.   printf("or else move #define HAVE_UNSIGNED_SHORT outside the\n");
  345.   printf("#ifdef HAVE_STDC/#endif lines surrounding it in jconfig.h.\n");
  346. #endif
  347. #endif /* HAVE_UNSIGNED_CHAR */
  348.  
  349. #ifdef HAVE_CONST
  350.   new_change();
  351.   printf("You should delete the  #define const  line from jconfig.h.\n");
  352. #endif
  353.  
  354. #endif /* HAVE_STDC */
  355.  
  356.   test_char_sign((int) signed_char_check);
  357.  
  358.   test_shifting(-0x7F7E80B1L);
  359.  
  360. #ifndef HAVE_VOID
  361.   new_change();
  362.   printf("You should add -Dvoid=char to CFLAGS,\n");
  363.   printf("or else remove the /* */ comment marks from the line\n");
  364.   printf("/* #define void char */  in jconfig.h.\n");
  365.   printf("(Be sure to delete the space before the # character too.)\n");
  366. #endif
  367.  
  368. #ifdef INCLUDES_ARE_ANSI
  369. #ifndef __STDC__
  370.   new_change();
  371.   printf("You should add -DINCLUDES_ARE_ANSI to CFLAGS, or else add\n");
  372.   printf("#define INCLUDES_ARE_ANSI at the beginning of jinclude.h (NOT jconfig.h).\n");
  373. #endif
  374. #else /* !INCLUDES_ARE_ANSI */
  375. #ifdef __STDC__
  376.   new_change();
  377.   printf("You should add -DNONANSI_INCLUDES to CFLAGS, or else add\n");
  378.   printf("#define NONANSI_INCLUDES at the beginning of jinclude.h (NOT jconfig.h).\n");
  379. #endif
  380. #ifdef NEED_SPECIAL_INCLUDE
  381.   new_change();
  382.   printf("In jinclude.h, change the line reading #include <sys/types.h>\n");
  383.   printf("to instead include the file you found size_t in.\n");
  384. #else /* !NEED_SPECIAL_INCLUDE */
  385. #ifndef HAVE_TYPES_H
  386.   new_change();
  387.   printf("In jinclude.h, delete the line reading #include <sys/types.h>.\n");
  388. #endif
  389. #endif /* NEED_SPECIAL_INCLUDE */
  390. #ifdef BSD
  391.   new_change();
  392.   printf("You should add -DBSD to CFLAGS, or else add\n");
  393.   printf("#define BSD at the beginning of jinclude.h (NOT jconfig.h).\n");
  394. #endif
  395. #endif /* INCLUDES_ARE_ANSI */
  396.  
  397.   if (any_changes) {
  398.     printf("\nI think that's everything...\n");
  399.   } else {
  400.     printf("\nI think jconfig.h is OK as distributed.\n");
  401.   }
  402.  
  403.   return any_changes;
  404. }
  405.