2 dnl Copyright (C) 2001-2015 Free Software Foundation, Inc.
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.
7 dnl From Paul Eggert and Bruno Haible.
8 dnl Test whether <stdint.h> is supported or must be substituted.
10 AC_DEFUN_ONCE([gl_STDINT_H],
14 dnl Check for long long int and unsigned long long int.
15 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
16 if test $ac_cv_type_long_long_int = yes; then
21 AC_SUBST([HAVE_LONG_LONG_INT])
22 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
23 if test $ac_cv_type_unsigned_long_long_int = yes; then
24 HAVE_UNSIGNED_LONG_LONG_INT=1
26 HAVE_UNSIGNED_LONG_LONG_INT=0
28 AC_SUBST([HAVE_UNSIGNED_LONG_LONG_INT])
30 dnl Check for <wchar.h>, in the same way as gl_WCHAR_H does.
31 AC_CHECK_HEADERS_ONCE([wchar.h])
32 if test $ac_cv_header_wchar_h = yes; then
37 AC_SUBST([HAVE_WCHAR_H])
39 dnl Check for <inttypes.h>.
40 dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h.
41 if test $ac_cv_header_inttypes_h = yes; then
46 AC_SUBST([HAVE_INTTYPES_H])
48 dnl Check for <sys/types.h>.
49 dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h.
50 if test $ac_cv_header_sys_types_h = yes; then
55 AC_SUBST([HAVE_SYS_TYPES_H])
57 gl_CHECK_NEXT_HEADERS([stdint.h])
58 if test $ac_cv_header_stdint_h = yes; then
63 AC_SUBST([HAVE_STDINT_H])
65 dnl Now see whether we need a substitute <stdint.h>.
66 if test $ac_cv_header_stdint_h = yes; then
67 AC_CACHE_CHECK([whether stdint.h conforms to C99],
68 [gl_cv_header_working_stdint_h],
69 [gl_cv_header_working_stdint_h=no
72 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
74 /* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>. */
75 #if !(defined WCHAR_MIN && defined WCHAR_MAX)
76 #error "WCHAR_MIN, WCHAR_MAX not defined in <stdint.h>"
83 int8_t a1min = INT8_MIN;
86 int16_t a2 = INT16_MAX;
87 int16_t a2min = INT16_MIN;
90 int32_t a3 = INT32_MAX;
91 int32_t a3min = INT32_MIN;
94 int64_t a4 = INT64_MAX;
95 int64_t a4min = INT64_MIN;
98 uint8_t b1 = UINT8_MAX;
100 typedef int b1[(unsigned char) -1 != 255 ? 1 : -1];
103 uint16_t b2 = UINT16_MAX;
106 uint32_t b3 = UINT32_MAX;
109 uint64_t b4 = UINT64_MAX;
111 int_least8_t c1 = INT8_C (0x7f);
112 int_least8_t c1max = INT_LEAST8_MAX;
113 int_least8_t c1min = INT_LEAST8_MIN;
114 int_least16_t c2 = INT16_C (0x7fff);
115 int_least16_t c2max = INT_LEAST16_MAX;
116 int_least16_t c2min = INT_LEAST16_MIN;
117 int_least32_t c3 = INT32_C (0x7fffffff);
118 int_least32_t c3max = INT_LEAST32_MAX;
119 int_least32_t c3min = INT_LEAST32_MIN;
120 int_least64_t c4 = INT64_C (0x7fffffffffffffff);
121 int_least64_t c4max = INT_LEAST64_MAX;
122 int_least64_t c4min = INT_LEAST64_MIN;
123 uint_least8_t d1 = UINT8_C (0xff);
124 uint_least8_t d1max = UINT_LEAST8_MAX;
125 uint_least16_t d2 = UINT16_C (0xffff);
126 uint_least16_t d2max = UINT_LEAST16_MAX;
127 uint_least32_t d3 = UINT32_C (0xffffffff);
128 uint_least32_t d3max = UINT_LEAST32_MAX;
129 uint_least64_t d4 = UINT64_C (0xffffffffffffffff);
130 uint_least64_t d4max = UINT_LEAST64_MAX;
131 int_fast8_t e1 = INT_FAST8_MAX;
132 int_fast8_t e1min = INT_FAST8_MIN;
133 int_fast16_t e2 = INT_FAST16_MAX;
134 int_fast16_t e2min = INT_FAST16_MIN;
135 int_fast32_t e3 = INT_FAST32_MAX;
136 int_fast32_t e3min = INT_FAST32_MIN;
137 int_fast64_t e4 = INT_FAST64_MAX;
138 int_fast64_t e4min = INT_FAST64_MIN;
139 uint_fast8_t f1 = UINT_FAST8_MAX;
140 uint_fast16_t f2 = UINT_FAST16_MAX;
141 uint_fast32_t f3 = UINT_FAST32_MAX;
142 uint_fast64_t f4 = UINT_FAST64_MAX;
144 intptr_t g = INTPTR_MAX;
145 intptr_t gmin = INTPTR_MIN;
148 uintptr_t h = UINTPTR_MAX;
150 intmax_t i = INTMAX_MAX;
151 uintmax_t j = UINTMAX_MAX;
153 #include <limits.h> /* for CHAR_BIT */
154 #define TYPE_MINIMUM(t) \
155 ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ TYPE_MAXIMUM (t)))
156 #define TYPE_MAXIMUM(t) \
157 ((t) ((t) 0 < (t) -1 \
159 : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
162 PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t)
163 && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t)
165 /* Detect bug in FreeBSD 6.0 / ia64. */
166 int check_SIG_ATOMIC:
167 SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t)
168 && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t)
170 int check_SIZE: SIZE_MAX == TYPE_MAXIMUM (size_t) ? 1 : -1;
172 WCHAR_MIN == TYPE_MINIMUM (wchar_t)
173 && WCHAR_MAX == TYPE_MAXIMUM (wchar_t)
175 /* Detect bug in mingw. */
177 WINT_MIN == TYPE_MINIMUM (wint_t)
178 && WINT_MAX == TYPE_MAXIMUM (wint_t)
181 /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */
183 (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1;
185 (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1;
187 /* Detect bugs in OpenBSD 3.9 stdint.h. */
189 int check_uint8: (uint8_t) -1 == UINT8_MAX ? 1 : -1;
192 int check_uint16: (uint16_t) -1 == UINT16_MAX ? 1 : -1;
195 int check_uint32: (uint32_t) -1 == UINT32_MAX ? 1 : -1;
198 int check_uint64: (uint64_t) -1 == UINT64_MAX ? 1 : -1;
200 int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1;
201 int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1;
202 int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1;
203 int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1;
204 int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1;
205 int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1;
206 int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1;
207 int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1;
208 int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1;
209 int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1;
210 int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1;
213 [dnl Determine whether the various *_MIN, *_MAX macros are usable
214 dnl in preprocessor expression. We could do it by compiling a test
215 dnl program for each of these macros. It is faster to run a program
216 dnl that inspects the macro expansion.
217 dnl This detects a bug on HP-UX 11.23/ia64.
220 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
227 #define MVAL(macro) MVAL1(macro)
228 #define MVAL1(expression) #expression
229 static const char *macro_values[] =
259 for (mv = macro_values; *mv != NULL; mv++)
261 const char *value = *mv;
262 /* Test whether it looks like a cast expression. */
263 if (strncmp (value, "((unsigned int)"/*)*/, 15) == 0
264 || strncmp (value, "((unsigned short)"/*)*/, 17) == 0
265 || strncmp (value, "((unsigned char)"/*)*/, 16) == 0
266 || strncmp (value, "((int)"/*)*/, 6) == 0
267 || strncmp (value, "((signed short)"/*)*/, 15) == 0
268 || strncmp (value, "((signed char)"/*)*/, 14) == 0)
269 return mv - macro_values + 1;
273 [gl_cv_header_working_stdint_h=yes],
275 [dnl When cross-compiling, assume it works.
276 gl_cv_header_working_stdint_h=yes
281 if test "$gl_cv_header_working_stdint_h" = yes; then
284 dnl Check for <sys/inttypes.h>, and for
285 dnl <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5).
286 AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h])
287 if test $ac_cv_header_sys_inttypes_h = yes; then
288 HAVE_SYS_INTTYPES_H=1
290 HAVE_SYS_INTTYPES_H=0
292 AC_SUBST([HAVE_SYS_INTTYPES_H])
293 if test $ac_cv_header_sys_bitypes_h = yes; then
298 AC_SUBST([HAVE_SYS_BITYPES_H])
300 gl_STDINT_TYPE_PROPERTIES
304 AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"])
307 dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES)
308 dnl Determine the size of each of the given types in bits.
309 AC_DEFUN([gl_STDINT_BITSIZEOF],
311 dnl Use a shell loop, to avoid bloating configure, and
312 dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
314 dnl - extra AC_SUBST calls, so that the right substitutions are made.
315 m4_foreach_w([gltype], [$1],
316 [AH_TEMPLATE([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]),
317 [Define to the number of bits in type ']gltype['.])])
318 for gltype in $1 ; do
319 AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}],
320 [AC_COMPUTE_INT([result], [sizeof ($gltype) * CHAR_BIT],
322 #include <limits.h>], [result=unknown])
323 eval gl_cv_bitsizeof_${gltype}=\$result
325 eval result=\$gl_cv_bitsizeof_${gltype}
326 if test $result = unknown; then
327 dnl Use a nonempty default, because some compilers, such as IRIX 5 cc,
328 dnl do a syntax check even on unused #if conditions and give an error
329 dnl on valid C code like this:
336 GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
337 AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result])
338 eval BITSIZEOF_${GLTYPE}=\$result
340 m4_foreach_w([gltype], [$1],
341 [AC_SUBST([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))])
344 dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES)
345 dnl Determine the signedness of each of the given types.
346 dnl Define HAVE_SIGNED_TYPE if type is signed.
347 AC_DEFUN([gl_CHECK_TYPES_SIGNED],
349 dnl Use a shell loop, to avoid bloating configure, and
350 dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
352 dnl - extra AC_SUBST calls, so that the right substitutions are made.
353 m4_foreach_w([gltype], [$1],
354 [AH_TEMPLATE([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]),
355 [Define to 1 if ']gltype[' is a signed integer type.])])
356 for gltype in $1 ; do
357 AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed],
359 [AC_LANG_PROGRAM([$2[
360 int verify[2 * (($gltype) -1 < ($gltype) 0) - 1];]])],
361 result=yes, result=no)
362 eval gl_cv_type_${gltype}_signed=\$result
364 eval result=\$gl_cv_type_${gltype}_signed
365 GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
366 if test "$result" = yes; then
367 AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], [1])
368 eval HAVE_SIGNED_${GLTYPE}=1
370 eval HAVE_SIGNED_${GLTYPE}=0
373 m4_foreach_w([gltype], [$1],
374 [AC_SUBST([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))])
377 dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES)
378 dnl Determine the suffix to use for integer constants of the given types.
379 dnl Define t_SUFFIX for each such type.
380 AC_DEFUN([gl_INTEGER_TYPE_SUFFIX],
382 dnl Use a shell loop, to avoid bloating configure, and
383 dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
385 dnl - extra AC_SUBST calls, so that the right substitutions are made.
386 m4_foreach_w([gltype], [$1],
387 [AH_TEMPLATE(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX],
388 [Define to l, ll, u, ul, ull, etc., as suitable for
389 constants of type ']gltype['.])])
390 for gltype in $1 ; do
391 AC_CACHE_CHECK([for $gltype integer literal suffix],
392 [gl_cv_type_${gltype}_suffix],
393 [eval gl_cv_type_${gltype}_suffix=no
394 eval result=\$gl_cv_type_${gltype}_signed
395 if test "$result" = yes; then
400 for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do
403 l) gltype1='long int';;
404 ll) gltype1='long long int';;
405 i64) gltype1='__int64';;
406 u) gltype1='unsigned int';;
407 ul) gltype1='unsigned long int';;
408 ull) gltype1='unsigned long long int';;
409 ui64)gltype1='unsigned __int64';;
412 [AC_LANG_PROGRAM([$2[
414 extern $gltype1 foo;]])],
415 [eval gl_cv_type_${gltype}_suffix=\$glsuf])
416 eval result=\$gl_cv_type_${gltype}_suffix
417 test "$result" != no && break
419 GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
420 eval result=\$gl_cv_type_${gltype}_suffix
421 test "$result" = no && result=
422 eval ${GLTYPE}_SUFFIX=\$result
423 AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], [$result])
425 m4_foreach_w([gltype], [$1],
426 [AC_SUBST(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])])
429 dnl gl_STDINT_INCLUDES
430 AC_DEFUN([gl_STDINT_INCLUDES],
432 /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
433 included before <wchar.h>. */
443 dnl gl_STDINT_TYPE_PROPERTIES
444 dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t
445 dnl of interest to stdint.in.h.
446 AC_DEFUN([gl_STDINT_TYPE_PROPERTIES],
448 AC_REQUIRE([gl_MULTIARCH])
449 if test $APPLE_UNIVERSAL_BUILD = 0; then
450 gl_STDINT_BITSIZEOF([ptrdiff_t size_t],
451 [gl_STDINT_INCLUDES])
453 gl_STDINT_BITSIZEOF([sig_atomic_t wchar_t wint_t],
454 [gl_STDINT_INCLUDES])
455 gl_CHECK_TYPES_SIGNED([sig_atomic_t wchar_t wint_t],
456 [gl_STDINT_INCLUDES])
457 gl_cv_type_ptrdiff_t_signed=yes
458 gl_cv_type_size_t_signed=no
459 if test $APPLE_UNIVERSAL_BUILD = 0; then
460 gl_INTEGER_TYPE_SUFFIX([ptrdiff_t size_t],
461 [gl_STDINT_INCLUDES])
463 gl_INTEGER_TYPE_SUFFIX([sig_atomic_t wchar_t wint_t],
464 [gl_STDINT_INCLUDES])
466 dnl If wint_t is smaller than 'int', it cannot satisfy the ISO C 99
467 dnl requirement that wint_t is "unchanged by default argument promotions".
468 dnl In this case gnulib's <wchar.h> and <wctype.h> override wint_t.
469 dnl Set the variable BITSIZEOF_WINT_T accordingly.
470 if test $BITSIZEOF_WINT_T -lt 32; then
475 dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
476 dnl Remove this when we can assume autoconf >= 2.61.
477 m4_ifdef([AC_COMPUTE_INT], [], [
478 AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])
483 # indent-tabs-mode: nil