2 dnl Copyright (C) 2006-2007 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 #include ABSOLUTE_INTTYPES_H
42 /* No need to duplicate the tests of stdint.m4; they are subsumed by
43 $gl_cv_header_working_stdint_h = yes. */
45 /* Tests for macros supposed to be defined in inttypes.h. */
47 const char *k = /* implicit string concatenation */
52 PRIo8 PRIu8 PRIx8 PRIX8
58 PRIo16 PRIu16 PRIx16 PRIX16
64 PRIo32 PRIu32 PRIx32 PRIX32
70 PRIo64 PRIu64 PRIx64 PRIX64
72 PRIdLEAST8 PRIiLEAST8 PRIoLEAST8 PRIuLEAST8 PRIxLEAST8 PRIXLEAST8
73 PRIdLEAST16 PRIiLEAST16 PRIoLEAST16 PRIuLEAST16 PRIxLEAST16 PRIXLEAST16
74 PRIdLEAST32 PRIiLEAST32 PRIoLEAST32 PRIuLEAST32 PRIxLEAST32 PRIXLEAST32
75 PRIdLEAST64 PRIiLEAST64
76 PRIoLEAST64 PRIuLEAST64 PRIxLEAST64 PRIXLEAST64
77 PRIdFAST8 PRIiFAST8 PRIoFAST8 PRIuFAST8 PRIxFAST8 PRIXFAST8
78 PRIdFAST16 PRIiFAST16 PRIoFAST16 PRIuFAST16 PRIxFAST16 PRIXFAST16
79 PRIdFAST32 PRIiFAST32 PRIoFAST32 PRIuFAST32 PRIxFAST32 PRIXFAST32
81 PRIoFAST64 PRIuFAST64 PRIxFAST64 PRIXFAST64
82 PRIdMAX PRIiMAX PRIoMAX PRIuMAX PRIxMAX PRIXMAX
87 PRIoPTR PRIuPTR PRIxPTR PRIXPTR
90 const char *l = /* implicit string concatenation */
115 SCNdLEAST8 SCNiLEAST8 SCNoLEAST8 SCNuLEAST8 SCNxLEAST8
116 SCNdLEAST16 SCNiLEAST16 SCNoLEAST16 SCNuLEAST16 SCNxLEAST16
117 SCNdLEAST32 SCNiLEAST32 SCNoLEAST32 SCNuLEAST32 SCNxLEAST32
118 SCNdLEAST64 SCNiLEAST64
119 SCNoLEAST64 SCNuLEAST64 SCNxLEAST64
120 SCNdFAST8 SCNiFAST8 SCNoFAST8 SCNuFAST8 SCNxFAST8
121 SCNdFAST16 SCNiFAST16 SCNoFAST16 SCNuFAST16 SCNxFAST16
122 SCNdFAST32 SCNiFAST32 SCNoFAST32 SCNuFAST32 SCNxFAST32
123 SCNdFAST64 SCNiFAST64
124 SCNoFAST64 SCNuFAST64 SCNxFAST64
125 SCNdMAX SCNiMAX SCNoMAX SCNuMAX SCNxMAX
130 SCNoPTR SCNuPTR SCNxPTR
134 [gl_cv_header_working_inttypes_h=yes])
137 dnl Override <inttypes.h> always, so that the portability warnings work.
138 if false && test $gl_cv_header_working_inttypes_h = yes; then
139 dnl Use the existing <inttypes.h>.
143 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
144 dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h.
145 if test $ac_cv_header_inttypes_h = yes; then
146 gl_ABSOLUTE_HEADER([inttypes.h])
147 ABSOLUTE_INTTYPES_H=\"$gl_cv_absolute_inttypes_h\"
149 ABSOLUTE_INTTYPES_H=\"no/such/file/inttypes.h\"
151 AC_SUBST([ABSOLUTE_INTTYPES_H])
154 if test -n "$STDINT_H"; then
155 dnl Using the gnulib <stdint.h>. It always defines intptr_t to 'long'.
158 dnl Using the system's <stdint.h>.
159 for glpfx in '' l ll I64; do
162 l) gltype1='long int';;
163 ll) gltype1='long long int';;
164 I64) gltype1='__int64';;
167 [AC_LANG_PROGRAM([#include <stdint.h>
169 extern $gltype1 foo;])],
170 [PRIPTR_PREFIX='"'$glpfx'"'])
171 test -n "$PRIPTR_PREFIX" && break
174 AC_SUBST([PRIPTR_PREFIX])
176 if test "$ac_cv_have_decl_imaxabs" = yes; then
182 if test "$ac_cv_have_decl_imaxdiv" = yes; then
188 if test "$ac_cv_have_decl_strtoimax" = yes; then
189 HAVE_DECL_STRTOIMAX=1
191 HAVE_DECL_STRTOIMAX=0
194 if test "$ac_cv_have_decl_strtoumax" = yes; then
195 HAVE_DECL_STRTOUMAX=1
197 HAVE_DECL_STRTOUMAX=0
200 INTTYPES_H='inttypes.h'
205 AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
207 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
208 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
209 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
212 AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
214 GNULIB_IMAXABS=0; AC_SUBST([GNULIB_IMAXABS])
215 GNULIB_IMAXDIV=0; AC_SUBST([GNULIB_IMAXDIV])
216 GNULIB_STRTOIMAX=0; AC_SUBST([GNULIB_STRTOIMAX])
217 GNULIB_STRTOUMAX=0; AC_SUBST([GNULIB_STRTOUMAX])
218 dnl Assume proper GNU behavior unless another module says otherwise.
219 HAVE_DECL_IMAXABS=1; AC_SUBST([HAVE_DECL_IMAXABS])
220 HAVE_DECL_IMAXDIV=1; AC_SUBST([HAVE_DECL_IMAXDIV])
221 HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
222 HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])