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