Commit | Line | Data |
---|---|---|
9c9d63b1 PM |
1 | # inttypes.m4 serial 32 |
2 | dnl Copyright (C) 2006-2021 Free Software Foundation, Inc. | |
55a8c076 YQ |
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], | |
770d76d7 PA |
11 | [ |
12 | AC_REQUIRE([gl_INTTYPES_INCOMPLETE]) | |
13 | gl_INTTYPES_PRI_SCN | |
14 | ]) | |
15 | ||
16 | AC_DEFUN_ONCE([gl_INTTYPES_INCOMPLETE], | |
55a8c076 YQ |
17 | [ |
18 | AC_REQUIRE([gl_STDINT_H]) | |
55a8c076 | 19 | AC_CHECK_HEADERS_ONCE([inttypes.h]) |
55a8c076 YQ |
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 | ||
770d76d7 PA |
27 | dnl Check for declarations of anything we want to poison if the |
28 | dnl corresponding gnulib module is not in use. | |
29 | gl_WARN_ON_USE_PREPARE([[#include <inttypes.h> | |
30 | ]], [imaxabs imaxdiv strtoimax strtoumax]) | |
698be2d8 CB |
31 | |
32 | AC_REQUIRE([AC_C_RESTRICT]) | |
55a8c076 YQ |
33 | ]) |
34 | ||
770d76d7 PA |
35 | # Ensure that the PRI* and SCN* macros are defined appropriately. |
36 | AC_DEFUN([gl_INTTYPES_PRI_SCN], | |
37 | [ | |
55a8c076 YQ |
38 | PRIPTR_PREFIX= |
39 | if test -n "$STDINT_H"; then | |
9c9d63b1 PM |
40 | dnl Using the gnulib <stdint.h>. It defines intptr_t to 'long' or |
41 | dnl 'long long', depending on _WIN64. | |
42 | AC_COMPILE_IFELSE( | |
43 | [AC_LANG_PROGRAM([[ | |
44 | #ifdef _WIN64 | |
45 | LLP64 | |
46 | #endif | |
47 | ]]) | |
48 | ], | |
49 | [PRIPTR_PREFIX='"l"'], | |
50 | [PRIPTR_PREFIX='"ll"']) | |
55a8c076 YQ |
51 | else |
52 | dnl Using the system's <stdint.h>. | |
53 | for glpfx in '' l ll I64; do | |
54 | case $glpfx in | |
55 | '') gltype1='int';; | |
56 | l) gltype1='long int';; | |
57 | ll) gltype1='long long int';; | |
58 | I64) gltype1='__int64';; | |
59 | esac | |
60 | AC_COMPILE_IFELSE( | |
61 | [AC_LANG_PROGRAM([[#include <stdint.h> | |
62 | extern intptr_t foo; | |
63 | extern $gltype1 foo;]])], | |
64 | [PRIPTR_PREFIX='"'$glpfx'"']) | |
65 | test -n "$PRIPTR_PREFIX" && break | |
66 | done | |
67 | fi | |
68 | AC_SUBST([PRIPTR_PREFIX]) | |
69 | ||
55a8c076 YQ |
70 | gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION( |
71 | [INT32_MAX_LT_INTMAX_MAX], | |
72 | [defined INT32_MAX && defined INTMAX_MAX], | |
73 | [INT32_MAX < INTMAX_MAX], | |
74 | [sizeof (int) < sizeof (long long int)]) | |
75 | if test $APPLE_UNIVERSAL_BUILD = 0; then | |
76 | gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION( | |
77 | [INT64_MAX_EQ_LONG_MAX], | |
78 | [defined INT64_MAX], | |
79 | [INT64_MAX == LONG_MAX], | |
80 | [sizeof (long long int) == sizeof (long int)]) | |
81 | else | |
82 | INT64_MAX_EQ_LONG_MAX=-1 | |
83 | fi | |
84 | gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION( | |
85 | [UINT32_MAX_LT_UINTMAX_MAX], | |
86 | [defined UINT32_MAX && defined UINTMAX_MAX], | |
87 | [UINT32_MAX < UINTMAX_MAX], | |
88 | [sizeof (unsigned int) < sizeof (unsigned long long int)]) | |
89 | if test $APPLE_UNIVERSAL_BUILD = 0; then | |
90 | gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION( | |
91 | [UINT64_MAX_EQ_ULONG_MAX], | |
92 | [defined UINT64_MAX], | |
93 | [UINT64_MAX == ULONG_MAX], | |
94 | [sizeof (unsigned long long int) == sizeof (unsigned long int)]) | |
95 | else | |
96 | UINT64_MAX_EQ_ULONG_MAX=-1 | |
97 | fi | |
55a8c076 YQ |
98 | ]) |
99 | ||
100 | # Define the symbol $1 to be 1 if the condition is true, 0 otherwise. | |
101 | # If $2 is true, the condition is $3; otherwise if long long int is supported | |
102 | # approximate the condition with $4; otherwise, assume the condition is false. | |
103 | # The condition should work on all C99 platforms; the approximations should be | |
104 | # good enough to work on all practical pre-C99 platforms. | |
105 | # $2 is evaluated by the C preprocessor, $3 and $4 as compile-time constants. | |
106 | AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION], | |
107 | [ | |
108 | AC_CACHE_CHECK([whether $3], | |
109 | [gl_cv_test_$1], | |
110 | [AC_COMPILE_IFELSE( | |
111 | [AC_LANG_PROGRAM( | |
112 | [[/* Work also in C++ mode. */ | |
113 | #define __STDC_LIMIT_MACROS 1 | |
114 | ||
115 | /* Work if build is not clean. */ | |
116 | #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H | |
117 | ||
118 | #include <limits.h> | |
119 | #if HAVE_STDINT_H | |
120 | #include <stdint.h> | |
121 | #endif | |
122 | ||
123 | #if $2 | |
124 | #define CONDITION ($3) | |
55a8c076 | 125 | #else |
5df4cba6 | 126 | #define CONDITION ($4) |
55a8c076 YQ |
127 | #endif |
128 | int test[CONDITION ? 1 : -1];]])], | |
129 | [gl_cv_test_$1=yes], | |
130 | [gl_cv_test_$1=no])]) | |
131 | if test $gl_cv_test_$1 = yes; then | |
132 | $1=1; | |
133 | else | |
134 | $1=0; | |
135 | fi | |
136 | AC_SUBST([$1]) | |
137 | ]) | |
138 | ||
139 | AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR], | |
140 | [ | |
141 | dnl Use AC_REQUIRE here, so that the default settings are expanded once only. | |
142 | AC_REQUIRE([gl_INTTYPES_H_DEFAULTS]) | |
143 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) | |
144 | ]) | |
145 | ||
146 | AC_DEFUN([gl_INTTYPES_H_DEFAULTS], | |
147 | [ | |
148 | GNULIB_IMAXABS=0; AC_SUBST([GNULIB_IMAXABS]) | |
149 | GNULIB_IMAXDIV=0; AC_SUBST([GNULIB_IMAXDIV]) | |
150 | GNULIB_STRTOIMAX=0; AC_SUBST([GNULIB_STRTOIMAX]) | |
151 | GNULIB_STRTOUMAX=0; AC_SUBST([GNULIB_STRTOUMAX]) | |
152 | dnl Assume proper GNU behavior unless another module says otherwise. | |
153 | HAVE_DECL_IMAXABS=1; AC_SUBST([HAVE_DECL_IMAXABS]) | |
154 | HAVE_DECL_IMAXDIV=1; AC_SUBST([HAVE_DECL_IMAXDIV]) | |
155 | HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX]) | |
156 | HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX]) | |
c0c3707f | 157 | HAVE_IMAXDIV_T=1; AC_SUBST([HAVE_IMAXDIV_T]) |
770d76d7 | 158 | REPLACE_STRTOIMAX=0; AC_SUBST([REPLACE_STRTOIMAX]) |
4a626d0a | 159 | REPLACE_STRTOUMAX=0; AC_SUBST([REPLACE_STRTOUMAX]) |
770d76d7 PA |
160 | INT32_MAX_LT_INTMAX_MAX=1; AC_SUBST([INT32_MAX_LT_INTMAX_MAX]) |
161 | INT64_MAX_EQ_LONG_MAX='defined _LP64'; AC_SUBST([INT64_MAX_EQ_LONG_MAX]) | |
770d76d7 PA |
162 | PRIPTR_PREFIX=__PRIPTR_PREFIX; AC_SUBST([PRIPTR_PREFIX]) |
163 | UINT32_MAX_LT_UINTMAX_MAX=1; AC_SUBST([UINT32_MAX_LT_UINTMAX_MAX]) | |
164 | UINT64_MAX_EQ_ULONG_MAX='defined _LP64'; AC_SUBST([UINT64_MAX_EQ_ULONG_MAX]) | |
55a8c076 | 165 | ]) |