1 # inttypes.m4 serial 18
2 dnl Copyright (C) 2006-2011 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_HEADERS_ONCE([inttypes.h])
15 AC_CHECK_DECLS_ONCE([imaxabs])
16 AC_CHECK_DECLS_ONCE([imaxdiv])
17 AC_CHECK_DECLS_ONCE([strtoimax])
18 AC_CHECK_DECLS_ONCE([strtoumax])
20 dnl Now see if we need a substitute <inttypes.h>.
21 dnl A complete <inttypes.h> requires
22 dnl - a complete <stdint.h>,
23 dnl - the existence of an <inttypes.h>,
24 dnl - that imaxabs, imaxdiv, strtoimax, strtoumax are declared,
25 dnl - some additional tests.
26 AC_CACHE_CHECK([whether inttypes.h conforms to C99],
27 [gl_cv_header_working_inttypes_h],
28 [gl_cv_header_working_inttypes_h=no
29 if test "$gl_cv_header_working_stdint_h" = yes \
30 && test $ac_cv_header_inttypes_h = yes \
31 && test "$ac_cv_have_decl_imaxabs" = yes \
32 && test "$ac_cv_have_decl_imaxdiv" = yes \
33 && test "$ac_cv_have_decl_strtoimax" = yes \
34 && test "$ac_cv_have_decl_strtoumax" = yes; then
38 #define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
39 #define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */
40 #define __STDC_FORMAT_MACROS 1 /* to make it work also in C++ mode */
41 #define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H /* work if build isn't clean */
44 /* No need to duplicate the tests of stdint.m4; they are subsumed by
45 $gl_cv_header_working_stdint_h = yes. */
47 /* Tests for macros supposed to be defined in inttypes.h. */
49 const char *k = /* implicit string concatenation */
54 PRIo8 PRIu8 PRIx8 PRIX8
60 PRIo16 PRIu16 PRIx16 PRIX16
66 PRIo32 PRIu32 PRIx32 PRIX32
72 PRIo64 PRIu64 PRIx64 PRIX64
74 PRIdLEAST8 PRIiLEAST8 PRIoLEAST8 PRIuLEAST8 PRIxLEAST8 PRIXLEAST8
75 PRIdLEAST16 PRIiLEAST16 PRIoLEAST16 PRIuLEAST16 PRIxLEAST16 PRIXLEAST16
76 PRIdLEAST32 PRIiLEAST32 PRIoLEAST32 PRIuLEAST32 PRIxLEAST32 PRIXLEAST32
77 PRIdLEAST64 PRIiLEAST64
78 PRIoLEAST64 PRIuLEAST64 PRIxLEAST64 PRIXLEAST64
79 PRIdFAST8 PRIiFAST8 PRIoFAST8 PRIuFAST8 PRIxFAST8 PRIXFAST8
80 PRIdFAST16 PRIiFAST16 PRIoFAST16 PRIuFAST16 PRIxFAST16 PRIXFAST16
81 PRIdFAST32 PRIiFAST32 PRIoFAST32 PRIuFAST32 PRIxFAST32 PRIXFAST32
83 PRIoFAST64 PRIuFAST64 PRIxFAST64 PRIXFAST64
84 PRIdMAX PRIiMAX PRIoMAX PRIuMAX PRIxMAX PRIXMAX
89 PRIoPTR PRIuPTR PRIxPTR PRIXPTR
92 const char *l = /* implicit string concatenation */
117 SCNdLEAST8 SCNiLEAST8 SCNoLEAST8 SCNuLEAST8 SCNxLEAST8
118 SCNdLEAST16 SCNiLEAST16 SCNoLEAST16 SCNuLEAST16 SCNxLEAST16
119 SCNdLEAST32 SCNiLEAST32 SCNoLEAST32 SCNuLEAST32 SCNxLEAST32
120 SCNdLEAST64 SCNiLEAST64
121 SCNoLEAST64 SCNuLEAST64 SCNxLEAST64
122 SCNdFAST8 SCNiFAST8 SCNoFAST8 SCNuFAST8 SCNxFAST8
123 SCNdFAST16 SCNiFAST16 SCNoFAST16 SCNuFAST16 SCNxFAST16
124 SCNdFAST32 SCNiFAST32 SCNoFAST32 SCNuFAST32 SCNxFAST32
125 SCNdFAST64 SCNiFAST64
126 SCNoFAST64 SCNuFAST64 SCNxFAST64
127 SCNdMAX SCNiMAX SCNoMAX SCNuMAX SCNxMAX
132 SCNoPTR SCNuPTR SCNxPTR
136 [gl_cv_header_working_inttypes_h=yes])
139 dnl Override <inttypes.h> always, so that the portability warnings work.
140 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
141 gl_CHECK_NEXT_HEADERS([inttypes.h])
143 AC_REQUIRE([gl_MULTIARCH])
145 dnl Ensure that <stdint.h> defines the limit macros, since gnulib's
146 dnl <inttypes.h> relies on them. This macro is only needed when a
147 dnl C++ compiler is in use; it has no effect for a C compiler.
148 dnl Also be careful to define __STDC_LIMIT_MACROS only when gnulib's
149 dnl <inttypes.h> is going to be created, and to avoid redefinition warnings
150 dnl if the __STDC_LIMIT_MACROS is already defined through the CPPFLAGS.
151 AC_DEFINE([GL_TRIGGER_STDC_LIMIT_MACROS], [1],
152 [Define to make the limit macros in <stdint.h> visible.])
153 AH_VERBATIM([__STDC_LIMIT_MACROS_ZZZ],
154 [/* Ensure that <stdint.h> defines the limit macros, since gnulib's
155 <inttypes.h> relies on them. */
156 #if defined __cplusplus && !defined __STDC_LIMIT_MACROS && GL_TRIGGER_STDC_LIMIT_MACROS
157 # define __STDC_LIMIT_MACROS 1
162 if test -n "$STDINT_H"; then
163 dnl Using the gnulib <stdint.h>. It always defines intptr_t to 'long'.
166 dnl Using the system's <stdint.h>.
167 for glpfx in '' l ll I64; do
170 l) gltype1='long int';;
171 ll) gltype1='long long int';;
172 I64) gltype1='__int64';;
175 [AC_LANG_PROGRAM([[#include <stdint.h>
177 extern $gltype1 foo;]])],
178 [PRIPTR_PREFIX='"'$glpfx'"'])
179 test -n "$PRIPTR_PREFIX" && break
182 AC_SUBST([PRIPTR_PREFIX])
184 if test "$ac_cv_have_decl_imaxabs" = yes; then
190 if test "$ac_cv_have_decl_imaxdiv" = yes; then
196 if test "$ac_cv_have_decl_strtoimax" = yes; then
197 HAVE_DECL_STRTOIMAX=1
199 HAVE_DECL_STRTOIMAX=0
202 if test "$ac_cv_have_decl_strtoumax" = yes; then
203 HAVE_DECL_STRTOUMAX=1
205 HAVE_DECL_STRTOUMAX=0
208 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
209 [INT32_MAX_LT_INTMAX_MAX],
210 [defined INT32_MAX && defined INTMAX_MAX],
211 [INT32_MAX < INTMAX_MAX],
212 [sizeof (int) < sizeof (long long int)])
213 if test $APPLE_UNIVERSAL_BUILD = 0; then
214 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
215 [INT64_MAX_EQ_LONG_MAX],
217 [INT64_MAX == LONG_MAX],
218 [sizeof (long long int) == sizeof (long int)])
220 INT64_MAX_EQ_LONG_MAX=-1
222 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
223 [UINT32_MAX_LT_UINTMAX_MAX],
224 [defined UINT32_MAX && defined UINTMAX_MAX],
225 [UINT32_MAX < UINTMAX_MAX],
226 [sizeof (unsigned int) < sizeof (unsigned long long int)])
227 if test $APPLE_UNIVERSAL_BUILD = 0; then
228 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
229 [UINT64_MAX_EQ_ULONG_MAX],
230 [defined UINT64_MAX],
231 [UINT64_MAX == ULONG_MAX],
232 [sizeof (unsigned long long int) == sizeof (unsigned long int)])
234 UINT64_MAX_EQ_ULONG_MAX=-1
237 dnl Check for declarations of anything we want to poison if the
238 dnl corresponding gnulib module is not in use.
239 gl_WARN_ON_USE_PREPARE([[#include <inttypes.h>
240 ]], [imaxabs imaxdiv strtoimax strtoumax])
243 # Define the symbol $1 to be 1 if the condition is true, 0 otherwise.
244 # If $2 is true, the condition is $3; otherwise if long long int is supported
245 # approximate the condition with $4; otherwise, assume the condition is false.
246 # The condition should work on all C99 platforms; the approximations should be
247 # good enough to work on all practical pre-C99 platforms.
248 # $2 is evaluated by the C preprocessor, $3 and $4 as compile-time constants.
249 AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION],
251 AC_CACHE_CHECK([whether $3],
255 [[/* Work also in C++ mode. */
256 #define __STDC_LIMIT_MACROS 1
258 /* Work if build is not clean. */
259 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H
267 #define CONDITION ($3)
268 #elif HAVE_LONG_LONG_INT
269 #define CONDITION ($4)
273 int test[CONDITION ? 1 : -1];]])],
275 [gl_cv_test_$1=no])])
276 if test $gl_cv_test_$1 = yes; then
284 AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
286 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
287 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
288 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
291 AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
293 GNULIB_IMAXABS=0; AC_SUBST([GNULIB_IMAXABS])
294 GNULIB_IMAXDIV=0; AC_SUBST([GNULIB_IMAXDIV])
295 GNULIB_STRTOIMAX=0; AC_SUBST([GNULIB_STRTOIMAX])
296 GNULIB_STRTOUMAX=0; AC_SUBST([GNULIB_STRTOUMAX])
297 dnl Assume proper GNU behavior unless another module says otherwise.
298 HAVE_DECL_IMAXABS=1; AC_SUBST([HAVE_DECL_IMAXABS])
299 HAVE_DECL_IMAXDIV=1; AC_SUBST([HAVE_DECL_IMAXDIV])
300 HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
301 HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])