Apply updated config.guess and config.sub
[platform/upstream/libjpeg6.git] / configure.ac
1 dnl IJG auto-configuration source file.
2 dnl Process this file with autoconf to produce a configure script.
3 AC_INIT(jcmaster.c)
4 AC_CONFIG_HEADER(jconfig.h:jconfig.cfg)
5 dnl
6 dnl do these first since other macros rely on them
7 AC_PROG_CC
8 AC_PROG_CPP
9 dnl
10 dnl See if compiler supports prototypes.
11 AC_MSG_CHECKING(for function prototypes)
12 AC_CACHE_VAL(ijg_cv_have_prototypes,
13 [AC_TRY_COMPILE([
14 int testfunction (int arg1, int * arg2); /* check prototypes */
15 struct methods_struct {         /* check method-pointer declarations */
16   int (*error_exit) (char *msgtext);
17   int (*trace_message) (char *msgtext);
18   int (*another_method) (void);
19 };
20 int testfunction (int arg1, int * arg2) /* check definitions */
21 { return arg2[arg1]; }
22 int test2function (void)        /* check void arg list */
23 { return 0; }
24 ], [ ], ijg_cv_have_prototypes=yes, ijg_cv_have_prototypes=no)])
25 AC_MSG_RESULT($ijg_cv_have_prototypes)
26 if test $ijg_cv_have_prototypes = yes; then
27   AC_DEFINE(HAVE_PROTOTYPES,1,[Define to 1 if we have prototypes.])
28 else
29   echo Your compiler does not seem to know about function prototypes.
30   echo Perhaps it needs a special switch to enable ANSI C mode.
31   echo If so, we recommend running configure like this:
32   echo "   ./configure  CC='cc -switch'"
33   echo where -switch is the proper switch.
34 fi
35 dnl
36 dnl check header files
37 AC_CHECK_HEADER(stddef.h, AC_DEFINE(HAVE_STDDEF_H,1,[Define to 1 if stddef.h is found.]))
38 AC_CHECK_HEADER(stdlib.h, AC_DEFINE(HAVE_STDLIB_H,1,[Define to 1 if stdlib.h is found.]))
39 AC_CHECK_HEADER(string.h,, AC_DEFINE(NEED_BSD_STRINGS,1,[Define to 1 if string.h is missing.]))
40 dnl See whether type size_t is defined in any ANSI-standard places;
41 dnl if not, perhaps it is defined in <sys/types.h>.
42 AC_MSG_CHECKING(for size_t)
43 AC_TRY_COMPILE([
44 #ifdef HAVE_STDDEF_H
45 #include <stddef.h>
46 #endif
47 #ifdef HAVE_STDLIB_H
48 #include <stdlib.h>
49 #endif
50 #include <stdio.h>
51 #ifdef NEED_BSD_STRINGS
52 #include <strings.h>
53 #else
54 #include <string.h>
55 #endif
56 typedef size_t my_size_t;
57 ], [ my_size_t foovar; ], ijg_size_t_ok=yes,
58 [ijg_size_t_ok="not ANSI, perhaps it is in sys/types.h"])
59 AC_MSG_RESULT($ijg_size_t_ok)
60 if test "$ijg_size_t_ok" != yes; then
61 AC_CHECK_HEADER(sys/types.h, [AC_DEFINE(NEED_SYS_TYPES_H,1,[Define to 1 if sys/types.h is found.])
62 AC_EGREP_CPP(size_t, [#include <sys/types.h>],
63 [ijg_size_t_ok="size_t is in sys/types.h"], ijg_size_t_ok=no)],
64 ijg_size_t_ok=no)
65 AC_MSG_RESULT($ijg_size_t_ok)
66 if test "$ijg_size_t_ok" = no; then
67   echo Type size_t is not defined in any of the usual places.
68   echo Try putting '"typedef unsigned int size_t;"' in jconfig.h.
69 fi
70 fi
71 dnl
72 dnl check compiler characteristics
73 AC_MSG_CHECKING(for type unsigned char)
74 AC_TRY_COMPILE(, [ unsigned char un_char; ],
75 [AC_MSG_RESULT(yes)
76 AC_DEFINE(HAVE_UNSIGNED_CHAR,1,[Define to 1 if unsigned char type exists.])], AC_MSG_RESULT(no))
77 AC_MSG_CHECKING(for type unsigned short)
78 AC_TRY_COMPILE(, [ unsigned short un_short; ],
79 [AC_MSG_RESULT(yes)
80 AC_DEFINE(HAVE_UNSIGNED_SHORT,1,[Define to 1 if unsigned short type exists.])], AC_MSG_RESULT(no))
81 AC_MSG_CHECKING(for type void)
82 AC_TRY_COMPILE([
83 /* Caution: a C++ compiler will insist on valid prototypes */
84 typedef void * void_ptr;        /* check void * */
85 #ifdef HAVE_PROTOTYPES          /* check ptr to function returning void */
86 typedef void (*void_func) (int a, int b);
87 #else
88 typedef void (*void_func) ();
89 #endif
90
91 #ifdef HAVE_PROTOTYPES          /* check void function result */
92 void test3function (void_ptr arg1, void_func arg2)
93 #else
94 void test3function (arg1, arg2)
95      void_ptr arg1;
96      void_func arg2;
97 #endif
98 {
99   char * locptr = (char *) arg1; /* check casting to and from void * */
100   arg1 = (void *) locptr;
101   (*arg2) (1, 2);               /* check call of fcn returning void */
102 }
103 ], [ ], AC_MSG_RESULT(yes), [AC_MSG_RESULT(no)
104 AC_DEFINE(void,char,[Define void type to char if it exists.])])
105
106 AC_C_CONST
107 dnl check for non-broken inline under various spellings
108 AC_MSG_CHECKING(for inline)
109 ijg_cv_inline=""
110 AC_TRY_COMPILE(, [} __inline__ int foo() { return 0; }
111 int bar() { return foo();], ijg_cv_inline="__inline__",
112 AC_TRY_COMPILE(, [} __inline int foo() { return 0; }
113 int bar() { return foo();], ijg_cv_inline="__inline",
114 AC_TRY_COMPILE(, [} inline int foo() { return 0; }
115 int bar() { return foo();], ijg_cv_inline="inline")))
116 AC_MSG_RESULT($ijg_cv_inline)
117 AC_DEFINE_UNQUOTED(INLINE,$ijg_cv_inline,[Define keyword style for inline.])
118 dnl we cannot check for bogus warnings, but at least we can check for errors
119 AC_MSG_CHECKING(for broken incomplete types)
120 AC_TRY_COMPILE([ typedef struct undefined_structure * undef_struct_ptr; ], ,
121 AC_MSG_RESULT(ok),
122 [AC_MSG_RESULT(broken)
123 AC_DEFINE(INCOMPLETE_TYPES_BROKEN,1,[Define to 1 if broken incomplete types are found.])])
124 dnl test whether global names are unique to at least 15 chars
125 AC_MSG_CHECKING(for short external names)
126 AC_TRY_LINK([
127 int possibly_duplicate_function () { return 0; }
128 int possibly_dupli_function () { return 1; }
129 ], [ ], AC_MSG_RESULT(ok), [AC_MSG_RESULT(short)
130 AC_DEFINE(NEED_SHORT_EXTERNAL_NAMES,1,[Define to 1 if short external names are needed.])])
131 dnl
132 dnl run-time checks
133 AC_MSG_CHECKING(to see if char is signed)
134 AC_TRY_RUN([
135 #ifdef HAVE_PROTOTYPES
136 int is_char_signed (int arg)
137 #else
138 int is_char_signed (arg)
139      int arg;
140 #endif
141 {
142   if (arg == 189) {             /* expected result for unsigned char */
143     return 0;                   /* type char is unsigned */
144   }
145   else if (arg != -67) {        /* expected result for signed char */
146     printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");
147     printf("I fear the JPEG software will not work at all.\n\n");
148   }
149   return 1;                     /* assume char is signed otherwise */
150 }
151 char signed_char_check = (char) (-67);
152 int main() {
153   exit(is_char_signed((int) signed_char_check));
154 }], [AC_MSG_RESULT(no)
155 AC_DEFINE(CHAR_IS_UNSIGNED,1,[Define to 1 if char type is unsigned.])], AC_MSG_RESULT(yes),
156 [echo Assuming that char is signed on target machine.
157 echo If it is unsigned, this will be a little bit inefficient.
158 ])
159 dnl
160 AC_MSG_CHECKING(to see if right shift is signed)
161 AC_TRY_RUN([
162 #ifdef HAVE_PROTOTYPES
163 int is_shifting_signed (long arg)
164 #else
165 int is_shifting_signed (arg)
166      long arg;
167 #endif
168 /* See whether right-shift on a long is signed or not. */
169 {
170   long res = arg >> 4;
171
172   if (res == -0x7F7E80CL) {     /* expected result for signed shift */
173     return 1;                   /* right shift is signed */
174   }
175   /* see if unsigned-shift hack will fix it. */
176   /* we can't just test exact value since it depends on width of long... */
177   res |= (~0L) << (32-4);
178   if (res == -0x7F7E80CL) {     /* expected result now? */
179     return 0;                   /* right shift is unsigned */
180   }
181   printf("Right shift isn't acting as I expect it to.\n");
182   printf("I fear the JPEG software will not work at all.\n\n");
183   return 0;                     /* try it with unsigned anyway */
184 }
185 int main() {
186   exit(is_shifting_signed(-0x7F7E80B1L));
187 }], [AC_MSG_RESULT(no)
188 AC_DEFINE(RIGHT_SHIFT_IS_UNSIGNED,1,[Define to 1 if right shift is unsigned.])], AC_MSG_RESULT(yes),
189 AC_MSG_RESULT(Assuming that right shift is signed on target machine.))
190 dnl
191 AC_MSG_CHECKING(to see if fopen accepts b spec)
192 AC_TRY_RUN([
193 #include <stdio.h>
194 int main() {
195   if (fopen("conftestdata", "wb") != NULL)
196     exit(0);
197   exit(1);
198 }], AC_MSG_RESULT(yes), [AC_MSG_RESULT(no)
199 AC_DEFINE(DONT_USE_B_MODE,1,[Define to 1 if fopen does not accept b spec.])],
200 AC_MSG_RESULT(Assuming that it does.))
201 dnl
202 dnl system services
203 AC_PROG_INSTALL
204 LT_INIT
205
206 # Decide whether to use libtool,
207 # and if so whether to build shared, static, or both flavors of library.
208 AC_DISABLE_SHARED
209 AC_DISABLE_STATIC
210 if test "x$enable_shared" != xno  -o  "x$enable_static" != xno; then
211   USELIBTOOL="yes"
212
213   # Configure libtool.
214   AC_PROG_LIBTOOL
215
216   LIBTOOL="./libtool"
217   O="lo"
218   A="la"
219   LN='$(LIBTOOL) --mode=link $(CC)'
220   INSTALL_LIB='$(LIBTOOL) --mode=install ${INSTALL}'
221   INSTALL_PROGRAM="\$(LIBTOOL) --mode=install $INSTALL_PROGRAM"
222 else
223   USELIBTOOL="no"
224   LIBTOOL=""
225   O="o"
226   A="a"
227   LN='$(CC)'
228   INSTALL_LIB="$INSTALL_DATA"
229 fi
230 AC_SUBST(LIBTOOL)
231 AC_SUBST(O)
232 AC_SUBST(A)
233 AC_SUBST(LN)
234 AC_SUBST(INSTALL_LIB)
235
236 # Select memory manager depending on user input.
237 # If no "-enable-maxmem", use jmemnobs
238 MEMORYMGR='jmemnobs.$(O)'
239 MAXMEM="no"
240 AC_ARG_ENABLE(maxmem,
241 [  --enable-maxmem[=N]     enable use of temp files, set max mem usage to N MB],
242 MAXMEM="$enableval")
243 dnl [# support --with-maxmem for backwards compatibility with IJG V5.]
244 dnl AC_ARG_WITH(maxmem, , MAXMEM="$withval")
245 if test "x$MAXMEM" = xyes; then
246   MAXMEM=1
247 fi
248 if test "x$MAXMEM" != xno; then
249 changequote(, )dnl
250   if test -n "`echo $MAXMEM | sed 's/[0-9]//g'`"; then
251 changequote([, ])dnl
252     AC_MSG_ERROR(non-numeric argument to --enable-maxmem)
253   fi
254   DEFAULTMAXMEM=`expr $MAXMEM \* 1048576`
255 AC_DEFINE_UNQUOTED(DEFAULT_MAX_MEM, ${DEFAULTMAXMEM},[Define default maxmem value.])
256 AC_MSG_CHECKING([for 'tmpfile()'])
257 AC_TRY_LINK([#include <stdio.h>], [ FILE * tfile = tmpfile(); ],
258 [AC_MSG_RESULT(yes)
259 MEMORYMGR='jmemansi.$(O)'],
260 [AC_MSG_RESULT(no)
261 dnl if tmpfile is not present, must use jmemname.
262 MEMORYMGR='jmemname.$(O)'
263 AC_DEFINE(NEED_SIGNAL_CATCHER,1,[Define to 1 if signal catcher is needed.])
264 AC_MSG_CHECKING([for 'mktemp()'])
265 AC_TRY_LINK(, [ char fname[80]; mktemp(fname); ], AC_MSG_RESULT(yes),
266 [AC_MSG_RESULT(no)
267 AC_DEFINE(NO_MKTEMP,1,[Define to 1 if mktemp is not available.])])])
268 fi
269 AC_SUBST(MEMORYMGR)
270
271 # Include PNG support in cjpeg/djpeg if appropriate.
272 AC_ARG_WITH(png,
273 [  --with-png              enable PNG support in cjpeg/djpeg],
274 [#], [with_png="maybe"])
275
276 # try to detect whether libpng is present
277 if test "x$with_png" = xmaybe ; then
278   AC_CHECK_HEADER(png.h, [: ok so far], [with_png="no"])
279 fi
280 if test "x$with_png" = xmaybe ; then
281   AC_CHECK_HEADER(zlib.h, [: ok so far], [with_png="no"])
282 fi
283 if test "x$with_png" = xmaybe ; then
284   AC_CHECK_LIB(z, deflate, [: ok so far], [with_png="no"])
285 fi
286 if test "x$with_png" = xmaybe ; then
287   AC_CHECK_LIB(png, png_create_info_struct,
288         [with_png="yes"], [with_png="no"], [-lz -lm])
289 fi
290
291 if test "x$with_png" = xyes ; then
292   AC_DEFINE(PNG_SUPPORTED,1,[Define to 1 if PNG is supported.])
293   LIBS="-lpng -lz -lm $LIBS"
294 fi
295
296 # Extract the library version ID from jpeglib.h.
297 AC_MSG_CHECKING([libjpeg version number])
298 [JPEG_LIB_VERSION=`sed -e '/^#define JPEG_LIB_VERSION/!d' -e 's/^[^0-9]*\([0-9][0-9]*\).*$/\1/' $srcdir/jpeglib.h`]
299 AC_MSG_RESULT($JPEG_LIB_VERSION)
300 AC_SUBST(JPEG_LIB_VERSION)
301
302 # Prepare to massage makefile.cfg correctly.
303 if test $ijg_cv_have_prototypes = yes; then
304   A2K_DEPS=""
305   COM_A2K="# "
306 else
307   A2K_DEPS="ansi2knr"
308   COM_A2K=""
309 fi
310 AC_SUBST(A2K_DEPS)
311 AC_SUBST(COM_A2K)
312 # ansi2knr needs -DBSD if string.h is missing
313 if test $ac_cv_header_string_h = no; then
314   ANSI2KNRFLAGS="-DBSD"
315 else
316   ANSI2KNRFLAGS=""
317 fi
318 AC_SUBST(ANSI2KNRFLAGS)
319 dnl
320 # Substitutions to enable or disable libtool-related stuff
321 if test $USELIBTOOL = yes -a $ijg_cv_have_prototypes = yes; then
322   COM_LT=""
323 else
324   COM_LT="# "
325 fi
326 AC_SUBST(COM_LT)
327 if test "x$enable_shared" != xno; then
328   FORCE_INSTALL_LIB="install-lib"
329 else
330   FORCE_INSTALL_LIB=""
331 fi
332 AC_SUBST(FORCE_INSTALL_LIB)
333 dnl
334 # Set up -I directives
335 if test "x$srcdir" = x.; then
336   INCLUDEFLAGS='-I$(srcdir)'
337 else
338   if test "x$GCC" = xyes; then
339     INCLUDEFLAGS='-I- -I. -I$(srcdir)'
340   else
341     INCLUDEFLAGS='-I. -I$(srcdir)'
342   fi
343 fi
344 AC_SUBST(INCLUDEFLAGS)
345 dnl
346 AC_OUTPUT(Makefile:makefile.cfg)