1 #These defines are needed because CentOS5 uses a old version of autoconf
3 AC_DEFUN([AC_TYPE_INT8_T], [_AC_TYPE_INT(8)])
4 AC_DEFUN([AC_TYPE_INT16_T], [_AC_TYPE_INT(16)])
5 AC_DEFUN([AC_TYPE_INT32_T], [_AC_TYPE_INT(32)])
6 AC_DEFUN([AC_TYPE_INT64_T], [_AC_TYPE_INT(64)])
7 AC_DEFUN([AC_TYPE_UINT8_T], [_AC_TYPE_UNSIGNED_INT(8)])
8 AC_DEFUN([AC_TYPE_UINT16_T], [_AC_TYPE_UNSIGNED_INT(16)])
9 AC_DEFUN([AC_TYPE_UINT32_T], [_AC_TYPE_UNSIGNED_INT(32)])
10 AC_DEFUN([AC_TYPE_UINT64_T], [_AC_TYPE_UNSIGNED_INT(64)])
14 AC_DEFUN([_AC_TYPE_INT],
16 AC_CACHE_CHECK([for int$1_t], [ac_cv_c_int$1_t],
18 for ac_type in 'int$1_t' 'int' 'long int' \
19 'long long int' 'short int' 'signed char'; do
21 [AC_LANG_BOOL_COMPILE_TRY(
22 [AC_INCLUDES_DEFAULT],
23 [[0 < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1)]])],
25 [AC_LANG_BOOL_COMPILE_TRY(
26 [AC_INCLUDES_DEFAULT],
27 [[($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1)
28 < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 2)]])],
30 [AS_CASE([$ac_type], [int$1_t],
31 [ac_cv_c_int$1_t=yes],
32 [ac_cv_c_int$1_t=$ac_type])])])
33 test "$ac_cv_c_int$1_t" != no && break
35 case $ac_cv_c_int$1_t in #(
38 AC_DEFINE_UNQUOTED([int$1_t], [$ac_cv_c_int$1_t],
39 [Define to the type of a signed integer type of width exactly $1 bits
40 if such a type exists and the standard includes do not define it.]);;
44 # _AC_TYPE_UNSIGNED_INT(NBITS)
45 # ----------------------------
46 AC_DEFUN([_AC_TYPE_UNSIGNED_INT],
48 AC_CACHE_CHECK([for uint$1_t], [ac_cv_c_uint$1_t],
50 for ac_type in 'uint$1_t' 'unsigned int' 'unsigned long int' \
51 'unsigned long long int' 'unsigned short int' 'unsigned char'; do
53 [AC_LANG_BOOL_COMPILE_TRY(
54 [AC_INCLUDES_DEFAULT],
55 [[($ac_type) -1 >> ($1 - 1) == 1]])],
56 [AS_CASE([$ac_type], [uint$1_t],
57 [ac_cv_c_uint$1_t=yes],
58 [ac_cv_c_uint$1_t=$ac_type])])
59 test "$ac_cv_c_uint$1_t" != no && break
61 case $ac_cv_c_uint$1_t in #(
64 m4_bmatch([$1], [^\(8\|32\|64\)$],
65 [AC_DEFINE([_UINT$1_T], 1,
66 [Define for Solaris 2.5.1 so the uint$1_t typedef from
67 <sys/synch.h>, <pthread.h>, or <semaphore.h> is not used.
68 If the typedef was allowed, the #define below would cause a
70 AC_DEFINE_UNQUOTED([uint$1_t], [$ac_cv_c_uint$1_t],
71 [Define to the type of an unsigned integer type of width exactly $1 bits
72 if such a type exists and the standard includes do not define it.]);;
74 ])# _AC_TYPE_UNSIGNED_INT
76 # AS_CASE(WORD, [PATTERN1], [IF-MATCHED1]...[DEFAULT])
77 # ----------------------------------------------------
80 # | PATTERN1) IF-MATCHED1 ;;
85 [m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
87 [$#], 2, [ $1) m4_default([$2], [:]) ;;],
88 [ $1) m4_default([$2], [:]) ;;
89 $0(m4_shiftn(2, $@))])dnl
94 _AS_CASE(m4_shift($@))
99 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
100 # ----------------------------------------------------------------
101 # If the C compiler is not in ISO C99 mode by default, try to add an
102 # option to output variable CC to make it so. This macro tries
103 # various options that select ISO C99 on some system or another. It
104 # considers the compiler to be in ISO C99 mode if it handles _Bool,
105 # // comments, flexible array members, inline, long long int, mixed
106 # code and declarations, named initialization of structs, restrict,
107 # va_copy, varargs macros, variable declarations in for loops and
108 # variable length arrays.
109 AC_DEFUN([_AC_PROG_CC_C99],
110 [_AC_C_STD_TRY([c99],
111 [[#include <stdarg.h>
117 // Check varargs macros. These examples are taken from C99 6.10.3.5.
118 #define debug(...) fprintf (stderr, __VA_ARGS__)
119 #define showlist(...) puts (#__VA_ARGS__)
120 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
122 test_varargs_macros (void)
127 debug ("X = %d\n", x);
128 showlist (The first, second, and third items.);
129 report (x>y, "x is %d but y is %d", x, y);
132 // Check long long types.
133 #define BIG64 18446744073709551615ull
134 #define BIG32 4294967295ul
135 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
137 your preprocessor is broken;
141 your preprocessor is broken;
143 static long long int bignum = -9223372036854775807LL;
144 static unsigned long long int ubignum = BIG64;
146 struct incomplete_array
158 typedef const char *ccp;
161 test_restrict (ccp restrict text)
163 // See if C++-style comments work.
164 // Iterate through items via the restricted pointer.
165 // Also check for declarations in for loops.
166 for (unsigned int i = 0; *(text+i) != '\0'; ++i)
171 // Check varargs and va_copy.
173 test_varargs (const char *format, ...)
176 va_start (args, format);
178 va_copy (args_copy, args);
189 str = va_arg (args_copy, const char *);
192 number = va_arg (args_copy, int);
195 fnumber = va_arg (args_copy, double);
207 _Bool success = false;
210 if (test_restrict ("String literal") == 0)
212 char *restrict newvar = "Another string";
215 test_varargs ("s, d' f .", "string", 65, 34.234);
216 test_varargs_macros ();
218 // Check flexible array members.
219 struct incomplete_array *ia =
220 malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
222 for (int i = 0; i < ia->datasize; ++i)
223 ia->data[i] = i * 1.234;
225 // Check named initializers.
226 struct named_init ni = {
228 .name = L"Test wide string",
229 .average = 543.34343,
234 int dynamic_array[ni.number];
235 dynamic_array[ni.number - 1] = 543;
237 // work around unused variable warnings
238 return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
239 || dynamic_array[ni.number - 1] != 543);
242 dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
243 dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
245 dnl Intel ICC -std=c99, -c99 (deprecated)
247 dnl Solaris -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9,
248 dnl as it incorrectly assumes C99 semantics for library functions)
250 dnl with extended modes being tried first.
251 [[-std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl
257 AC_DEFUN([AC_PROG_CC_C89],
258 [ AC_REQUIRE([AC_PROG_CC])dnl
264 AC_DEFUN([AC_PROG_CC_C99],
265 [ AC_REQUIRE([AC_PROG_CC])dnl
272 AC_DEFUN([AC_PROG_CC_STDC],
273 [ AC_REQUIRE([AC_PROG_CC])dnl
274 AS_CASE([$ac_cv_prog_cc_stdc],
275 [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no],
276 [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
277 [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
278 [ac_cv_prog_cc_stdc=no])])])dnl
279 AC_MSG_CHECKING([for $CC option to accept ISO Standard C])
280 AC_CACHE_VAL([ac_cv_prog_cc_stdc], [])
281 AS_CASE([$ac_cv_prog_cc_stdc],
282 [no], [AC_MSG_RESULT([unsupported])],
283 [''], [AC_MSG_RESULT([none needed])],
284 [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])])
287 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
288 # ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
289 # --------------------------------------------------------------
290 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
291 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
292 # try again with each compiler option in the space-separated OPTION-LIST; if one
293 # helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
294 # else ACTION-IF-UNAVAILABLE.
295 AC_DEFUN([_AC_C_STD_TRY],
296 [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
297 AC_CACHE_VAL(ac_cv_prog_cc_$1,
300 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
303 CC="$ac_save_CC $ac_arg"
304 _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
305 test "x$ac_cv_prog_cc_$1" != "xno" && break
307 rm -f conftest.$ac_ext
310 case "x$ac_cv_prog_cc_$1" in
312 AC_MSG_RESULT([none needed]) ;;
314 AC_MSG_RESULT([unsupported]) ;;
316 CC="$CC $ac_cv_prog_cc_$1"
317 AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
319 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])