kusano 7d535a
/*
kusano 7d535a
 * ckconfig.c
kusano 7d535a
 *
kusano 7d535a
 * Copyright (C) 1991-1994, Thomas G. Lane.
kusano 7d535a
 * This file is part of the Independent JPEG Group's software.
kusano 7d535a
 * For conditions of distribution and use, see the accompanying README file.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * This program is intended to help you determine how to configure the JPEG
kusano 7d535a
 * software for installation on a particular system.  The idea is to try to
kusano 7d535a
 * compile and execute this program.  If your compiler fails to compile the
kusano 7d535a
 * program, make changes as indicated in the comments below.  Once you can
kusano 7d535a
 * compile the program, run it, and it will produce a "jconfig.h" file for
kusano 7d535a
 * your system.
kusano 7d535a
 *
kusano 7d535a
 * As a general rule, each time you try to compile this program,
kusano 7d535a
 * pay attention only to the *first* error message you get from the compiler.
kusano 7d535a
 * Many C compilers will issue lots of spurious error messages once they
kusano 7d535a
 * have gotten confused.  Go to the line indicated in the first error message,
kusano 7d535a
 * and read the comments preceding that line to see what to change.
kusano 7d535a
 *
kusano 7d535a
 * Almost all of the edits you may need to make to this program consist of
kusano 7d535a
 * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL",
kusano 7d535a
 * or vice versa.  This is called defining or undefining that symbol.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* First we must see if your system has the include files we need.
kusano 7d535a
 * We start out with the assumption that your system has all the ANSI-standard
kusano 7d535a
 * include files.  If you get any error trying to include one of these files,
kusano 7d535a
 * undefine the corresponding HAVE_xxx symbol.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#define HAVE_STDDEF_H		/* replace 'define' by 'undef' if error here */
kusano 7d535a
#ifdef HAVE_STDDEF_H		/* next line will be skipped if you undef... */
kusano 7d535a
#include <stddef.h></stddef.h>
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#define HAVE_STDLIB_H		/* same thing for stdlib.h */
kusano 7d535a
#ifdef HAVE_STDLIB_H
kusano 7d535a
#include <stdlib.h></stdlib.h>
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#include <stdio.h>		/* If you ain't got this, you ain't got C. */</stdio.h>
kusano 7d535a
kusano 7d535a
/* We have to see if your string functions are defined by
kusano 7d535a
 * strings.h (old BSD convention) or string.h (everybody else).
kusano 7d535a
 * We try the non-BSD convention first; define NEED_BSD_STRINGS
kusano 7d535a
 * if the compiler says it can't find string.h.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#undef NEED_BSD_STRINGS
kusano 7d535a
kusano 7d535a
#ifdef NEED_BSD_STRINGS
kusano 7d535a
#include <strings.h></strings.h>
kusano 7d535a
#else
kusano 7d535a
#include <string.h></string.h>
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
/* On some systems (especially older Unix machines), type size_t is
kusano 7d535a
 * defined only in the include file <sys types.h="">.  If you get a failure</sys>
kusano 7d535a
 * on the size_t test below, try defining NEED_SYS_TYPES_H.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#undef NEED_SYS_TYPES_H		/* start by assuming we don't need it */
kusano 7d535a
#ifdef NEED_SYS_TYPES_H
kusano 7d535a
#include <sys types.h=""></sys>
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* Usually type size_t is defined in one of the include files we've included
kusano 7d535a
 * above.  If not, you'll get an error on the "typedef size_t my_size_t;" line.
kusano 7d535a
 * In that case, first try defining NEED_SYS_TYPES_H just above.
kusano 7d535a
 * If that doesn't work, you'll have to search through your system library
kusano 7d535a
 * to figure out which include file defines "size_t".  Look for a line that
kusano 7d535a
 * says "typedef something-or-other size_t;".  Then, change the line below
kusano 7d535a
 * that says "#include <someincludefile.h>" to instead include the file</someincludefile.h>
kusano 7d535a
 * you found size_t in, and define NEED_SPECIAL_INCLUDE.  If you can't find
kusano 7d535a
 * type size_t anywhere, try replacing "#include <someincludefile.h>" with</someincludefile.h>
kusano 7d535a
 * "typedef unsigned int size_t;".
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#undef NEED_SPECIAL_INCLUDE	/* assume we DON'T need it, for starters */
kusano 7d535a
kusano 7d535a
#ifdef NEED_SPECIAL_INCLUDE
kusano 7d535a
#include <someincludefile.h></someincludefile.h>
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
typedef size_t my_size_t;	/* The payoff: do we have size_t now? */
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* The next question is whether your compiler supports ANSI-style function
kusano 7d535a
 * prototypes.  You need to know this in order to choose between using
kusano 7d535a
 * makefile.ansi and using makefile.unix.
kusano 7d535a
 * The #define line below is set to assume you have ANSI function prototypes.
kusano 7d535a
 * If you get an error in this group of lines, undefine HAVE_PROTOTYPES.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#define HAVE_PROTOTYPES
kusano 7d535a
kusano 7d535a
#ifdef HAVE_PROTOTYPES
kusano 7d535a
int testfunction (int arg1, int * arg2); /* check prototypes */
kusano 7d535a
kusano 7d535a
struct methods_struct {		/* check method-pointer declarations */
kusano 7d535a
  int (*error_exit) (char *msgtext);
kusano 7d535a
  int (*trace_message) (char *msgtext);
kusano 7d535a
  int (*another_method) (void);
kusano 7d535a
};
kusano 7d535a
kusano 7d535a
int testfunction (int arg1, int * arg2) /* check definitions */
kusano 7d535a
{
kusano 7d535a
  return arg2[arg1];
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
int test2function (void)	/* check void arg list */
kusano 7d535a
{
kusano 7d535a
  return 0;
kusano 7d535a
}
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* Now we want to find out if your compiler knows what "unsigned char" means.
kusano 7d535a
 * If you get an error on the "unsigned char un_char;" line,
kusano 7d535a
 * then undefine HAVE_UNSIGNED_CHAR.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#define HAVE_UNSIGNED_CHAR
kusano 7d535a
kusano 7d535a
#ifdef HAVE_UNSIGNED_CHAR
kusano 7d535a
unsigned char un_char;
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* Now we want to find out if your compiler knows what "unsigned short" means.
kusano 7d535a
 * If you get an error on the "unsigned short un_short;" line,
kusano 7d535a
 * then undefine HAVE_UNSIGNED_SHORT.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#define HAVE_UNSIGNED_SHORT
kusano 7d535a
kusano 7d535a
#ifdef HAVE_UNSIGNED_SHORT
kusano 7d535a
unsigned short un_short;
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* Now we want to find out if your compiler understands type "void".
kusano 7d535a
 * If you get an error anywhere in here, undefine HAVE_VOID.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#define HAVE_VOID
kusano 7d535a
kusano 7d535a
#ifdef HAVE_VOID
kusano 7d535a
/* Caution: a C++ compiler will insist on complete prototypes */
kusano 7d535a
typedef void * void_ptr;	/* check void * */
kusano 7d535a
#ifdef HAVE_PROTOTYPES		/* check ptr to function returning void */
kusano 7d535a
typedef void (*void_func) (int a, int b);
kusano 7d535a
#else
kusano 7d535a
typedef void (*void_func) ();
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#ifdef HAVE_PROTOTYPES		/* check void function result */
kusano 7d535a
void test3function (void_ptr arg1, void_func arg2)
kusano 7d535a
#else
kusano 7d535a
void test3function (arg1, arg2)
kusano 7d535a
     void_ptr arg1;
kusano 7d535a
     void_func arg2;
kusano 7d535a
#endif
kusano 7d535a
{
kusano 7d535a
  char * locptr = (char *) arg1; /* check casting to and from void * */
kusano 7d535a
  arg1 = (void *) locptr;
kusano 7d535a
  (*arg2) (1, 2);		/* check call of fcn returning void */
kusano 7d535a
}
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* Now we want to find out if your compiler knows what "const" means.
kusano 7d535a
 * If you get an error here, undefine HAVE_CONST.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#define HAVE_CONST
kusano 7d535a
kusano 7d535a
#ifdef HAVE_CONST
kusano 7d535a
static const int carray[3] = {1, 2, 3};
kusano 7d535a
kusano 7d535a
#ifdef HAVE_PROTOTYPES
kusano 7d535a
int test4function (const int arg1)
kusano 7d535a
#else
kusano 7d535a
int test4function (arg1)
kusano 7d535a
     const int arg1;
kusano 7d535a
#endif
kusano 7d535a
{
kusano 7d535a
  return carray[arg1];
kusano 7d535a
}
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* If you get an error or warning about this structure definition,
kusano 7d535a
 * define INCOMPLETE_TYPES_BROKEN.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#undef INCOMPLETE_TYPES_BROKEN
kusano 7d535a
kusano 7d535a
#ifndef INCOMPLETE_TYPES_BROKEN
kusano 7d535a
typedef struct undefined_structure * undef_struct_ptr;
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* If you get an error about duplicate names,
kusano 7d535a
 * define NEED_SHORT_EXTERNAL_NAMES.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#undef NEED_SHORT_EXTERNAL_NAMES
kusano 7d535a
kusano 7d535a
#ifndef NEED_SHORT_EXTERNAL_NAMES
kusano 7d535a
kusano 7d535a
int possibly_duplicate_function ()
kusano 7d535a
{
kusano 7d535a
  return 0;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
int possibly_dupli_function ()
kusano 7d535a
{
kusano 7d535a
  return 1;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
/************************************************************************
kusano 7d535a
 *  OK, that's it.  You should not have to change anything beyond this
kusano 7d535a
 *  point in order to compile and execute this program.  (You might get
kusano 7d535a
 *  some warnings, but you can ignore them.)
kusano 7d535a
 *  When you run the program, it will make a couple more tests that it
kusano 7d535a
 *  can do automatically, and then it will create jconfig.h and print out
kusano 7d535a
 *  any additional suggestions it has.
kusano 7d535a
 ************************************************************************
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
#ifdef HAVE_PROTOTYPES
kusano 7d535a
int is_char_signed (int arg)
kusano 7d535a
#else
kusano 7d535a
int is_char_signed (arg)
kusano 7d535a
     int arg;
kusano 7d535a
#endif
kusano 7d535a
{
kusano 7d535a
  if (arg == 189) {		/* expected result for unsigned char */
kusano 7d535a
    return 0;			/* type char is unsigned */
kusano 7d535a
  }
kusano 7d535a
  else if (arg != -67) {	/* expected result for signed char */
kusano 7d535a
    printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");
kusano 7d535a
    printf("I fear the JPEG software will not work at all.\n\n");
kusano 7d535a
  }
kusano 7d535a
  return 1;			/* assume char is signed otherwise */
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
#ifdef HAVE_PROTOTYPES
kusano 7d535a
int is_shifting_signed (long arg)
kusano 7d535a
#else
kusano 7d535a
int is_shifting_signed (arg)
kusano 7d535a
     long arg;
kusano 7d535a
#endif
kusano 7d535a
/* See whether right-shift on a long is signed or not. */
kusano 7d535a
{
kusano 7d535a
  long res = arg >> 4;
kusano 7d535a
kusano 7d535a
  if (res == -0x7F7E80CL) {	/* expected result for signed shift */
kusano 7d535a
    return 1;			/* right shift is signed */
kusano 7d535a
  }
kusano 7d535a
  /* see if unsigned-shift hack will fix it. */
kusano 7d535a
  /* we can't just test exact value since it depends on width of long... */
kusano 7d535a
  res |= (~0L) << (32-4);
kusano 7d535a
  if (res == -0x7F7E80CL) {	/* expected result now? */
kusano 7d535a
    return 0;			/* right shift is unsigned */
kusano 7d535a
  }
kusano 7d535a
  printf("Right shift isn't acting as I expect it to.\n");
kusano 7d535a
  printf("I fear the JPEG software will not work at all.\n\n");
kusano 7d535a
  return 0;			/* try it with unsigned anyway */
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
#ifdef HAVE_PROTOTYPES
kusano 7d535a
int main (int argc, char ** argv)
kusano 7d535a
#else
kusano 7d535a
int main (argc, argv)
kusano 7d535a
     int argc;
kusano 7d535a
     char ** argv;
kusano 7d535a
#endif
kusano 7d535a
{
kusano 7d535a
  char signed_char_check = (char) (-67);
kusano 7d535a
  FILE *outfile;
kusano 7d535a
kusano 7d535a
  /* Attempt to write jconfig.h */
kusano 7d535a
  if ((outfile = fopen("jconfig.h", "w")) == NULL) {
kusano 7d535a
    printf("Failed to write jconfig.h\n");
kusano 7d535a
    return 1;
kusano 7d535a
  }
kusano 7d535a
kusano 7d535a
  /* Write out all the info */
kusano 7d535a
  fprintf(outfile, "/* jconfig.h --- generated by ckconfig.c */\n");
kusano 7d535a
  fprintf(outfile, "/* see jconfig.txt for explanations */\n\n");
kusano 7d535a
#ifdef HAVE_PROTOTYPES
kusano 7d535a
  fprintf(outfile, "#define HAVE_PROTOTYPES\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#undef HAVE_PROTOTYPES\n");
kusano 7d535a
#endif
kusano 7d535a
#ifdef HAVE_UNSIGNED_CHAR
kusano 7d535a
  fprintf(outfile, "#define HAVE_UNSIGNED_CHAR\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#undef HAVE_UNSIGNED_CHAR\n");
kusano 7d535a
#endif
kusano 7d535a
#ifdef HAVE_UNSIGNED_SHORT
kusano 7d535a
  fprintf(outfile, "#define HAVE_UNSIGNED_SHORT\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#undef HAVE_UNSIGNED_SHORT\n");
kusano 7d535a
#endif
kusano 7d535a
#ifdef HAVE_VOID
kusano 7d535a
  fprintf(outfile, "/* #define void char */\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#define void char\n");
kusano 7d535a
#endif
kusano 7d535a
#ifdef HAVE_CONST
kusano 7d535a
  fprintf(outfile, "/* #define const */\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#define const\n");
kusano 7d535a
#endif
kusano 7d535a
  if (is_char_signed((int) signed_char_check))
kusano 7d535a
    fprintf(outfile, "#undef CHAR_IS_UNSIGNED\n");
kusano 7d535a
  else
kusano 7d535a
    fprintf(outfile, "#define CHAR_IS_UNSIGNED\n");
kusano 7d535a
#ifdef HAVE_STDDEF_H
kusano 7d535a
  fprintf(outfile, "#define HAVE_STDDEF_H\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#undef HAVE_STDDEF_H\n");
kusano 7d535a
#endif
kusano 7d535a
#ifdef HAVE_STDLIB_H
kusano 7d535a
  fprintf(outfile, "#define HAVE_STDLIB_H\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#undef HAVE_STDLIB_H\n");
kusano 7d535a
#endif
kusano 7d535a
#ifdef NEED_BSD_STRINGS
kusano 7d535a
  fprintf(outfile, "#define NEED_BSD_STRINGS\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#undef NEED_BSD_STRINGS\n");
kusano 7d535a
#endif
kusano 7d535a
#ifdef NEED_SYS_TYPES_H
kusano 7d535a
  fprintf(outfile, "#define NEED_SYS_TYPES_H\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#undef NEED_SYS_TYPES_H\n");
kusano 7d535a
#endif
kusano 7d535a
  fprintf(outfile, "#undef NEED_FAR_POINTERS\n");
kusano 7d535a
#ifdef NEED_SHORT_EXTERNAL_NAMES
kusano 7d535a
  fprintf(outfile, "#define NEED_SHORT_EXTERNAL_NAMES\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#undef NEED_SHORT_EXTERNAL_NAMES\n");
kusano 7d535a
#endif
kusano 7d535a
#ifdef INCOMPLETE_TYPES_BROKEN
kusano 7d535a
  fprintf(outfile, "#define INCOMPLETE_TYPES_BROKEN\n");
kusano 7d535a
#else
kusano 7d535a
  fprintf(outfile, "#undef INCOMPLETE_TYPES_BROKEN\n");
kusano 7d535a
#endif
kusano 7d535a
  fprintf(outfile, "\n#ifdef JPEG_INTERNALS\n\n");
kusano 7d535a
  if (is_shifting_signed(-0x7F7E80B1L))
kusano 7d535a
    fprintf(outfile, "#undef RIGHT_SHIFT_IS_UNSIGNED\n");
kusano 7d535a
  else
kusano 7d535a
    fprintf(outfile, "#define RIGHT_SHIFT_IS_UNSIGNED\n");
kusano 7d535a
  fprintf(outfile, "\n#endif /* JPEG_INTERNALS */\n");
kusano 7d535a
  fprintf(outfile, "\n#ifdef JPEG_CJPEG_DJPEG\n\n");
kusano 7d535a
  fprintf(outfile, "#define BMP_SUPPORTED		/* BMP image file format */\n");
kusano 7d535a
  fprintf(outfile, "#define GIF_SUPPORTED		/* GIF image file format */\n");
kusano 7d535a
  fprintf(outfile, "#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */\n");
kusano 7d535a
  fprintf(outfile, "#undef RLE_SUPPORTED		/* Utah RLE image file format */\n");
kusano 7d535a
  fprintf(outfile, "#define TARGA_SUPPORTED		/* Targa image file format */\n\n");
kusano 7d535a
  fprintf(outfile, "#undef TWO_FILE_COMMANDLINE	/* You may need this on non-Unix systems */\n");
kusano 7d535a
  fprintf(outfile, "#undef NEED_SIGNAL_CATCHER	/* Define this if you use jmemname.c */\n");
kusano 7d535a
  fprintf(outfile, "#undef DONT_USE_B_MODE\n");
kusano 7d535a
  fprintf(outfile, "/* #define PROGRESS_REPORT */	/* optional */\n");
kusano 7d535a
  fprintf(outfile, "\n#endif /* JPEG_CJPEG_DJPEG */\n");
kusano 7d535a
kusano 7d535a
  /* Close the jconfig.h file */
kusano 7d535a
  fclose(outfile);
kusano 7d535a
kusano 7d535a
  /* User report */
kusano 7d535a
  printf("Configuration check for Independent JPEG Group's software done.\n");
kusano 7d535a
  printf("\nI have written the jconfig.h file for you.\n\n");
kusano 7d535a
#ifdef HAVE_PROTOTYPES
kusano 7d535a
  printf("You should use makefile.ansi as the starting point for your Makefile.\n");
kusano 7d535a
#else
kusano 7d535a
  printf("You should use makefile.unix as the starting point for your Makefile.\n");
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#ifdef NEED_SPECIAL_INCLUDE
kusano 7d535a
  printf("\nYou'll need to change jconfig.h to include the system include file\n");
kusano 7d535a
  printf("that you found type size_t in, or add a direct definition of type\n");
kusano 7d535a
  printf("size_t if that's what you used.  Just add it to the end.\n");
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
  return 0;
kusano 7d535a
}