Debian Codegraph @

m4/inttypes.m4

raw
1 # inttypes.m4
2 # serial 37
3 dnl Copyright (C) 2006-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 dnl From Derek Price, Bruno Haible.
10 dnl Test whether <inttypes.h> is supported or must be substituted.
11
12 AC_DEFUN_ONCE([gl_INTTYPES_H],
13 [
14 AC_REQUIRE([gl_INTTYPES_INCOMPLETE])
15 gl_INTTYPES_PRI_SCN
16 ])
17
18 AC_DEFUN_ONCE([gl_INTTYPES_INCOMPLETE],
19 [
20 AC_REQUIRE([gl_STDINT_H])
21 AC_CHECK_HEADERS_ONCE([inttypes.h])
22
23 dnl Override <inttypes.h> always, so that the portability warnings work.
24 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
25 gl_CHECK_NEXT_HEADERS([inttypes.h])
26
27 AC_REQUIRE([gl_MULTIARCH])
28
29 dnl Check for declarations of anything we want to poison if the
30 dnl corresponding gnulib module is not in use.
31 gl_WARN_ON_USE_PREPARE([[#include <inttypes.h>
32 ]], [imaxabs imaxdiv strtoimax strtoumax])
33
34 AC_REQUIRE([AC_C_RESTRICT])
35 ])
36
37 # Ensure that the PRI* and SCN* macros are defined appropriately.
38 AC_DEFUN([gl_INTTYPES_PRI_SCN],
39 [
40 PRIPTR_PREFIX=
41 if $GL_GENERATE_STDINT_H; then
42 dnl Using the gnulib <stdint.h>. It defines intptr_t to 'long' or
43 dnl 'long long', depending on _WIN64.
44 AC_COMPILE_IFELSE(
45 [AC_LANG_PROGRAM([[
46 #ifdef _WIN64
47 LLP64
48 #endif
49 ]])
50 ],
51 [PRIPTR_PREFIX='"l"'],
52 [PRIPTR_PREFIX='"ll"'])
53 else
54 dnl Using the system's <stdint.h>.
55 for glpfx in '' l ll I64; do
56 case $glpfx in
57 '') gltype1='int';;
58 l) gltype1='long int';;
59 ll) gltype1='long long int';;
60 I64) gltype1='__int64';;
61 esac
62 AC_COMPILE_IFELSE(
63 [AC_LANG_PROGRAM([[#include <stdint.h>
64 extern intptr_t foo;
65 extern $gltype1 foo;]])],
66 [PRIPTR_PREFIX='"'$glpfx'"'])
67 test -n "$PRIPTR_PREFIX" && break
68 done
69 fi
70 AC_SUBST([PRIPTR_PREFIX])
71
72 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
73 [INT32_MAX_LT_INTMAX_MAX],
74 [defined INT32_MAX && defined INTMAX_MAX],
75 [INT32_MAX < INTMAX_MAX],
76 [sizeof (int) < sizeof (long long int)])
77 if test $APPLE_UNIVERSAL_BUILD = 0; then
78 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
79 [INT64_MAX_EQ_LONG_MAX],
80 [defined INT64_MAX],
81 [INT64_MAX == LONG_MAX],
82 [sizeof (long long int) == sizeof (long int)])
83 else
84 INT64_MAX_EQ_LONG_MAX=-1
85 fi
86 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
87 [UINT32_MAX_LT_UINTMAX_MAX],
88 [defined UINT32_MAX && defined UINTMAX_MAX],
89 [UINT32_MAX < UINTMAX_MAX],
90 [sizeof (unsigned int) < sizeof (unsigned long long int)])
91 if test $APPLE_UNIVERSAL_BUILD = 0; then
92 gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
93 [UINT64_MAX_EQ_ULONG_MAX],
94 [defined UINT64_MAX],
95 [UINT64_MAX == ULONG_MAX],
96 [sizeof (unsigned long long int) == sizeof (unsigned long int)])
97 else
98 UINT64_MAX_EQ_ULONG_MAX=-1
99 fi
100 ])
101
102 # Define the symbol $1 to be 1 if the condition is true, 0 otherwise.
103 # If $2 is true, the condition is $3; otherwise if long long int is supported
104 # approximate the condition with $4; otherwise, assume the condition is false.
105 # The condition should work on all C99 platforms; the approximations should be
106 # good enough to work on all practical pre-C99 platforms.
107 # $2 is evaluated by the C preprocessor, $3 and $4 as compile-time constants.
108 AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION],
109 [
110 AC_CACHE_CHECK([whether $3],
111 [gl_cv_test_$1],
112 [AC_COMPILE_IFELSE(
113 [AC_LANG_PROGRAM(
114 [[/* Work also in C++ mode. */
115 #define __STDC_LIMIT_MACROS 1
116
117 /* Work if build is not clean. */
118 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H
119
120 #include <limits.h>
121 #if HAVE_STDINT_H
122 #include <stdint.h>
123 #endif
124
125 #if $2
126 #define CONDITION ($3)
127 #else
128 #define CONDITION ($4)
129 #endif
130 int test[CONDITION ? 1 : -1];]])],
131 [gl_cv_test_$1=yes],
132 [gl_cv_test_$1=no])])
133 if test $gl_cv_test_$1 = yes; then
134 $1=1;
135 else
136 $1=0;
137 fi
138 AC_SUBST([$1])
139 ])
140
141 # gl_INTTYPES_MODULE_INDICATOR([modulename])
142 # sets the shell variable that indicates the presence of the given module
143 # to a C preprocessor expression that will evaluate to 1.
144 # This macro invocation must not occur in macros that are AC_REQUIREd.
145 AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
146 [
147 dnl Ensure to expand the default settings once only.
148 gl_INTTYPES_H_REQUIRE_DEFAULTS
149 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
150 ])
151
152 # Initializes the default values for AC_SUBSTed shell variables.
153 # This macro must not be AC_REQUIREd. It must only be invoked, and only
154 # outside of macros or in macros that are not AC_REQUIREd.
155 AC_DEFUN([gl_INTTYPES_H_REQUIRE_DEFAULTS],
156 [
157 m4_defun(GL_MODULE_INDICATOR_PREFIX[_INTTYPES_H_MODULE_INDICATOR_DEFAULTS], [
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_IMAXABS])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_IMAXDIV])
160 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOIMAX])
161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOUMAX])
162 ])
163 m4_require(GL_MODULE_INDICATOR_PREFIX[_INTTYPES_H_MODULE_INDICATOR_DEFAULTS])
164 AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
165 ])
166
167 AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
168 [
169 dnl Assume proper GNU behavior unless another module says otherwise.
170 HAVE_DECL_IMAXABS=1; AC_SUBST([HAVE_DECL_IMAXABS])
171 HAVE_DECL_IMAXDIV=1; AC_SUBST([HAVE_DECL_IMAXDIV])
172 HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
173 HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])
174 HAVE_IMAXDIV_T=1; AC_SUBST([HAVE_IMAXDIV_T])
175 HAVE_IMAXABS=1; AC_SUBST([HAVE_IMAXABS])
176 HAVE_IMAXDIV=1; AC_SUBST([HAVE_IMAXDIV])
177 REPLACE_IMAXABS=0; AC_SUBST([REPLACE_IMAXABS])
178 REPLACE_IMAXDIV=0; AC_SUBST([REPLACE_IMAXDIV])
179 REPLACE_STRTOIMAX=0; AC_SUBST([REPLACE_STRTOIMAX])
180 REPLACE_STRTOUMAX=0; AC_SUBST([REPLACE_STRTOUMAX])
181 INT32_MAX_LT_INTMAX_MAX=1; AC_SUBST([INT32_MAX_LT_INTMAX_MAX])
182 INT64_MAX_EQ_LONG_MAX='defined _LP64'; AC_SUBST([INT64_MAX_EQ_LONG_MAX])
183 PRIPTR_PREFIX=__PRIPTR_PREFIX; AC_SUBST([PRIPTR_PREFIX])
184 UINT32_MAX_LT_UINTMAX_MAX=1; AC_SUBST([UINT32_MAX_LT_UINTMAX_MAX])
185 UINT64_MAX_EQ_ULONG_MAX='defined _LP64'; AC_SUBST([UINT64_MAX_EQ_ULONG_MAX])
186 ])