1 # inttypes.m4 serial 15
2 dnl Copyright (C) 2006-2009 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 Derek Price, Bruno Haible.
8 dnl Test whether <inttypes.h> is supported or must be substituted.
10 AC_DEFUN([gl_INTTYPES_H],
12 AC_REQUIRE([gl_STDINT_H])
13 AC_REQUIRE([gt_INTTYPES_PRI])
14 AC_CHECK_DECLS_ONCE([imaxabs])
15 AC_CHECK_DECLS_ONCE([imaxdiv])
16 AC_CHECK_DECLS_ONCE([strtoimax])
17 AC_CHECK_DECLS_ONCE([strtoumax])
19 dnl Now see if we need a substitute <inttypes.h>.
20 dnl A complete <inttypes.h> requires
21 dnl - a complete <stdint.h>,
22 dnl - the existence of an <inttypes.h>,
23 dnl - that imaxabs, imaxdiv, strtoimax, strtoumax are declared,
24 dnl - some additional tests.
25 AC_CACHE_CHECK([whether inttypes.h conforms to C99],
26 [gl_cv_header_working_inttypes_h],
27 [gl_cv_header_working_inttypes_h=no
28 if test "$gl_cv_header_working_stdint_h" = yes \
29 && test $ac_cv_header_inttypes_h = yes \
30 && test "$ac_cv_have_decl_imaxabs" = yes \
31 && test "$ac_cv_have_decl_imaxdiv" = yes \
32 && test "$ac_cv_have_decl_strtoimax" = yes \
33 && test "$ac_cv_have_decl_strtoumax" = yes; then
37 #define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
38 #define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */
39 #define __STDC_FORMAT_MACROS 1 /* to make it work also in C++ mode */
40 #define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H /* work if build isn't clean */
43 /* No need to duplicate the tests of stdint.m4; they are subsumed by
44 $gl_cv_header_working_stdint_h = yes. */
46 /* Tests for macros supposed to be defined in inttypes.h. */
48 const char *k = /* implicit string concatenation */
53 PRIo8 PRIu8 PRIx8 PRIX8
59 PRIo16 PRIu16 PRIx16 PRIX16
65 PRIo32 PRIu32 PRIx32 PRIX32
71 PRIo64 PRIu64 PRIx64 PRIX64
73 PRIdLEAST8 PRIiLEAST8 PRIoLEAST8 PRIuLEAST8 PRIxLEAST8 PRIXLEAST8
74 PRIdLEAST16 PRIiLEAST16 PRIoLEAST16 PRIuLEAST16 PRIxLEAST16 PRIXLEAST16
75 PRIdLEAST32 PRIiLEAST32 PRIoLEAST32 PRIuLEAST32 PRIxLEAST32 PRIXLEAST32
76 PRIdLEAST64 PRIiLEAST64
77 PRIoLEAST64 PRIuLEAST64 PRIxLEAST64 PRIXLEAST64
78 PRIdFAST8 PRIiFAST8 PRIoFAST8 PRIuFAST8 PRIxFAST8 PRIXFAST8
79 PRIdFAST16 PRIiFAST16 PRIoFAST16 PRIuFAST16 PRIxFAST16 PRIXFAST16
80 PRIdFAST32 PRIiFAST32 PRIoFAST32 PRIuFAST32 PRIxFAST32 PRIXFAST32
82 PRIoFAST64 PRIuFAST64 PRIxFAST64 PRIXFAST64
83 PRIdMAX PRIiMAX PRIoMAX PRIuMAX PRIxMAX PRIXMAX
88 PRIoPTR PRIuPTR PRIxPTR PRIXPTR
91 const char *l = /* implicit string concatenation */
116 SCNdLEAST8 SCNiLEAST8 SCNoLEAST8 SCNuLEAST8 SCNxLEAST8
117 SCNdLEAST16 SCNiLEAST16 SCNoLEAST16 SCNuLEAST16 SCNxLEAST16
118 SCNdLEAST32 SCNiLEAST32 SCNoLEAST32 SCNuLEAST32 SCNxLEAST32
119 SCNdLEAST64 SCNiLEAST64
120 SCNoLEAST64 SCNuLEAST64 SCNxLEAST64
121 SCNdFAST8 SCNiFAST8 SCNoFAST8 SCNuFAST8 SCNxFAST8
122 SCNdFAST16 SCNiFAST16 SCNoFAST16 SCNuFAST16 SCNxFAST16
123 SCNdFAST32 SCNiFAST32 SCNoFAST32 SCNuFAST32 SCNxFAST32
124 SCNdFAST64 SCNiFAST64
125 SCNoFAST64 SCNuFAST64 SCNxFAST64
126 SCNdMAX SCNiMAX SCNoMAX SCNuMAX SCNxMAX
131 SCNoPTR SCNuPTR SCNxPTR
135 [gl_cv_header_working_inttypes_h=yes])
138 dnl Override <inttypes.h> always, so that the portability warnings work.
139 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
140 gl_CHECK_NEXT_HEADERS([inttypes.h])
142 AC_REQUIRE([gl_MULTIARCH])
144 dnl Ensure that <stdint.h> defines the limit macros, since gnulib's
145 dnl <inttypes.h> relies on them. This macro is only needed when a
146 dnl C++ compiler is in use; it has no effect for a C compiler.
147 dnl Also be careful to define __STDC_LIMIT_MACROS only when gnulib's
148 dnl <inttypes.h> is going to be created, and to avoid redefinition warnings
149 dnl if the __STDC_LIMIT_MACROS is already defined through the CPPFLAGS.
150 AC_DEFINE([GL_TRIGGER_STDC_LIMIT_MACROS], [1],
151 [Define to make the limit macros in <stdint.h> visible.])
152 AH_VERBATIM([__STDC_LIMIT_MACROS_ZZZ],
153 [/* Ensure that <stdint.h> defines the limit macros, since gnulib's
154 <inttypes.h> relies on them. */
155 #if defined __cplusplus && !defined __STDC_LIMIT_MACROS && GL_TRIGGER_STDC_LIMIT_MACROS
156 # define __STDC_LIMIT_MACROS 1
161 if test -n "$STDINT_H"; then
162 dnl Using the gnulib <stdint.h>. It always defines intptr_t to 'long'.
165 dnl Using the system's <stdint.h>.
166 for glpfx in '' l ll I64; do
169 l) gltype1='long int';;
170 ll) gltype1='long long int';;
171 I64) gltype1='__int64';;
174 [AC_LANG_PROGRAM([[#include <stdint.h>
176 extern $gltype1 foo;]])],
177 [PRIPTR_PREFIX='"'$glpfx'"'])
178 test -n "$PRIPTR_PREFIX" && break
181 AC_SUBST([PRIPTR_PREFIX])
183 if test "$ac_cv_have_decl_imaxabs" = yes; then
189 if test "$ac_cv_have_decl_imaxdiv" = yes; then
195 if test "$ac_cv_have_decl_strtoimax" = yes; then
196 HAVE_DECL_STRTOIMAX=1
198 HAVE_DECL_STRTOIMAX=0
201 if test "$ac_cv_have_decl_strtoumax" = yes; then
202 HAVE_DECL_STRTOUMAX=1
204 HAVE_DECL_STRTOUMAX=0
207 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
208 [INT32_MAX_LT_INTMAX_MAX],
209 [defined INT32_MAX && defined INTMAX_MAX],
210 [INT32_MAX < INTMAX_MAX],
211 [sizeof (int) < sizeof (long long int)])
212 if test $APPLE_UNIVERSAL_BUILD = 0; then
213 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
214 [INT64_MAX_EQ_LONG_MAX],
216 [INT64_MAX == LONG_MAX],
217 [sizeof (long long int) == sizeof (long int)])
219 INT64_MAX_EQ_LONG_MAX=-1
221 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
222 [UINT32_MAX_LT_UINTMAX_MAX],
223 [defined UINT32_MAX && defined UINTMAX_MAX],
224 [UINT32_MAX < UINTMAX_MAX],
225 [sizeof (unsigned int) < sizeof (unsigned long long int)])
226 if test $APPLE_UNIVERSAL_BUILD = 0; then
227 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
228 [UINT64_MAX_EQ_ULONG_MAX],
229 [defined UINT64_MAX],
230 [UINT64_MAX == ULONG_MAX],
231 [sizeof (unsigned long long int) == sizeof (unsigned long int)])
233 UINT64_MAX_EQ_ULONG_MAX=-1
237 # Define the symbol $1 to be 1 if the condition is true, 0 otherwise.
238 # If $2 is true, the condition is $3; otherwise if long long int is supported
239 # approximate the condition with $4; otherwise, assume the condition is false.
240 # The condition should work on all C99 platforms; the approximations should be
241 # good enough to work on all practical pre-C99 platforms.
242 # $2 is evaluated by the C preprocessor, $3 and $4 as compile-time constants.
243 AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION],
245 AC_CACHE_CHECK([whether $3],
249 [[/* Work also in C++ mode. */
250 #define __STDC_LIMIT_MACROS 1
252 /* Work if build is not clean. */
253 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H
261 #define CONDITION ($3)
262 #elif HAVE_LONG_LONG_INT
263 #define CONDITION ($4)
267 int test[CONDITION ? 1 : -1];]])],
269 [gl_cv_test_$1=no])])
270 if test $gl_cv_test_$1 = yes; then
278 AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
280 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
281 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
282 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
285 AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
287 GNULIB_IMAXABS=0; AC_SUBST([GNULIB_IMAXABS])
288 GNULIB_IMAXDIV=0; AC_SUBST([GNULIB_IMAXDIV])
289 GNULIB_STRTOIMAX=0; AC_SUBST([GNULIB_STRTOIMAX])
290 GNULIB_STRTOUMAX=0; AC_SUBST([GNULIB_STRTOUMAX])
291 dnl Assume proper GNU behavior unless another module says otherwise.
292 HAVE_DECL_IMAXABS=1; AC_SUBST([HAVE_DECL_IMAXABS])
293 HAVE_DECL_IMAXDIV=1; AC_SUBST([HAVE_DECL_IMAXDIV])
294 HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
295 HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])