1 # inttypes.m4 serial 20
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([imaxdiv])
16 AC_CHECK_DECLS_ONCE([strtoimax])
17 AC_CHECK_DECLS_ONCE([strtoumax])
19 dnl Override <inttypes.h> always, so that the portability warnings work.
20 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
21 gl_CHECK_NEXT_HEADERS([inttypes.h])
23 AC_REQUIRE([gl_MULTIARCH])
25 dnl Ensure that <stdint.h> defines the limit macros, since gnulib's
26 dnl <inttypes.h> relies on them. This macro is only needed when a
27 dnl C++ compiler is in use; it has no effect for a C compiler.
28 dnl Also be careful to define __STDC_LIMIT_MACROS only when gnulib's
29 dnl <inttypes.h> is going to be created, and to avoid redefinition warnings
30 dnl if the __STDC_LIMIT_MACROS is already defined through the CPPFLAGS.
31 AC_DEFINE([GL_TRIGGER_STDC_LIMIT_MACROS], [1],
32 [Define to make the limit macros in <stdint.h> visible.])
33 AH_VERBATIM([__STDC_LIMIT_MACROS_ZZZ],
34 [/* Ensure that <stdint.h> defines the limit macros, since gnulib's
35 <inttypes.h> relies on them. */
36 #if defined __cplusplus && !defined __STDC_LIMIT_MACROS && GL_TRIGGER_STDC_LIMIT_MACROS
37 # define __STDC_LIMIT_MACROS 1
42 if test -n "$STDINT_H"; then
43 dnl Using the gnulib <stdint.h>. It always defines intptr_t to 'long'.
46 dnl Using the system's <stdint.h>.
47 for glpfx in '' l ll I64; do
50 l) gltype1='long int';;
51 ll) gltype1='long long int';;
52 I64) gltype1='__int64';;
55 [AC_LANG_PROGRAM([[#include <stdint.h>
57 extern $gltype1 foo;]])],
58 [PRIPTR_PREFIX='"'$glpfx'"'])
59 test -n "$PRIPTR_PREFIX" && break
62 AC_SUBST([PRIPTR_PREFIX])
64 if test "$ac_cv_have_decl_imaxdiv" = yes; then
70 if test "$ac_cv_have_decl_strtoimax" = yes; then
76 if test "$ac_cv_have_decl_strtoumax" = yes; then
82 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
83 [INT32_MAX_LT_INTMAX_MAX],
84 [defined INT32_MAX && defined INTMAX_MAX],
85 [INT32_MAX < INTMAX_MAX],
86 [sizeof (int) < sizeof (long long int)])
87 if test $APPLE_UNIVERSAL_BUILD = 0; then
88 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
89 [INT64_MAX_EQ_LONG_MAX],
91 [INT64_MAX == LONG_MAX],
92 [sizeof (long long int) == sizeof (long int)])
94 INT64_MAX_EQ_LONG_MAX=-1
96 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
97 [UINT32_MAX_LT_UINTMAX_MAX],
98 [defined UINT32_MAX && defined UINTMAX_MAX],
99 [UINT32_MAX < UINTMAX_MAX],
100 [sizeof (unsigned int) < sizeof (unsigned long long int)])
101 if test $APPLE_UNIVERSAL_BUILD = 0; then
102 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
103 [UINT64_MAX_EQ_ULONG_MAX],
104 [defined UINT64_MAX],
105 [UINT64_MAX == ULONG_MAX],
106 [sizeof (unsigned long long int) == sizeof (unsigned long int)])
108 UINT64_MAX_EQ_ULONG_MAX=-1
111 dnl Check for declarations of anything we want to poison if the
112 dnl corresponding gnulib module is not in use.
113 gl_WARN_ON_USE_PREPARE([[#include <inttypes.h>
114 ]], [imaxabs imaxdiv strtoimax strtoumax])
117 # Define the symbol $1 to be 1 if the condition is true, 0 otherwise.
118 # If $2 is true, the condition is $3; otherwise if long long int is supported
119 # approximate the condition with $4; otherwise, assume the condition is false.
120 # The condition should work on all C99 platforms; the approximations should be
121 # good enough to work on all practical pre-C99 platforms.
122 # $2 is evaluated by the C preprocessor, $3 and $4 as compile-time constants.
123 AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION],
125 AC_CACHE_CHECK([whether $3],
129 [[/* Work also in C++ mode. */
130 #define __STDC_LIMIT_MACROS 1
132 /* Work if build is not clean. */
133 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H
141 #define CONDITION ($3)
142 #elif HAVE_LONG_LONG_INT
143 #define CONDITION ($4)
147 int test[CONDITION ? 1 : -1];]])],
149 [gl_cv_test_$1=no])])
150 if test $gl_cv_test_$1 = yes; then
158 AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
160 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
161 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
162 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
165 AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
167 GNULIB_IMAXABS=0; AC_SUBST([GNULIB_IMAXABS])
168 GNULIB_IMAXDIV=0; AC_SUBST([GNULIB_IMAXDIV])
169 GNULIB_STRTOIMAX=0; AC_SUBST([GNULIB_STRTOIMAX])
170 GNULIB_STRTOUMAX=0; AC_SUBST([GNULIB_STRTOUMAX])
171 dnl Assume proper GNU behavior unless another module says otherwise.
172 HAVE_DECL_IMAXABS=1; AC_SUBST([HAVE_DECL_IMAXABS])
173 HAVE_DECL_IMAXDIV=1; AC_SUBST([HAVE_DECL_IMAXDIV])
174 HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
175 HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])