1# IJG auto-configuration source file.
2# Process this file with autoconf to produce a configure script.
3
4#
5# Configure script for IJG libjpeg
6#
7
8AC_INIT([libjpeg], [7.0])
9
10# Directory where autotools helper scripts lives.
11AC_CONFIG_AUX_DIR([.])
12
13# Generate configuration headers.
14AC_CONFIG_HEADERS([jconfig.h:jconfig.cfg])
15
16# Hack: disable autoheader so that it doesn't overwrite our cfg template.
17AUTOHEADER="echo autoheader ignored"
18
19# Check system type
20AC_CANONICAL_TARGET
21
22# Initialize Automake
23# Don't require all the GNU mandated files
24AM_INIT_AUTOMAKE([-Wall -Werror ansi2knr no-dist foreign])
25
26# Make --enable-silent-rules the default.
27# To get verbose build output you may configure
28# with --disable-silent-rules or use "make V=1".
29AM_SILENT_RULES([yes])
30
31# This is required when using the de-ANSI-fication feature.
32AM_C_PROTOTYPES
33
34# Add configure option --enable-maintainer-mode which enables
35# dependency checking and generation useful to package maintainers.
36# This is made an option to avoid confusing end users.
37AM_MAINTAINER_MODE
38
39# Check for programs
40AC_PROG_CC
41AC_PROG_CC_STDC
42AC_PROG_CPP
43AC_PROG_INSTALL
44AC_PROG_MAKE_SET
45AC_PROG_LN_S
46
47# Check if LD supports linker scripts,
48# and define automake conditional HAVE_LD_VERSION_SCRIPT if so.
49AC_ARG_ENABLE([ld-version-script],
50  AS_HELP_STRING([--enable-ld-version-script],
51    [enable linker version script (default is enabled when possible)]),
52    [have_ld_version_script=$enableval], [])
53if test -z "$have_ld_version_script"; then
54  AC_MSG_CHECKING([if LD -Wl,--version-script works])
55  save_LDFLAGS="$LDFLAGS"
56  LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
57  cat > conftest.map <<EOF
58VERS_1 {
59        global: sym;
60};
61
62VERS_2 {
63        global: sym;
64} VERS_1;
65EOF
66  AC_LINK_IFELSE(AC_LANG_PROGRAM([], []),
67                 [have_ld_version_script=yes], [have_ld_version_script=no])
68  rm -f conftest.map
69  LDFLAGS="$save_LDFLAGS"
70  AC_MSG_RESULT($have_ld_version_script)
71fi
72AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
73
74# See if compiler supports prototypes.
75AC_MSG_CHECKING(for function prototypes)
76AC_CACHE_VAL(ijg_cv_have_prototypes,
77[AC_TRY_COMPILE([
78int testfunction (int arg1, int * arg2); /* check prototypes */
79struct methods_struct {		/* check method-pointer declarations */
80  int (*error_exit) (char *msgtext);
81  int (*trace_message) (char *msgtext);
82  int (*another_method) (void);
83};
84int testfunction (int arg1, int * arg2) /* check definitions */
85{ return arg2[arg1]; }
86int test2function (void)	/* check void arg list */
87{ return 0; }
88], [ ], ijg_cv_have_prototypes=yes, ijg_cv_have_prototypes=no)])
89AC_MSG_RESULT($ijg_cv_have_prototypes)
90if test $ijg_cv_have_prototypes = yes; then
91  AC_DEFINE([HAVE_PROTOTYPES],[1],[Compiler supports function prototypes.])
92else
93  echo Your compiler does not seem to know about function prototypes.
94  echo Perhaps it needs a special switch to enable ANSI C mode.
95  echo If so, we recommend running configure like this:
96  echo "   ./configure  CC='cc -switch'"
97  echo where -switch is the proper switch.
98fi
99
100# Check header files
101AC_CHECK_HEADERS(stddef.h stdlib.h locale.h)
102AC_CHECK_HEADER(string.h, , AC_DEFINE([NEED_BSD_STRINGS],[1],[Compiler has <strings.h> rather than standard <string.h>.]))
103
104# See whether type size_t is defined in any ANSI-standard places;
105# if not, perhaps it is defined in <sys/types.h>.
106AC_MSG_CHECKING(for size_t)
107AC_TRY_COMPILE([
108#ifdef HAVE_STDDEF_H
109#include <stddef.h>
110#endif
111#ifdef HAVE_STDLIB_H
112#include <stdlib.h>
113#endif
114#include <stdio.h>
115#ifdef NEED_BSD_STRINGS
116#include <strings.h>
117#else
118#include <string.h>
119#endif
120typedef size_t my_size_t;
121], [ my_size_t foovar; ], ijg_size_t_ok=yes,
122[ijg_size_t_ok="not ANSI, perhaps it is in sys/types.h"])
123AC_MSG_RESULT($ijg_size_t_ok)
124if test "$ijg_size_t_ok" != yes; then
125AC_CHECK_HEADER(sys/types.h, [AC_DEFINE([NEED_SYS_TYPES_H],[1],[Need to include <sys/types.h> in order to obtain size_t.])
126AC_EGREP_CPP(size_t, [#include <sys/types.h>],
127[ijg_size_t_ok="size_t is in sys/types.h"], ijg_size_t_ok=no)],
128ijg_size_t_ok=no)
129AC_MSG_RESULT($ijg_size_t_ok)
130if test "$ijg_size_t_ok" = no; then
131  echo Type size_t is not defined in any of the usual places.
132  echo Try putting '"typedef unsigned int size_t;"' in jconfig.h.
133fi
134fi
135
136# Check compiler characteristics
137AC_MSG_CHECKING(for type unsigned char)
138AC_TRY_COMPILE(, [ unsigned char un_char; ],
139[AC_MSG_RESULT(yes)
140AC_DEFINE([HAVE_UNSIGNED_CHAR],[1],[Compiler supports 'unsigned char'.])], AC_MSG_RESULT(no))
141dnl
142AC_MSG_CHECKING(for type unsigned short)
143AC_TRY_COMPILE(, [ unsigned short un_short; ],
144[AC_MSG_RESULT(yes)
145AC_DEFINE([HAVE_UNSIGNED_SHORT],[1],[Compiler supports 'unsigned short'.])], AC_MSG_RESULT(no))
146dnl
147AC_MSG_CHECKING(for type void)
148AC_TRY_COMPILE([
149/* Caution: a C++ compiler will insist on valid prototypes */
150typedef void * void_ptr;	/* check void * */
151#ifdef HAVE_PROTOTYPES		/* check ptr to function returning void */
152typedef void (*void_func) (int a, int b);
153#else
154typedef void (*void_func) ();
155#endif
156
157#ifdef HAVE_PROTOTYPES		/* check void function result */
158void test3function (void_ptr arg1, void_func arg2)
159#else
160void test3function (arg1, arg2)
161     void_ptr arg1;
162     void_func arg2;
163#endif
164{
165  char * locptr = (char *) arg1; /* check casting to and from void * */
166  arg1 = (void *) locptr;
167  (*arg2) (1, 2);		/* check call of fcn returning void */
168}
169], [ ], AC_MSG_RESULT(yes), [AC_MSG_RESULT(no)
170AC_DEFINE([void],[char],[Define 'void' as 'char' for archaic compilers that don't understand it.])])
171AC_C_CONST
172
173# Check for non-broken inline under various spellings
174AC_MSG_CHECKING(for inline)
175ijg_cv_inline=""
176AC_TRY_COMPILE(, [} __inline__ int foo() { return 0; }
177int bar() { return foo();], ijg_cv_inline="__inline__",
178AC_TRY_COMPILE(, [} __inline int foo() { return 0; }
179int bar() { return foo();], ijg_cv_inline="__inline",
180AC_TRY_COMPILE(, [} inline int foo() { return 0; }
181int bar() { return foo();], ijg_cv_inline="inline")))
182AC_MSG_RESULT($ijg_cv_inline)
183AC_DEFINE_UNQUOTED([INLINE],[$ijg_cv_inline],[How to obtain function inlining.])
184
185# We cannot check for bogus warnings, but at least we can check for errors
186AC_MSG_CHECKING(for broken incomplete types)
187AC_TRY_COMPILE([ typedef struct undefined_structure * undef_struct_ptr; ], ,
188AC_MSG_RESULT(ok),
189[AC_MSG_RESULT(broken)
190AC_DEFINE([INCOMPLETE_TYPES_BROKEN],[1],[Compiler does not support pointers to unspecified structures.])])
191
192# Test whether global names are unique to at least 15 chars
193AC_MSG_CHECKING(for short external names)
194AC_TRY_LINK([
195int possibly_duplicate_function () { return 0; }
196int possibly_dupli_function () { return 1; }
197], [ ], AC_MSG_RESULT(ok), [AC_MSG_RESULT(short)
198AC_DEFINE([NEED_SHORT_EXTERNAL_NAMES],[1],[Linker requires that global names be unique in first 15 characters.])])
199
200# Run-time checks
201AC_MSG_CHECKING(to see if char is signed)
202AC_TRY_RUN([
203#ifdef HAVE_PROTOTYPES
204int is_char_signed (int arg)
205#else
206int is_char_signed (arg)
207     int arg;
208#endif
209{
210  if (arg == 189) {		/* expected result for unsigned char */
211    return 0;			/* type char is unsigned */
212  }
213  else if (arg != -67) {	/* expected result for signed char */
214    printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");
215    printf("I fear the JPEG software will not work at all.\n\n");
216  }
217  return 1;			/* assume char is signed otherwise */
218}
219char signed_char_check = (char) (-67);
220int main() {
221  exit(is_char_signed((int) signed_char_check));
222}], [AC_MSG_RESULT(no)
223AC_DEFINE([CHAR_IS_UNSIGNED],[1],[Characters are unsigned])], AC_MSG_RESULT(yes),
224[echo Assuming that char is signed on target machine.
225echo If it is unsigned, this will be a little bit inefficient.
226])
227dnl
228AC_MSG_CHECKING(to see if right shift is signed)
229AC_TRY_RUN([
230#ifdef HAVE_PROTOTYPES
231int is_shifting_signed (long arg)
232#else
233int is_shifting_signed (arg)
234     long arg;
235#endif
236/* See whether right-shift on a long is signed or not. */
237{
238  long res = arg >> 4;
239
240  if (res == -0x7F7E80CL) {	/* expected result for signed shift */
241    return 1;			/* right shift is signed */
242  }
243  /* see if unsigned-shift hack will fix it. */
244  /* we can't just test exact value since it depends on width of long... */
245  res |= (~0L) << (32-4);
246  if (res == -0x7F7E80CL) {	/* expected result now? */
247    return 0;			/* right shift is unsigned */
248  }
249  printf("Right shift isn't acting as I expect it to.\n");
250  printf("I fear the JPEG software will not work at all.\n\n");
251  return 0;			/* try it with unsigned anyway */
252}
253int main() {
254  exit(is_shifting_signed(-0x7F7E80B1L));
255}], [AC_MSG_RESULT(no)
256AC_DEFINE([RIGHT_SHIFT_IS_UNSIGNED],[1],[Broken compiler shifts signed values as an unsigned shift.])], AC_MSG_RESULT(yes),
257AC_MSG_RESULT(Assuming that right shift is signed on target machine.))
258dnl
259AC_MSG_CHECKING(to see if fopen accepts b spec)
260AC_TRY_RUN([
261#include <stdio.h>
262int main() {
263  if (fopen("conftestdata", "wb") != NULL)
264    exit(0);
265  exit(1);
266}], AC_MSG_RESULT(yes), [AC_MSG_RESULT(no)
267AC_DEFINE([DONT_USE_B_MODE],[1],[Don't open files in binary mode.])],
268AC_MSG_RESULT(Assuming that it does.))
269
270# Configure libtool
271AC_LIBTOOL_WIN32_DLL
272AC_PROG_LIBTOOL
273
274# Select memory manager depending on user input.
275# If no "-enable-maxmem", use jmemnobs
276MEMORYMGR='jmemnobs'
277MAXMEM="no"
278AC_ARG_ENABLE(maxmem,
279[  --enable-maxmem[=N]     enable use of temp files, set max mem usage to N MB],
280MAXMEM="$enableval")
281dnl [# support --with-maxmem for backwards compatibility with IJG V5.]
282dnl AC_ARG_WITH(maxmem, , MAXMEM="$withval")
283if test "x$MAXMEM" = xyes; then
284  MAXMEM=1
285fi
286if test "x$MAXMEM" != xno; then
287  if test -n "`echo $MAXMEM | sed 's/[[0-9]]//g'`"; then
288    AC_MSG_ERROR(non-numeric argument to --enable-maxmem)
289  fi
290  DEFAULTMAXMEM=`expr $MAXMEM \* 1048576`
291AC_DEFINE_UNQUOTED([DEFAULT_MAX_MEM], [${DEFAULTMAXMEM}], [Maximum data space library will allocate.])
292AC_MSG_CHECKING([for 'tmpfile()'])
293AC_TRY_LINK([#include <stdio.h>], [ FILE * tfile = tmpfile(); ],
294[AC_MSG_RESULT(yes)
295MEMORYMGR='jmemansi'],
296[AC_MSG_RESULT(no)
297dnl if tmpfile is not present, must use jmemname.
298MEMORYMGR='jmemname'
299
300# Test for the need to remove temporary files using a signal handler (for cjpeg/djpeg)
301AC_DEFINE([NEED_SIGNAL_CATCHER],[1],[Need signal handler to clean up temporary files.])
302AC_MSG_CHECKING([for 'mktemp()'])
303AC_TRY_LINK(, [ char fname[80]; mktemp(fname); ], AC_MSG_RESULT(yes),
304[AC_MSG_RESULT(no)
305AC_DEFINE([NO_MKTEMP],[1],[The mktemp() function is not available.])])])
306fi
307AC_SUBST(MEMORYMGR)
308
309# Extract the library version ID from jpeglib.h.
310AC_MSG_CHECKING([libjpeg version number])
311[JPEG_LIB_VERSION=`sed -e '/^#define JPEG_LIB_VERSION/!d' -e 's/^[^0-9]*\([0-9][0-9]*\).*$/\1/' $srcdir/jpeglib.h`]
312[JPEG_LIB_VERSION="`expr $JPEG_LIB_VERSION / 10`:`expr $JPEG_LIB_VERSION % 10`"]
313AC_MSG_RESULT([$JPEG_LIB_VERSION])
314AC_SUBST([JPEG_LIB_VERSION])
315
316AC_CONFIG_FILES([Makefile])
317AC_OUTPUT
318