Commit | Line | Data |
---|---|---|
7a6dbc2f SDJ |
1 | # stdint.m4 serial 52 |
2 | dnl Copyright (C) 2001-2018 Free Software Foundation, Inc. | |
f6ea5628 DJ |
3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | |
5 | dnl with or without modifications, as long as this notice is preserved. | |
6 | ||
7 | dnl From Paul Eggert and Bruno Haible. | |
8 | dnl Test whether <stdint.h> is supported or must be substituted. | |
9 | ||
770d76d7 | 10 | AC_DEFUN_ONCE([gl_STDINT_H], |
f6ea5628 | 11 | [ |
f434ba03 | 12 | AC_PREREQ([2.59])dnl |
7a6dbc2f | 13 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
f6ea5628 | 14 | |
49e4877c | 15 | AC_REQUIRE([gl_LIMITS_H]) |
7a6dbc2f | 16 | AC_REQUIRE([gt_TYPE_WINT_T]) |
49e4877c | 17 | |
f6ea5628 DJ |
18 | dnl Check for long long int and unsigned long long int. |
19 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) | |
20 | if test $ac_cv_type_long_long_int = yes; then | |
21 | HAVE_LONG_LONG_INT=1 | |
22 | else | |
23 | HAVE_LONG_LONG_INT=0 | |
24 | fi | |
25 | AC_SUBST([HAVE_LONG_LONG_INT]) | |
26 | AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) | |
27 | if test $ac_cv_type_unsigned_long_long_int = yes; then | |
28 | HAVE_UNSIGNED_LONG_LONG_INT=1 | |
29 | else | |
30 | HAVE_UNSIGNED_LONG_LONG_INT=0 | |
31 | fi | |
32 | AC_SUBST([HAVE_UNSIGNED_LONG_LONG_INT]) | |
33 | ||
770d76d7 PA |
34 | dnl Check for <wchar.h>, in the same way as gl_WCHAR_H does. |
35 | AC_CHECK_HEADERS_ONCE([wchar.h]) | |
36 | if test $ac_cv_header_wchar_h = yes; then | |
37 | HAVE_WCHAR_H=1 | |
38 | else | |
39 | HAVE_WCHAR_H=0 | |
40 | fi | |
41 | AC_SUBST([HAVE_WCHAR_H]) | |
42 | ||
f6ea5628 DJ |
43 | dnl Check for <inttypes.h>. |
44 | dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h. | |
45 | if test $ac_cv_header_inttypes_h = yes; then | |
46 | HAVE_INTTYPES_H=1 | |
47 | else | |
48 | HAVE_INTTYPES_H=0 | |
49 | fi | |
50 | AC_SUBST([HAVE_INTTYPES_H]) | |
51 | ||
52 | dnl Check for <sys/types.h>. | |
53 | dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h. | |
54 | if test $ac_cv_header_sys_types_h = yes; then | |
55 | HAVE_SYS_TYPES_H=1 | |
56 | else | |
57 | HAVE_SYS_TYPES_H=0 | |
58 | fi | |
59 | AC_SUBST([HAVE_SYS_TYPES_H]) | |
60 | ||
61 | gl_CHECK_NEXT_HEADERS([stdint.h]) | |
62 | if test $ac_cv_header_stdint_h = yes; then | |
63 | HAVE_STDINT_H=1 | |
64 | else | |
65 | HAVE_STDINT_H=0 | |
66 | fi | |
67 | AC_SUBST([HAVE_STDINT_H]) | |
68 | ||
69 | dnl Now see whether we need a substitute <stdint.h>. | |
70 | if test $ac_cv_header_stdint_h = yes; then | |
71 | AC_CACHE_CHECK([whether stdint.h conforms to C99], | |
72 | [gl_cv_header_working_stdint_h], | |
73 | [gl_cv_header_working_stdint_h=no | |
74 | AC_COMPILE_IFELSE([ | |
75 | AC_LANG_PROGRAM([[ | |
f6ea5628 | 76 | #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ |
49e4877c PA |
77 | #define __STDC_CONSTANT_MACROS 1 |
78 | #define __STDC_LIMIT_MACROS 1 | |
f6ea5628 DJ |
79 | #include <stdint.h> |
80 | /* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>. */ | |
81 | #if !(defined WCHAR_MIN && defined WCHAR_MAX) | |
82 | #error "WCHAR_MIN, WCHAR_MAX not defined in <stdint.h>" | |
83 | #endif | |
84 | ] | |
85 | gl_STDINT_INCLUDES | |
86 | [ | |
87 | #ifdef INT8_MAX | |
88 | int8_t a1 = INT8_MAX; | |
89 | int8_t a1min = INT8_MIN; | |
90 | #endif | |
91 | #ifdef INT16_MAX | |
92 | int16_t a2 = INT16_MAX; | |
93 | int16_t a2min = INT16_MIN; | |
94 | #endif | |
95 | #ifdef INT32_MAX | |
96 | int32_t a3 = INT32_MAX; | |
97 | int32_t a3min = INT32_MIN; | |
98 | #endif | |
99 | #ifdef INT64_MAX | |
100 | int64_t a4 = INT64_MAX; | |
101 | int64_t a4min = INT64_MIN; | |
102 | #endif | |
103 | #ifdef UINT8_MAX | |
104 | uint8_t b1 = UINT8_MAX; | |
105 | #else | |
106 | typedef int b1[(unsigned char) -1 != 255 ? 1 : -1]; | |
107 | #endif | |
108 | #ifdef UINT16_MAX | |
109 | uint16_t b2 = UINT16_MAX; | |
110 | #endif | |
111 | #ifdef UINT32_MAX | |
112 | uint32_t b3 = UINT32_MAX; | |
113 | #endif | |
114 | #ifdef UINT64_MAX | |
115 | uint64_t b4 = UINT64_MAX; | |
116 | #endif | |
117 | int_least8_t c1 = INT8_C (0x7f); | |
118 | int_least8_t c1max = INT_LEAST8_MAX; | |
119 | int_least8_t c1min = INT_LEAST8_MIN; | |
120 | int_least16_t c2 = INT16_C (0x7fff); | |
121 | int_least16_t c2max = INT_LEAST16_MAX; | |
122 | int_least16_t c2min = INT_LEAST16_MIN; | |
123 | int_least32_t c3 = INT32_C (0x7fffffff); | |
124 | int_least32_t c3max = INT_LEAST32_MAX; | |
125 | int_least32_t c3min = INT_LEAST32_MIN; | |
126 | int_least64_t c4 = INT64_C (0x7fffffffffffffff); | |
127 | int_least64_t c4max = INT_LEAST64_MAX; | |
128 | int_least64_t c4min = INT_LEAST64_MIN; | |
129 | uint_least8_t d1 = UINT8_C (0xff); | |
130 | uint_least8_t d1max = UINT_LEAST8_MAX; | |
131 | uint_least16_t d2 = UINT16_C (0xffff); | |
132 | uint_least16_t d2max = UINT_LEAST16_MAX; | |
133 | uint_least32_t d3 = UINT32_C (0xffffffff); | |
134 | uint_least32_t d3max = UINT_LEAST32_MAX; | |
135 | uint_least64_t d4 = UINT64_C (0xffffffffffffffff); | |
136 | uint_least64_t d4max = UINT_LEAST64_MAX; | |
137 | int_fast8_t e1 = INT_FAST8_MAX; | |
138 | int_fast8_t e1min = INT_FAST8_MIN; | |
139 | int_fast16_t e2 = INT_FAST16_MAX; | |
140 | int_fast16_t e2min = INT_FAST16_MIN; | |
141 | int_fast32_t e3 = INT_FAST32_MAX; | |
142 | int_fast32_t e3min = INT_FAST32_MIN; | |
143 | int_fast64_t e4 = INT_FAST64_MAX; | |
144 | int_fast64_t e4min = INT_FAST64_MIN; | |
145 | uint_fast8_t f1 = UINT_FAST8_MAX; | |
146 | uint_fast16_t f2 = UINT_FAST16_MAX; | |
147 | uint_fast32_t f3 = UINT_FAST32_MAX; | |
148 | uint_fast64_t f4 = UINT_FAST64_MAX; | |
149 | #ifdef INTPTR_MAX | |
150 | intptr_t g = INTPTR_MAX; | |
151 | intptr_t gmin = INTPTR_MIN; | |
152 | #endif | |
153 | #ifdef UINTPTR_MAX | |
154 | uintptr_t h = UINTPTR_MAX; | |
155 | #endif | |
156 | intmax_t i = INTMAX_MAX; | |
157 | uintmax_t j = UINTMAX_MAX; | |
158 | ||
4c62b19f PA |
159 | /* Check that SIZE_MAX has the correct type, if possible. */ |
160 | #if 201112 <= __STDC_VERSION__ | |
161 | int k = _Generic (SIZE_MAX, size_t: 0); | |
162 | #elif (2 <= __GNUC__ || defined __IBM__TYPEOF__ \ | |
163 | || (0x5110 <= __SUNPRO_C && !__STDC__)) | |
164 | extern size_t k; | |
165 | extern __typeof__ (SIZE_MAX) k; | |
166 | #endif | |
167 | ||
f6ea5628 DJ |
168 | #include <limits.h> /* for CHAR_BIT */ |
169 | #define TYPE_MINIMUM(t) \ | |
770d76d7 | 170 | ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ TYPE_MAXIMUM (t))) |
f6ea5628 | 171 | #define TYPE_MAXIMUM(t) \ |
770d76d7 PA |
172 | ((t) ((t) 0 < (t) -1 \ |
173 | ? (t) -1 \ | |
174 | : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) | |
f6ea5628 DJ |
175 | struct s { |
176 | int check_PTRDIFF: | |
177 | PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t) | |
178 | && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t) | |
179 | ? 1 : -1; | |
180 | /* Detect bug in FreeBSD 6.0 / ia64. */ | |
181 | int check_SIG_ATOMIC: | |
182 | SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t) | |
183 | && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t) | |
184 | ? 1 : -1; | |
185 | int check_SIZE: SIZE_MAX == TYPE_MAXIMUM (size_t) ? 1 : -1; | |
186 | int check_WCHAR: | |
187 | WCHAR_MIN == TYPE_MINIMUM (wchar_t) | |
188 | && WCHAR_MAX == TYPE_MAXIMUM (wchar_t) | |
189 | ? 1 : -1; | |
190 | /* Detect bug in mingw. */ | |
191 | int check_WINT: | |
192 | WINT_MIN == TYPE_MINIMUM (wint_t) | |
193 | && WINT_MAX == TYPE_MAXIMUM (wint_t) | |
194 | ? 1 : -1; | |
195 | ||
196 | /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */ | |
197 | int check_UINT8_C: | |
198 | (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1; | |
199 | int check_UINT16_C: | |
200 | (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1; | |
201 | ||
202 | /* Detect bugs in OpenBSD 3.9 stdint.h. */ | |
203 | #ifdef UINT8_MAX | |
204 | int check_uint8: (uint8_t) -1 == UINT8_MAX ? 1 : -1; | |
205 | #endif | |
206 | #ifdef UINT16_MAX | |
207 | int check_uint16: (uint16_t) -1 == UINT16_MAX ? 1 : -1; | |
208 | #endif | |
209 | #ifdef UINT32_MAX | |
210 | int check_uint32: (uint32_t) -1 == UINT32_MAX ? 1 : -1; | |
211 | #endif | |
212 | #ifdef UINT64_MAX | |
213 | int check_uint64: (uint64_t) -1 == UINT64_MAX ? 1 : -1; | |
214 | #endif | |
215 | int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1; | |
216 | int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1; | |
217 | int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1; | |
218 | int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1; | |
219 | int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1; | |
220 | int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1; | |
221 | int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1; | |
222 | int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1; | |
223 | int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1; | |
224 | int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1; | |
225 | int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1; | |
226 | }; | |
227 | ]])], | |
f434ba03 PA |
228 | [dnl Determine whether the various *_MIN, *_MAX macros are usable |
229 | dnl in preprocessor expression. We could do it by compiling a test | |
230 | dnl program for each of these macros. It is faster to run a program | |
231 | dnl that inspects the macro expansion. | |
232 | dnl This detects a bug on HP-UX 11.23/ia64. | |
233 | AC_RUN_IFELSE([ | |
234 | AC_LANG_PROGRAM([[ | |
f434ba03 | 235 | #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ |
49e4877c PA |
236 | #define __STDC_CONSTANT_MACROS 1 |
237 | #define __STDC_LIMIT_MACROS 1 | |
f434ba03 PA |
238 | #include <stdint.h> |
239 | ] | |
240 | gl_STDINT_INCLUDES | |
241 | [ | |
242 | #include <stdio.h> | |
243 | #include <string.h> | |
244 | #define MVAL(macro) MVAL1(macro) | |
245 | #define MVAL1(expression) #expression | |
246 | static const char *macro_values[] = | |
247 | { | |
248 | #ifdef INT8_MAX | |
249 | MVAL (INT8_MAX), | |
250 | #endif | |
251 | #ifdef INT16_MAX | |
252 | MVAL (INT16_MAX), | |
253 | #endif | |
254 | #ifdef INT32_MAX | |
255 | MVAL (INT32_MAX), | |
256 | #endif | |
257 | #ifdef INT64_MAX | |
258 | MVAL (INT64_MAX), | |
259 | #endif | |
260 | #ifdef UINT8_MAX | |
261 | MVAL (UINT8_MAX), | |
262 | #endif | |
263 | #ifdef UINT16_MAX | |
264 | MVAL (UINT16_MAX), | |
265 | #endif | |
266 | #ifdef UINT32_MAX | |
267 | MVAL (UINT32_MAX), | |
268 | #endif | |
269 | #ifdef UINT64_MAX | |
270 | MVAL (UINT64_MAX), | |
271 | #endif | |
272 | NULL | |
273 | }; | |
274 | ]], [[ | |
275 | const char **mv; | |
276 | for (mv = macro_values; *mv != NULL; mv++) | |
277 | { | |
278 | const char *value = *mv; | |
279 | /* Test whether it looks like a cast expression. */ | |
280 | if (strncmp (value, "((unsigned int)"/*)*/, 15) == 0 | |
281 | || strncmp (value, "((unsigned short)"/*)*/, 17) == 0 | |
282 | || strncmp (value, "((unsigned char)"/*)*/, 16) == 0 | |
283 | || strncmp (value, "((int)"/*)*/, 6) == 0 | |
284 | || strncmp (value, "((signed short)"/*)*/, 15) == 0 | |
285 | || strncmp (value, "((signed char)"/*)*/, 14) == 0) | |
770d76d7 | 286 | return mv - macro_values + 1; |
f434ba03 PA |
287 | } |
288 | return 0; | |
289 | ]])], | |
290 | [gl_cv_header_working_stdint_h=yes], | |
291 | [], | |
7a6dbc2f SDJ |
292 | [case "$host_os" in |
293 | # Guess yes on native Windows. | |
294 | mingw*) gl_cv_header_working_stdint_h="guessing yes" ;; | |
295 | # In general, assume it works. | |
296 | *) gl_cv_header_working_stdint_h="guessing yes" ;; | |
297 | esac | |
f434ba03 PA |
298 | ]) |
299 | ]) | |
300 | ]) | |
f6ea5628 | 301 | fi |
49e4877c PA |
302 | |
303 | HAVE_C99_STDINT_H=0 | |
304 | HAVE_SYS_BITYPES_H=0 | |
305 | HAVE_SYS_INTTYPES_H=0 | |
306 | STDINT_H=stdint.h | |
7a6dbc2f SDJ |
307 | case "$gl_cv_header_working_stdint_h" in |
308 | *yes) | |
309 | HAVE_C99_STDINT_H=1 | |
310 | dnl Now see whether the system <stdint.h> works without | |
311 | dnl __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined. | |
312 | AC_CACHE_CHECK([whether stdint.h predates C++11], | |
313 | [gl_cv_header_stdint_predates_cxx11_h], | |
314 | [gl_cv_header_stdint_predates_cxx11_h=yes | |
315 | AC_COMPILE_IFELSE([ | |
316 | AC_LANG_PROGRAM([[ | |
49e4877c PA |
317 | #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ |
318 | #include <stdint.h> | |
319 | ] | |
320 | gl_STDINT_INCLUDES | |
321 | [ | |
322 | intmax_t im = INTMAX_MAX; | |
323 | int32_t i32 = INT32_C (0x7fffffff); | |
7a6dbc2f SDJ |
324 | ]])], |
325 | [gl_cv_header_stdint_predates_cxx11_h=no])]) | |
49e4877c | 326 | |
7a6dbc2f SDJ |
327 | if test "$gl_cv_header_stdint_predates_cxx11_h" = yes; then |
328 | AC_DEFINE([__STDC_CONSTANT_MACROS], [1], | |
329 | [Define to 1 if the system <stdint.h> predates C++11.]) | |
330 | AC_DEFINE([__STDC_LIMIT_MACROS], [1], | |
331 | [Define to 1 if the system <stdint.h> predates C++11.]) | |
332 | fi | |
333 | AC_CACHE_CHECK([whether stdint.h has UINTMAX_WIDTH etc.], | |
334 | [gl_cv_header_stdint_width], | |
335 | [gl_cv_header_stdint_width=no | |
336 | AC_COMPILE_IFELSE( | |
337 | [AC_LANG_PROGRAM([[ | |
338 | /* Work if build is not clean. */ | |
339 | #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 | |
340 | #ifndef __STDC_WANT_IEC_60559_BFP_EXT__ | |
341 | #define __STDC_WANT_IEC_60559_BFP_EXT__ 1 | |
342 | #endif | |
343 | #include <stdint.h> | |
344 | ]gl_STDINT_INCLUDES[ | |
345 | int iw = UINTMAX_WIDTH; | |
346 | ]])], | |
347 | [gl_cv_header_stdint_width=yes])]) | |
348 | if test "$gl_cv_header_stdint_width" = yes; then | |
349 | STDINT_H= | |
350 | fi | |
351 | ;; | |
352 | *) | |
353 | dnl Check for <sys/inttypes.h>, and for | |
354 | dnl <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5). | |
355 | AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h]) | |
356 | if test $ac_cv_header_sys_inttypes_h = yes; then | |
357 | HAVE_SYS_INTTYPES_H=1 | |
358 | fi | |
359 | if test $ac_cv_header_sys_bitypes_h = yes; then | |
360 | HAVE_SYS_BITYPES_H=1 | |
361 | fi | |
362 | gl_STDINT_TYPE_PROPERTIES | |
363 | ;; | |
364 | esac | |
49e4877c | 365 | |
7a6dbc2f SDJ |
366 | dnl The substitute stdint.h needs the substitute limit.h's _GL_INTEGER_WIDTH. |
367 | gl_REPLACE_LIMITS_H | |
49e4877c PA |
368 | |
369 | AC_SUBST([HAVE_C99_STDINT_H]) | |
370 | AC_SUBST([HAVE_SYS_BITYPES_H]) | |
371 | AC_SUBST([HAVE_SYS_INTTYPES_H]) | |
f434ba03 | 372 | AC_SUBST([STDINT_H]) |
770d76d7 | 373 | AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"]) |
f6ea5628 DJ |
374 | ]) |
375 | ||
376 | dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES) | |
377 | dnl Determine the size of each of the given types in bits. | |
378 | AC_DEFUN([gl_STDINT_BITSIZEOF], | |
379 | [ | |
380 | dnl Use a shell loop, to avoid bloating configure, and | |
381 | dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into | |
382 | dnl config.h.in, | |
383 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | |
f434ba03 | 384 | m4_foreach_w([gltype], [$1], |
770d76d7 | 385 | [AH_TEMPLATE([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), |
f6ea5628 DJ |
386 | [Define to the number of bits in type ']gltype['.])]) |
387 | for gltype in $1 ; do | |
388 | AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}], | |
389 | [AC_COMPUTE_INT([result], [sizeof ($gltype) * CHAR_BIT], | |
390 | [$2 | |
391 | #include <limits.h>], [result=unknown]) | |
392 | eval gl_cv_bitsizeof_${gltype}=\$result | |
393 | ]) | |
394 | eval result=\$gl_cv_bitsizeof_${gltype} | |
395 | if test $result = unknown; then | |
396 | dnl Use a nonempty default, because some compilers, such as IRIX 5 cc, | |
397 | dnl do a syntax check even on unused #if conditions and give an error | |
398 | dnl on valid C code like this: | |
399 | dnl #if 0 | |
400 | dnl # if > 32 | |
401 | dnl # endif | |
402 | dnl #endif | |
403 | result=0 | |
404 | fi | |
405 | GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` | |
406 | AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result]) | |
407 | eval BITSIZEOF_${GLTYPE}=\$result | |
408 | done | |
f434ba03 | 409 | m4_foreach_w([gltype], [$1], |
770d76d7 | 410 | [AC_SUBST([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) |
f6ea5628 DJ |
411 | ]) |
412 | ||
413 | dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES) | |
414 | dnl Determine the signedness of each of the given types. | |
415 | dnl Define HAVE_SIGNED_TYPE if type is signed. | |
416 | AC_DEFUN([gl_CHECK_TYPES_SIGNED], | |
417 | [ | |
418 | dnl Use a shell loop, to avoid bloating configure, and | |
419 | dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into | |
420 | dnl config.h.in, | |
421 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | |
f434ba03 | 422 | m4_foreach_w([gltype], [$1], |
770d76d7 | 423 | [AH_TEMPLATE([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), |
f6ea5628 DJ |
424 | [Define to 1 if ']gltype[' is a signed integer type.])]) |
425 | for gltype in $1 ; do | |
426 | AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed], | |
427 | [AC_COMPILE_IFELSE( | |
428 | [AC_LANG_PROGRAM([$2[ | |
429 | int verify[2 * (($gltype) -1 < ($gltype) 0) - 1];]])], | |
430 | result=yes, result=no) | |
431 | eval gl_cv_type_${gltype}_signed=\$result | |
432 | ]) | |
433 | eval result=\$gl_cv_type_${gltype}_signed | |
434 | GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` | |
435 | if test "$result" = yes; then | |
f434ba03 | 436 | AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], [1]) |
f6ea5628 DJ |
437 | eval HAVE_SIGNED_${GLTYPE}=1 |
438 | else | |
439 | eval HAVE_SIGNED_${GLTYPE}=0 | |
440 | fi | |
441 | done | |
f434ba03 | 442 | m4_foreach_w([gltype], [$1], |
770d76d7 | 443 | [AC_SUBST([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) |
f6ea5628 DJ |
444 | ]) |
445 | ||
446 | dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES) | |
447 | dnl Determine the suffix to use for integer constants of the given types. | |
448 | dnl Define t_SUFFIX for each such type. | |
449 | AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], | |
450 | [ | |
451 | dnl Use a shell loop, to avoid bloating configure, and | |
452 | dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into | |
453 | dnl config.h.in, | |
454 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | |
f434ba03 | 455 | m4_foreach_w([gltype], [$1], |
770d76d7 | 456 | [AH_TEMPLATE(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX], |
f6ea5628 DJ |
457 | [Define to l, ll, u, ul, ull, etc., as suitable for |
458 | constants of type ']gltype['.])]) | |
459 | for gltype in $1 ; do | |
460 | AC_CACHE_CHECK([for $gltype integer literal suffix], | |
461 | [gl_cv_type_${gltype}_suffix], | |
462 | [eval gl_cv_type_${gltype}_suffix=no | |
463 | eval result=\$gl_cv_type_${gltype}_signed | |
464 | if test "$result" = yes; then | |
465 | glsufu= | |
466 | else | |
467 | glsufu=u | |
468 | fi | |
469 | for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do | |
470 | case $glsuf in | |
471 | '') gltype1='int';; | |
f434ba03 PA |
472 | l) gltype1='long int';; |
473 | ll) gltype1='long long int';; | |
474 | i64) gltype1='__int64';; | |
475 | u) gltype1='unsigned int';; | |
476 | ul) gltype1='unsigned long int';; | |
477 | ull) gltype1='unsigned long long int';; | |
f6ea5628 DJ |
478 | ui64)gltype1='unsigned __int64';; |
479 | esac | |
480 | AC_COMPILE_IFELSE( | |
f434ba03 | 481 | [AC_LANG_PROGRAM([$2[ |
f6ea5628 | 482 | extern $gltype foo; |
f434ba03 | 483 | extern $gltype1 foo;]])], |
f6ea5628 DJ |
484 | [eval gl_cv_type_${gltype}_suffix=\$glsuf]) |
485 | eval result=\$gl_cv_type_${gltype}_suffix | |
486 | test "$result" != no && break | |
487 | done]) | |
488 | GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` | |
489 | eval result=\$gl_cv_type_${gltype}_suffix | |
490 | test "$result" = no && result= | |
491 | eval ${GLTYPE}_SUFFIX=\$result | |
f434ba03 | 492 | AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], [$result]) |
f6ea5628 | 493 | done |
f434ba03 | 494 | m4_foreach_w([gltype], [$1], |
770d76d7 | 495 | [AC_SUBST(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])]) |
f6ea5628 DJ |
496 | ]) |
497 | ||
498 | dnl gl_STDINT_INCLUDES | |
499 | AC_DEFUN([gl_STDINT_INCLUDES], | |
500 | [[ | |
501 | /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | |
502 | included before <wchar.h>. */ | |
503 | #include <stddef.h> | |
504 | #include <signal.h> | |
505 | #if HAVE_WCHAR_H | |
506 | # include <stdio.h> | |
507 | # include <time.h> | |
508 | # include <wchar.h> | |
509 | #endif | |
510 | ]]) | |
511 | ||
512 | dnl gl_STDINT_TYPE_PROPERTIES | |
513 | dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t | |
514 | dnl of interest to stdint.in.h. | |
515 | AC_DEFUN([gl_STDINT_TYPE_PROPERTIES], | |
516 | [ | |
f434ba03 PA |
517 | AC_REQUIRE([gl_MULTIARCH]) |
518 | if test $APPLE_UNIVERSAL_BUILD = 0; then | |
519 | gl_STDINT_BITSIZEOF([ptrdiff_t size_t], | |
520 | [gl_STDINT_INCLUDES]) | |
521 | fi | |
522 | gl_STDINT_BITSIZEOF([sig_atomic_t wchar_t wint_t], | |
f6ea5628 DJ |
523 | [gl_STDINT_INCLUDES]) |
524 | gl_CHECK_TYPES_SIGNED([sig_atomic_t wchar_t wint_t], | |
525 | [gl_STDINT_INCLUDES]) | |
526 | gl_cv_type_ptrdiff_t_signed=yes | |
527 | gl_cv_type_size_t_signed=no | |
f434ba03 PA |
528 | if test $APPLE_UNIVERSAL_BUILD = 0; then |
529 | gl_INTEGER_TYPE_SUFFIX([ptrdiff_t size_t], | |
530 | [gl_STDINT_INCLUDES]) | |
531 | fi | |
532 | gl_INTEGER_TYPE_SUFFIX([sig_atomic_t wchar_t wint_t], | |
f6ea5628 | 533 | [gl_STDINT_INCLUDES]) |
770d76d7 PA |
534 | |
535 | dnl If wint_t is smaller than 'int', it cannot satisfy the ISO C 99 | |
536 | dnl requirement that wint_t is "unchanged by default argument promotions". | |
537 | dnl In this case gnulib's <wchar.h> and <wctype.h> override wint_t. | |
538 | dnl Set the variable BITSIZEOF_WINT_T accordingly. | |
7a6dbc2f | 539 | if test $GNULIB_OVERRIDES_WINT_T = 1; then |
770d76d7 PA |
540 | BITSIZEOF_WINT_T=32 |
541 | fi | |
f6ea5628 DJ |
542 | ]) |
543 | ||
544 | dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. | |
545 | dnl Remove this when we can assume autoconf >= 2.61. | |
546 | m4_ifdef([AC_COMPUTE_INT], [], [ | |
547 | AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) | |
548 | ]) |