Back to index

plt-scheme  4.2.1
ckconfig.c
Go to the documentation of this file.
00001 /*
00002  * ckconfig.c
00003  *
00004  * Copyright (C) 1991-1994, Thomas G. Lane.
00005  * This file is part of the Independent JPEG Group's software.
00006  * For conditions of distribution and use, see the accompanying README file.
00007  */
00008 
00009 /*
00010  * This program is intended to help you determine how to configure the JPEG
00011  * software for installation on a particular system.  The idea is to try to
00012  * compile and execute this program.  If your compiler fails to compile the
00013  * program, make changes as indicated in the comments below.  Once you can
00014  * compile the program, run it, and it will produce a "jconfig.h" file for
00015  * your system.
00016  *
00017  * As a general rule, each time you try to compile this program,
00018  * pay attention only to the *first* error message you get from the compiler.
00019  * Many C compilers will issue lots of spurious error messages once they
00020  * have gotten confused.  Go to the line indicated in the first error message,
00021  * and read the comments preceding that line to see what to change.
00022  *
00023  * Almost all of the edits you may need to make to this program consist of
00024  * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL",
00025  * or vice versa.  This is called defining or undefining that symbol.
00026  */
00027 
00028 
00029 /* First we must see if your system has the include files we need.
00030  * We start out with the assumption that your system has all the ANSI-standard
00031  * include files.  If you get any error trying to include one of these files,
00032  * undefine the corresponding HAVE_xxx symbol.
00033  */
00034 
00035 #define HAVE_STDDEF_H              /* replace 'define' by 'undef' if error here */
00036 #ifdef HAVE_STDDEF_H        /* next line will be skipped if you undef... */
00037 #include <stddef.h>
00038 #endif
00039 
00040 #define HAVE_STDLIB_H              /* same thing for stdlib.h */
00041 #ifdef HAVE_STDLIB_H
00042 #include <stdlib.h>
00043 #endif
00044 
00045 #include <stdio.h>          /* If you ain't got this, you ain't got C. */
00046 
00047 /* We have to see if your string functions are defined by
00048  * strings.h (old BSD convention) or string.h (everybody else).
00049  * We try the non-BSD convention first; define NEED_BSD_STRINGS
00050  * if the compiler says it can't find string.h.
00051  */
00052 
00053 #undef NEED_BSD_STRINGS
00054 
00055 #ifdef NEED_BSD_STRINGS
00056 #include <strings.h>
00057 #else
00058 #include <string.h>
00059 #endif
00060 
00061 /* On some systems (especially older Unix machines), type size_t is
00062  * defined only in the include file <sys/types.h>.  If you get a failure
00063  * on the size_t test below, try defining NEED_SYS_TYPES_H.
00064  */
00065 
00066 #undef NEED_SYS_TYPES_H            /* start by assuming we don't need it */
00067 #ifdef NEED_SYS_TYPES_H
00068 #include <sys/types.h>
00069 #endif
00070 
00071 
00072 /* Usually type size_t is defined in one of the include files we've included
00073  * above.  If not, you'll get an error on the "typedef size_t my_size_t;" line.
00074  * In that case, first try defining NEED_SYS_TYPES_H just above.
00075  * If that doesn't work, you'll have to search through your system library
00076  * to figure out which include file defines "size_t".  Look for a line that
00077  * says "typedef something-or-other size_t;".  Then, change the line below
00078  * that says "#include <someincludefile.h>" to instead include the file
00079  * you found size_t in, and define NEED_SPECIAL_INCLUDE.  If you can't find
00080  * type size_t anywhere, try replacing "#include <someincludefile.h>" with
00081  * "typedef unsigned int size_t;".
00082  */
00083 
00084 #undef NEED_SPECIAL_INCLUDE /* assume we DON'T need it, for starters */
00085 
00086 #ifdef NEED_SPECIAL_INCLUDE
00087 #include <someincludefile.h>
00088 #endif
00089 
00090 typedef size_t my_size_t;   /* The payoff: do we have size_t now? */
00091 
00092 
00093 /* The next question is whether your compiler supports ANSI-style function
00094  * prototypes.  You need to know this in order to choose between using
00095  * makefile.ansi and using makefile.unix.
00096  * The #define line below is set to assume you have ANSI function prototypes.
00097  * If you get an error in this group of lines, undefine HAVE_PROTOTYPES.
00098  */
00099 
00100 #define HAVE_PROTOTYPES
00101 
00102 #ifdef HAVE_PROTOTYPES
00103 int testfunction (int arg1, int * arg2); /* check prototypes */
00104 
00105 struct methods_struct {            /* check method-pointer declarations */
00106   int (*error_exit) (char *msgtext);
00107   int (*trace_message) (char *msgtext);
00108   int (*another_method) (void);
00109 };
00110 
00111 int testfunction (int arg1, int * arg2) /* check definitions */
00112 {
00113   return arg2[arg1];
00114 }
00115 
00116 int test2function (void)    /* check void arg list */
00117 {
00118   return 0;
00119 }
00120 #endif
00121 
00122 
00123 /* Now we want to find out if your compiler knows what "unsigned char" means.
00124  * If you get an error on the "unsigned char un_char;" line,
00125  * then undefine HAVE_UNSIGNED_CHAR.
00126  */
00127 
00128 #define HAVE_UNSIGNED_CHAR
00129 
00130 #ifdef HAVE_UNSIGNED_CHAR
00131 unsigned char un_char;
00132 #endif
00133 
00134 
00135 /* Now we want to find out if your compiler knows what "unsigned short" means.
00136  * If you get an error on the "unsigned short un_short;" line,
00137  * then undefine HAVE_UNSIGNED_SHORT.
00138  */
00139 
00140 #define HAVE_UNSIGNED_SHORT
00141 
00142 #ifdef HAVE_UNSIGNED_SHORT
00143 unsigned short un_short;
00144 #endif
00145 
00146 
00147 /* Now we want to find out if your compiler understands type "void".
00148  * If you get an error anywhere in here, undefine HAVE_VOID.
00149  */
00150 
00151 #define HAVE_VOID
00152 
00153 #ifdef HAVE_VOID
00154 /* Caution: a C++ compiler will insist on complete prototypes */
00155 typedef void * void_ptr;    /* check void * */
00156 #ifdef HAVE_PROTOTYPES             /* check ptr to function returning void */
00157 typedef void (*void_func) (int a, int b);
00158 #else
00159 typedef void (*void_func) ();
00160 #endif
00161 
00162 #ifdef HAVE_PROTOTYPES             /* check void function result */
00163 void test3function (void_ptr arg1, void_func arg2)
00164 #else
00165 void test3function (arg1, arg2)
00166      void_ptr arg1;
00167      void_func arg2;
00168 #endif
00169 {
00170   char * locptr = (char *) arg1; /* check casting to and from void * */
00171   arg1 = (void *) locptr;
00172   (*arg2) (1, 2);           /* check call of fcn returning void */
00173 }
00174 #endif
00175 
00176 
00177 /* Now we want to find out if your compiler knows what "const" means.
00178  * If you get an error here, undefine HAVE_CONST.
00179  */
00180 
00181 #define HAVE_CONST
00182 
00183 #ifdef HAVE_CONST
00184 static const int carray[3] = {1, 2, 3};
00185 
00186 #ifdef HAVE_PROTOTYPES
00187 int test4function (const int arg1)
00188 #else
00189 int test4function (arg1)
00190      const int arg1;
00191 #endif
00192 {
00193   return carray[arg1];
00194 }
00195 #endif
00196 
00197 
00198 /* If you get an error or warning about this structure definition,
00199  * define INCOMPLETE_TYPES_BROKEN.
00200  */
00201 
00202 #undef INCOMPLETE_TYPES_BROKEN
00203 
00204 #ifndef INCOMPLETE_TYPES_BROKEN
00205 typedef struct undefined_structure * undef_struct_ptr;
00206 #endif
00207 
00208 
00209 /* If you get an error about duplicate names,
00210  * define NEED_SHORT_EXTERNAL_NAMES.
00211  */
00212 
00213 #undef NEED_SHORT_EXTERNAL_NAMES
00214 
00215 #ifndef NEED_SHORT_EXTERNAL_NAMES
00216 
00217 int possibly_duplicate_function ()
00218 {
00219   return 0;
00220 }
00221 
00222 int possibly_dupli_function ()
00223 {
00224   return 1;
00225 }
00226 
00227 #endif
00228 
00229 
00230 
00231 /************************************************************************
00232  *  OK, that's it.  You should not have to change anything beyond this
00233  *  point in order to compile and execute this program.  (You might get
00234  *  some warnings, but you can ignore them.)
00235  *  When you run the program, it will make a couple more tests that it
00236  *  can do automatically, and then it will create jconfig.h and print out
00237  *  any additional suggestions it has.
00238  ************************************************************************
00239  */
00240 
00241 
00242 #ifdef HAVE_PROTOTYPES
00243 int is_char_signed (int arg)
00244 #else
00245 int is_char_signed (arg)
00246      int arg;
00247 #endif
00248 {
00249   if (arg == 189) {         /* expected result for unsigned char */
00250     return 0;               /* type char is unsigned */
00251   }
00252   else if (arg != -67) {    /* expected result for signed char */
00253     printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");
00254     printf("I fear the JPEG software will not work at all.\n\n");
00255   }
00256   return 1;                 /* assume char is signed otherwise */
00257 }
00258 
00259 
00260 #ifdef HAVE_PROTOTYPES
00261 int is_shifting_signed (long arg)
00262 #else
00263 int is_shifting_signed (arg)
00264      long arg;
00265 #endif
00266 /* See whether right-shift on a long is signed or not. */
00267 {
00268   long res = arg >> 4;
00269 
00270   if (res == -0x7F7E80CL) { /* expected result for signed shift */
00271     return 1;               /* right shift is signed */
00272   }
00273   /* see if unsigned-shift hack will fix it. */
00274   /* we can't just test exact value since it depends on width of long... */
00275   res |= (~0L) << (32-4);
00276   if (res == -0x7F7E80CL) { /* expected result now? */
00277     return 0;               /* right shift is unsigned */
00278   }
00279   printf("Right shift isn't acting as I expect it to.\n");
00280   printf("I fear the JPEG software will not work at all.\n\n");
00281   return 0;                 /* try it with unsigned anyway */
00282 }
00283 
00284 
00285 #ifdef HAVE_PROTOTYPES
00286 int main (int argc, char ** argv)
00287 #else
00288 int main (argc, argv)
00289      int argc;
00290      char ** argv;
00291 #endif
00292 {
00293   char signed_char_check = (char) (-67);
00294   FILE *outfile;
00295 
00296   /* Attempt to write jconfig.h */
00297   if ((outfile = fopen("jconfig.h", "w")) == NULL) {
00298     printf("Failed to write jconfig.h\n");
00299     return 1;
00300   }
00301 
00302   /* Write out all the info */
00303   fprintf(outfile, "/* jconfig.h --- generated by ckconfig.c */\n");
00304   fprintf(outfile, "/* see jconfig.doc for explanations */\n\n");
00305 #ifdef HAVE_PROTOTYPES
00306   fprintf(outfile, "#define HAVE_PROTOTYPES\n");
00307 #else
00308   fprintf(outfile, "#undef HAVE_PROTOTYPES\n");
00309 #endif
00310 #ifdef HAVE_UNSIGNED_CHAR
00311   fprintf(outfile, "#define HAVE_UNSIGNED_CHAR\n");
00312 #else
00313   fprintf(outfile, "#undef HAVE_UNSIGNED_CHAR\n");
00314 #endif
00315 #ifdef HAVE_UNSIGNED_SHORT
00316   fprintf(outfile, "#define HAVE_UNSIGNED_SHORT\n");
00317 #else
00318   fprintf(outfile, "#undef HAVE_UNSIGNED_SHORT\n");
00319 #endif
00320 #ifdef HAVE_VOID
00321   fprintf(outfile, "/* #define void char */\n");
00322 #else
00323   fprintf(outfile, "#define void char\n");
00324 #endif
00325 #ifdef HAVE_CONST
00326   fprintf(outfile, "/* #define const */\n");
00327 #else
00328   fprintf(outfile, "#define const\n");
00329 #endif
00330   if (is_char_signed((int) signed_char_check))
00331     fprintf(outfile, "#undef CHAR_IS_UNSIGNED\n");
00332   else
00333     fprintf(outfile, "#define CHAR_IS_UNSIGNED\n");
00334 #ifdef HAVE_STDDEF_H
00335   fprintf(outfile, "#define HAVE_STDDEF_H\n");
00336 #else
00337   fprintf(outfile, "#undef HAVE_STDDEF_H\n");
00338 #endif
00339 #ifdef HAVE_STDLIB_H
00340   fprintf(outfile, "#define HAVE_STDLIB_H\n");
00341 #else
00342   fprintf(outfile, "#undef HAVE_STDLIB_H\n");
00343 #endif
00344 #ifdef NEED_BSD_STRINGS
00345   fprintf(outfile, "#define NEED_BSD_STRINGS\n");
00346 #else
00347   fprintf(outfile, "#undef NEED_BSD_STRINGS\n");
00348 #endif
00349 #ifdef NEED_SYS_TYPES_H
00350   fprintf(outfile, "#define NEED_SYS_TYPES_H\n");
00351 #else
00352   fprintf(outfile, "#undef NEED_SYS_TYPES_H\n");
00353 #endif
00354   fprintf(outfile, "#undef NEED_FAR_POINTERS\n");
00355 #ifdef NEED_SHORT_EXTERNAL_NAMES
00356   fprintf(outfile, "#define NEED_SHORT_EXTERNAL_NAMES\n");
00357 #else
00358   fprintf(outfile, "#undef NEED_SHORT_EXTERNAL_NAMES\n");
00359 #endif
00360 #ifdef INCOMPLETE_TYPES_BROKEN
00361   fprintf(outfile, "#define INCOMPLETE_TYPES_BROKEN\n");
00362 #else
00363   fprintf(outfile, "#undef INCOMPLETE_TYPES_BROKEN\n");
00364 #endif
00365   fprintf(outfile, "\n#ifdef JPEG_INTERNALS\n\n");
00366   if (is_shifting_signed(-0x7F7E80B1L))
00367     fprintf(outfile, "#undef RIGHT_SHIFT_IS_UNSIGNED\n");
00368   else
00369     fprintf(outfile, "#define RIGHT_SHIFT_IS_UNSIGNED\n");
00370   fprintf(outfile, "\n#endif /* JPEG_INTERNALS */\n");
00371   fprintf(outfile, "\n#ifdef JPEG_CJPEG_DJPEG\n\n");
00372   fprintf(outfile, "#define BMP_SUPPORTED        /* BMP image file format */\n");
00373   fprintf(outfile, "#define GIF_SUPPORTED        /* GIF image file format */\n");
00374   fprintf(outfile, "#define PPM_SUPPORTED        /* PBMPLUS PPM/PGM image file format */\n");
00375   fprintf(outfile, "#undef RLE_SUPPORTED         /* Utah RLE image file format */\n");
00376   fprintf(outfile, "#define TARGA_SUPPORTED             /* Targa image file format */\n\n");
00377   fprintf(outfile, "#undef TWO_FILE_COMMANDLINE  /* You may need this on non-Unix systems */\n");
00378   fprintf(outfile, "#undef NEED_SIGNAL_CATCHER   /* Define this if you use jmemname.c */\n");
00379   fprintf(outfile, "#undef DONT_USE_B_MODE\n");
00380   fprintf(outfile, "/* #define PROGRESS_REPORT */       /* optional */\n");
00381   fprintf(outfile, "\n#endif /* JPEG_CJPEG_DJPEG */\n");
00382 
00383   /* Close the jconfig.h file */
00384   fclose(outfile);
00385 
00386   /* User report */
00387   printf("Configuration check for Independent JPEG Group's software done.\n");
00388   printf("\nI have written the jconfig.h file for you.\n\n");
00389 #ifdef HAVE_PROTOTYPES
00390   printf("You should use makefile.ansi as the starting point for your Makefile.\n");
00391 #else
00392   printf("You should use makefile.unix as the starting point for your Makefile.\n");
00393 #endif
00394 
00395 #ifdef NEED_SPECIAL_INCLUDE
00396   printf("\nYou'll need to change jconfig.h to include the system include file\n");
00397   printf("that you found type size_t in, or add a direct definition of type\n");
00398   printf("size_t if that's what you used.  Just add it to the end.\n");
00399 #endif
00400 
00401   return 0;
00402 }