]>
Commit | Line | Data |
---|---|---|
58396a9a WM |
1 | #These defines are needed because CentOS5 uses a old version of autoconf |
2 | # | |
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)]) | |
11 | ||
7691fc4f VJ |
12 | AC_DEFUN([AC_TYPE_UINT], [_AC_TYPE_UTYPE(u_int)]) |
13 | AC_DEFUN([AC_TYPE_ULONG], [_AC_TYPE_UTYPE(u_long)]) | |
14 | AC_DEFUN([AC_TYPE_UCHAR], [_AC_TYPE_UTYPE(u_char)]) | |
15 | AC_DEFUN([AC_TYPE_USHORT], [_AC_TYPE_UTYPE(u_short)]) | |
16 | ||
17 | # _AC_TYPE_UTYPE(BASE) | |
18 | # ------------------- | |
19 | AC_DEFUN([_AC_TYPE_UTYPE], | |
20 | [ | |
21 | AC_CACHE_CHECK([for $1], [ac_cv_c_$1], | |
22 | [ac_cv_c_$1=no | |
23 | case $1 in | |
24 | "u_long") | |
25 | ac_cv_c_$1_type="U_LONG" | |
26 | ;; | |
27 | "u_int") | |
28 | ac_cv_c_$1_type="U_INT" | |
29 | ;; | |
30 | "u_short") | |
31 | ac_cv_c_$1_type="U_SHORT" | |
32 | ;; | |
33 | "u_char") | |
34 | ac_cv_c_$1_type="U_CHAR" | |
35 | ;; | |
36 | *) | |
37 | ;; | |
38 | esac | |
39 | ||
40 | AC_COMPILE_IFELSE( | |
41 | [AC_LANG_BOOL_COMPILE_TRY( | |
42 | [AC_INCLUDES_DEFAULT], | |
43 | [[($1) -1 >> ((sizeof($1) * 8) - 1) == 1]])], | |
44 | [AS_CASE([$1], [$1], | |
45 | [ac_cv_c_$1=yes], | |
46 | [ac_cv_c_$1=no])]) | |
47 | ]) | |
48 | case $ac_cv_c_$1 in #( | |
49 | no) | |
50 | AC_DEFINE_UNQUOTED([HAVE_TYPE_$ac_cv_c_$1_type_NOT_DEFINED], [1], [$1 is undefined]) | |
51 | ;; | |
52 | *) | |
53 | ;; | |
54 | esac | |
55 | ])# _AC_TYPE_UTYPE | |
56 | ||
58396a9a WM |
57 | # _AC_TYPE_INT(NBITS) |
58 | # ------------------- | |
59 | AC_DEFUN([_AC_TYPE_INT], | |
60 | [ | |
61 | AC_CACHE_CHECK([for int$1_t], [ac_cv_c_int$1_t], | |
62 | [ac_cv_c_int$1_t=no | |
63 | for ac_type in 'int$1_t' 'int' 'long int' \ | |
64 | 'long long int' 'short int' 'signed char'; do | |
65 | AC_COMPILE_IFELSE( | |
66 | [AC_LANG_BOOL_COMPILE_TRY( | |
67 | [AC_INCLUDES_DEFAULT], | |
68 | [[0 < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1)]])], | |
69 | [AC_COMPILE_IFELSE( | |
70 | [AC_LANG_BOOL_COMPILE_TRY( | |
71 | [AC_INCLUDES_DEFAULT], | |
72 | [[($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1) | |
73 | < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 2)]])], | |
74 | [], | |
75 | [AS_CASE([$ac_type], [int$1_t], | |
76 | [ac_cv_c_int$1_t=yes], | |
77 | [ac_cv_c_int$1_t=$ac_type])])]) | |
78 | test "$ac_cv_c_int$1_t" != no && break | |
79 | done]) | |
80 | case $ac_cv_c_int$1_t in #( | |
81 | no|yes) ;; #( | |
82 | *) | |
83 | AC_DEFINE_UNQUOTED([int$1_t], [$ac_cv_c_int$1_t], | |
84 | [Define to the type of a signed integer type of width exactly $1 bits | |
85 | if such a type exists and the standard includes do not define it.]);; | |
86 | esac | |
87 | ])# _AC_TYPE_INT | |
88 | ||
89 | # _AC_TYPE_UNSIGNED_INT(NBITS) | |
90 | # ---------------------------- | |
91 | AC_DEFUN([_AC_TYPE_UNSIGNED_INT], | |
92 | [ | |
93 | AC_CACHE_CHECK([for uint$1_t], [ac_cv_c_uint$1_t], | |
94 | [ac_cv_c_uint$1_t=no | |
95 | for ac_type in 'uint$1_t' 'unsigned int' 'unsigned long int' \ | |
96 | 'unsigned long long int' 'unsigned short int' 'unsigned char'; do | |
97 | AC_COMPILE_IFELSE( | |
98 | [AC_LANG_BOOL_COMPILE_TRY( | |
99 | [AC_INCLUDES_DEFAULT], | |
100 | [[($ac_type) -1 >> ($1 - 1) == 1]])], | |
101 | [AS_CASE([$ac_type], [uint$1_t], | |
102 | [ac_cv_c_uint$1_t=yes], | |
103 | [ac_cv_c_uint$1_t=$ac_type])]) | |
104 | test "$ac_cv_c_uint$1_t" != no && break | |
105 | done]) | |
106 | case $ac_cv_c_uint$1_t in #( | |
107 | no|yes) ;; #( | |
108 | *) | |
109 | m4_bmatch([$1], [^\(8\|32\|64\)$], | |
110 | [AC_DEFINE([_UINT$1_T], 1, | |
111 | [Define for Solaris 2.5.1 so the uint$1_t typedef from | |
112 | <sys/synch.h>, <pthread.h>, or <semaphore.h> is not used. | |
113 | If the typedef was allowed, the #define below would cause a | |
114 | syntax error.])]) | |
115 | AC_DEFINE_UNQUOTED([uint$1_t], [$ac_cv_c_uint$1_t], | |
116 | [Define to the type of an unsigned integer type of width exactly $1 bits | |
117 | if such a type exists and the standard includes do not define it.]);; | |
118 | esac | |
119 | ])# _AC_TYPE_UNSIGNED_INT | |
120 | ||
121 | # AS_CASE(WORD, [PATTERN1], [IF-MATCHED1]...[DEFAULT]) | |
122 | # ---------------------------------------------------- | |
123 | # Expand into | |
124 | # | case WORD in | |
125 | # | PATTERN1) IF-MATCHED1 ;; | |
126 | # | ... | |
127 | # | *) DEFAULT ;; | |
128 | # | esac | |
129 | m4_define([_AS_CASE], | |
130 | [m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])], | |
131 | [$#], 1, [ *) $1 ;;], | |
132 | [$#], 2, [ $1) m4_default([$2], [:]) ;;], | |
133 | [ $1) m4_default([$2], [:]) ;; | |
134 | $0(m4_shiftn(2, $@))])dnl | |
135 | ]) | |
136 | m4_defun([AS_CASE], | |
137 | [m4_ifval([$2$3], | |
138 | [case $1 in | |
139 | _AS_CASE(m4_shift($@)) | |
140 | esac | |
141 | ])dnl | |
142 | ])# AS_CASE | |
3e4d503e WM |
143 | |
144 | # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE]) | |
145 | # ---------------------------------------------------------------- | |
146 | # If the C compiler is not in ISO C99 mode by default, try to add an | |
147 | # option to output variable CC to make it so. This macro tries | |
148 | # various options that select ISO C99 on some system or another. It | |
149 | # considers the compiler to be in ISO C99 mode if it handles _Bool, | |
150 | # // comments, flexible array members, inline, long long int, mixed | |
151 | # code and declarations, named initialization of structs, restrict, | |
152 | # va_copy, varargs macros, variable declarations in for loops and | |
153 | # variable length arrays. | |
154 | AC_DEFUN([_AC_PROG_CC_C99], | |
155 | [_AC_C_STD_TRY([c99], | |
156 | [[#include <stdarg.h> | |
157 | #include <stdbool.h> | |
158 | #include <stdlib.h> | |
159 | #include <wchar.h> | |
160 | #include <stdio.h> | |
161 | ||
162 | // Check varargs macros. These examples are taken from C99 6.10.3.5. | |
163 | #define debug(...) fprintf (stderr, __VA_ARGS__) | |
164 | #define showlist(...) puts (#__VA_ARGS__) | |
165 | #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) | |
166 | static void | |
167 | test_varargs_macros (void) | |
168 | { | |
169 | int x = 1234; | |
170 | int y = 5678; | |
171 | debug ("Flag"); | |
172 | debug ("X = %d\n", x); | |
173 | showlist (The first, second, and third items.); | |
174 | report (x>y, "x is %d but y is %d", x, y); | |
175 | } | |
176 | ||
177 | // Check long long types. | |
178 | #define BIG64 18446744073709551615ull | |
179 | #define BIG32 4294967295ul | |
180 | #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) | |
181 | #if !BIG_OK | |
182 | your preprocessor is broken; | |
183 | #endif | |
184 | #if BIG_OK | |
185 | #else | |
186 | your preprocessor is broken; | |
187 | #endif | |
188 | static long long int bignum = -9223372036854775807LL; | |
189 | static unsigned long long int ubignum = BIG64; | |
190 | ||
191 | struct incomplete_array | |
192 | { | |
193 | int datasize; | |
194 | double data[]; | |
195 | }; | |
196 | ||
197 | struct named_init { | |
198 | int number; | |
199 | const wchar_t *name; | |
200 | double average; | |
201 | }; | |
202 | ||
203 | typedef const char *ccp; | |
204 | ||
205 | static inline int | |
206 | test_restrict (ccp restrict text) | |
207 | { | |
208 | // See if C++-style comments work. | |
209 | // Iterate through items via the restricted pointer. | |
210 | // Also check for declarations in for loops. | |
211 | for (unsigned int i = 0; *(text+i) != '\0'; ++i) | |
212 | continue; | |
213 | return 0; | |
214 | } | |
215 | ||
216 | // Check varargs and va_copy. | |
217 | static void | |
218 | test_varargs (const char *format, ...) | |
219 | { | |
220 | va_list args; | |
221 | va_start (args, format); | |
222 | va_list args_copy; | |
223 | va_copy (args_copy, args); | |
224 | ||
225 | const char *str; | |
226 | int number; | |
227 | float fnumber; | |
228 | ||
229 | while (*format) | |
230 | { | |
231 | switch (*format++) | |
232 | { | |
233 | case 's': // string | |
234 | str = va_arg (args_copy, const char *); | |
235 | break; | |
236 | case 'd': // int | |
237 | number = va_arg (args_copy, int); | |
238 | break; | |
239 | case 'f': // float | |
240 | fnumber = va_arg (args_copy, double); | |
241 | break; | |
242 | default: | |
243 | break; | |
244 | } | |
245 | } | |
246 | va_end (args_copy); | |
247 | va_end (args); | |
248 | } | |
249 | ]], | |
250 | [[ | |
251 | // Check bool. | |
252 | _Bool success = false; | |
253 | ||
254 | // Check restrict. | |
255 | if (test_restrict ("String literal") == 0) | |
256 | success = true; | |
257 | char *restrict newvar = "Another string"; | |
258 | ||
259 | // Check varargs. | |
260 | test_varargs ("s, d' f .", "string", 65, 34.234); | |
261 | test_varargs_macros (); | |
262 | ||
263 | // Check flexible array members. | |
264 | struct incomplete_array *ia = | |
265 | malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); | |
266 | ia->datasize = 10; | |
267 | for (int i = 0; i < ia->datasize; ++i) | |
268 | ia->data[i] = i * 1.234; | |
269 | ||
270 | // Check named initializers. | |
271 | struct named_init ni = { | |
272 | .number = 34, | |
273 | .name = L"Test wide string", | |
274 | .average = 543.34343, | |
275 | }; | |
276 | ||
277 | ni.number = 58; | |
278 | ||
279 | int dynamic_array[ni.number]; | |
280 | dynamic_array[ni.number - 1] = 543; | |
281 | ||
282 | // work around unused variable warnings | |
283 | return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x' | |
284 | || dynamic_array[ni.number - 1] != 543); | |
285 | ]], | |
286 | dnl Try | |
287 | dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999) | |
288 | dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99) | |
289 | dnl HP cc -AC99 | |
290 | dnl Intel ICC -std=c99, -c99 (deprecated) | |
291 | dnl IRIX -c99 | |
292 | dnl Solaris -xc99=all (Forte Developer 7 C mishandles -xc99 on Solaris 9, | |
293 | dnl as it incorrectly assumes C99 semantics for library functions) | |
294 | dnl Tru64 -c99 | |
295 | dnl with extended modes being tried first. | |
296 | [[-std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99]], [$1], [$2])[]dnl | |
297 | ])# _AC_PROG_CC_C99 | |
298 | ||
299 | ||
300 | # AC_PROG_CC_C89 | |
301 | # -------------- | |
302 | AC_DEFUN([AC_PROG_CC_C89], | |
303 | [ AC_REQUIRE([AC_PROG_CC])dnl | |
304 | _AC_PROG_CC_C89 | |
305 | ]) | |
306 | ||
307 | # AC_PROG_CC_C99 | |
308 | # -------------- | |
309 | AC_DEFUN([AC_PROG_CC_C99], | |
310 | [ AC_REQUIRE([AC_PROG_CC])dnl | |
311 | _AC_PROG_CC_C99 | |
312 | ]) | |
313 | ||
314 | ||
315 | # AC_PROG_CC_STDC | |
316 | # --------------- | |
317 | AC_DEFUN([AC_PROG_CC_STDC], | |
318 | [ AC_REQUIRE([AC_PROG_CC])dnl | |
319 | AS_CASE([$ac_cv_prog_cc_stdc], | |
320 | [no], [ac_cv_prog_cc_c99=no; ac_cv_prog_cc_c89=no], | |
321 | [_AC_PROG_CC_C99([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99], | |
322 | [_AC_PROG_CC_C89([ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89], | |
323 | [ac_cv_prog_cc_stdc=no])])])dnl | |
324 | AC_MSG_CHECKING([for $CC option to accept ISO Standard C]) | |
325 | AC_CACHE_VAL([ac_cv_prog_cc_stdc], []) | |
326 | AS_CASE([$ac_cv_prog_cc_stdc], | |
327 | [no], [AC_MSG_RESULT([unsupported])], | |
328 | [''], [AC_MSG_RESULT([none needed])], | |
329 | [AC_MSG_RESULT([$ac_cv_prog_cc_stdc])]) | |
330 | ]) | |
331 | ||
332 | # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST, | |
333 | # ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE) | |
334 | # -------------------------------------------------------------- | |
335 | # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99') | |
336 | # by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails, | |
337 | # try again with each compiler option in the space-separated OPTION-LIST; if one | |
338 | # helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE, | |
339 | # else ACTION-IF-UNAVAILABLE. | |
340 | AC_DEFUN([_AC_C_STD_TRY], | |
341 | [AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C])) | |
342 | AC_CACHE_VAL(ac_cv_prog_cc_$1, | |
343 | [ac_cv_prog_cc_$1=no | |
344 | ac_save_CC=$CC | |
345 | AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])]) | |
346 | for ac_arg in '' $4 | |
347 | do | |
348 | CC="$ac_save_CC $ac_arg" | |
349 | _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg]) | |
350 | test "x$ac_cv_prog_cc_$1" != "xno" && break | |
351 | done | |
352 | rm -f conftest.$ac_ext | |
353 | CC=$ac_save_CC | |
354 | ])# AC_CACHE_VAL | |
355 | case "x$ac_cv_prog_cc_$1" in | |
356 | x) | |
357 | AC_MSG_RESULT([none needed]) ;; | |
358 | xno) | |
359 | AC_MSG_RESULT([unsupported]) ;; | |
360 | *) | |
361 | CC="$CC $ac_cv_prog_cc_$1" | |
362 | AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;; | |
363 | esac | |
364 | AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6]) | |
365 | ])# _AC_C_STD_TRY | |
366 | ||
367 |