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