inttypes: Remove configure tests that are not needed since 2009-12-31.
[gnulib.git] / m4 / inttypes.m4
1 # inttypes.m4 serial 19
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.
6
7 dnl From Derek Price, Bruno Haible.
8 dnl Test whether <inttypes.h> is supported or must be substituted.
9
10 AC_DEFUN([gl_INTTYPES_H],
11 [
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])
19
20   dnl Override <inttypes.h> always, so that the portability warnings work.
21   AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
22   gl_CHECK_NEXT_HEADERS([inttypes.h])
23
24   AC_REQUIRE([gl_MULTIARCH])
25
26   dnl Ensure that <stdint.h> defines the limit macros, since gnulib's
27   dnl <inttypes.h> relies on them.  This macro is only needed when a
28   dnl C++ compiler is in use; it has no effect for a C compiler.
29   dnl Also be careful to define __STDC_LIMIT_MACROS only when gnulib's
30   dnl <inttypes.h> is going to be created, and to avoid redefinition warnings
31   dnl if the __STDC_LIMIT_MACROS is already defined through the CPPFLAGS.
32   AC_DEFINE([GL_TRIGGER_STDC_LIMIT_MACROS], [1],
33     [Define to make the limit macros in <stdint.h> visible.])
34   AH_VERBATIM([__STDC_LIMIT_MACROS_ZZZ],
35 [/* Ensure that <stdint.h> defines the limit macros, since gnulib's
36    <inttypes.h> relies on them.  */
37 #if defined __cplusplus && !defined __STDC_LIMIT_MACROS && GL_TRIGGER_STDC_LIMIT_MACROS
38 # define __STDC_LIMIT_MACROS 1
39 #endif
40 ])
41
42   PRIPTR_PREFIX=
43   if test -n "$STDINT_H"; then
44     dnl Using the gnulib <stdint.h>. It always defines intptr_t to 'long'.
45     PRIPTR_PREFIX='"l"'
46   else
47     dnl Using the system's <stdint.h>.
48     for glpfx in '' l ll I64; do
49       case $glpfx in
50         '')  gltype1='int';;
51         l)   gltype1='long int';;
52         ll)  gltype1='long long int';;
53         I64) gltype1='__int64';;
54       esac
55       AC_COMPILE_IFELSE(
56         [AC_LANG_PROGRAM([[#include <stdint.h>
57            extern intptr_t foo;
58            extern $gltype1 foo;]])],
59         [PRIPTR_PREFIX='"'$glpfx'"'])
60       test -n "$PRIPTR_PREFIX" && break
61     done
62   fi
63   AC_SUBST([PRIPTR_PREFIX])
64
65   if test "$ac_cv_have_decl_imaxabs" = yes; then
66     HAVE_DECL_IMAXABS=1
67   else
68     HAVE_DECL_IMAXABS=0
69   fi
70
71   if test "$ac_cv_have_decl_imaxdiv" = yes; then
72     HAVE_DECL_IMAXDIV=1
73   else
74     HAVE_DECL_IMAXDIV=0
75   fi
76
77   if test "$ac_cv_have_decl_strtoimax" = yes; then
78     HAVE_DECL_STRTOIMAX=1
79   else
80     HAVE_DECL_STRTOIMAX=0
81   fi
82
83   if test "$ac_cv_have_decl_strtoumax" = yes; then
84     HAVE_DECL_STRTOUMAX=1
85   else
86     HAVE_DECL_STRTOUMAX=0
87   fi
88
89   gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
90     [INT32_MAX_LT_INTMAX_MAX],
91     [defined INT32_MAX && defined INTMAX_MAX],
92     [INT32_MAX < INTMAX_MAX],
93     [sizeof (int) < sizeof (long long int)])
94   if test $APPLE_UNIVERSAL_BUILD = 0; then
95     gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
96       [INT64_MAX_EQ_LONG_MAX],
97       [defined INT64_MAX],
98       [INT64_MAX == LONG_MAX],
99       [sizeof (long long int) == sizeof (long int)])
100   else
101     INT64_MAX_EQ_LONG_MAX=-1
102   fi
103   gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
104     [UINT32_MAX_LT_UINTMAX_MAX],
105     [defined UINT32_MAX && defined UINTMAX_MAX],
106     [UINT32_MAX < UINTMAX_MAX],
107     [sizeof (unsigned int) < sizeof (unsigned long long int)])
108   if test $APPLE_UNIVERSAL_BUILD = 0; then
109     gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
110       [UINT64_MAX_EQ_ULONG_MAX],
111       [defined UINT64_MAX],
112       [UINT64_MAX == ULONG_MAX],
113       [sizeof (unsigned long long int) == sizeof (unsigned long int)])
114   else
115     UINT64_MAX_EQ_ULONG_MAX=-1
116   fi
117
118   dnl Check for declarations of anything we want to poison if the
119   dnl corresponding gnulib module is not in use.
120   gl_WARN_ON_USE_PREPARE([[#include <inttypes.h>
121     ]], [imaxabs imaxdiv strtoimax strtoumax])
122 ])
123
124 # Define the symbol $1 to be 1 if the condition is true, 0 otherwise.
125 # If $2 is true, the condition is $3; otherwise if long long int is supported
126 # approximate the condition with $4; otherwise, assume the condition is false.
127 # The condition should work on all C99 platforms; the approximations should be
128 # good enough to work on all practical pre-C99 platforms.
129 # $2 is evaluated by the C preprocessor, $3 and $4 as compile-time constants.
130 AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION],
131 [
132   AC_CACHE_CHECK([whether $3],
133     [gl_cv_test_$1],
134     [AC_COMPILE_IFELSE(
135        [AC_LANG_PROGRAM(
136           [[/* Work also in C++ mode.  */
137             #define __STDC_LIMIT_MACROS 1
138
139             /* Work if build is not clean.  */
140             #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H
141
142             #include <limits.h>
143             #if HAVE_STDINT_H
144              #include <stdint.h>
145             #endif
146
147             #if $2
148              #define CONDITION ($3)
149             #elif HAVE_LONG_LONG_INT
150              #define CONDITION ($4)
151             #else
152              #define CONDITION 0
153             #endif
154             int test[CONDITION ? 1 : -1];]])],
155        [gl_cv_test_$1=yes],
156        [gl_cv_test_$1=no])])
157   if test $gl_cv_test_$1 = yes; then
158     $1=1;
159   else
160     $1=0;
161   fi
162   AC_SUBST([$1])
163 ])
164
165 AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
166 [
167   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
168   AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
169   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
170 ])
171
172 AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
173 [
174   GNULIB_IMAXABS=0;      AC_SUBST([GNULIB_IMAXABS])
175   GNULIB_IMAXDIV=0;      AC_SUBST([GNULIB_IMAXDIV])
176   GNULIB_STRTOIMAX=0;    AC_SUBST([GNULIB_STRTOIMAX])
177   GNULIB_STRTOUMAX=0;    AC_SUBST([GNULIB_STRTOUMAX])
178   dnl Assume proper GNU behavior unless another module says otherwise.
179   HAVE_DECL_IMAXABS=1;   AC_SUBST([HAVE_DECL_IMAXABS])
180   HAVE_DECL_IMAXDIV=1;   AC_SUBST([HAVE_DECL_IMAXDIV])
181   HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
182   HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])
183 ])