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