Commit | Line | Data |
---|---|---|
c0c3707f CB |
1 | # stdint.m4 serial 53 |
2 | dnl Copyright (C) 2001-2019 Free Software Foundation, Inc. | |
f6ea5628 DJ |
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 Paul Eggert and Bruno Haible. | |
8 | dnl Test whether <stdint.h> is supported or must be substituted. | |
9 | ||
c0c3707f CB |
10 | AC_PREREQ([2.61]) |
11 | ||
770d76d7 | 12 | AC_DEFUN_ONCE([gl_STDINT_H], |
f6ea5628 | 13 | [ |
f434ba03 | 14 | AC_PREREQ([2.59])dnl |
c0c3707f | 15 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
f6ea5628 | 16 | |
49e4877c | 17 | AC_REQUIRE([gl_LIMITS_H]) |
c0c3707f | 18 | AC_REQUIRE([gt_TYPE_WINT_T]) |
49e4877c | 19 | |
f6ea5628 DJ |
20 | dnl Check for long long int and unsigned long long int. |
21 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) | |
22 | if test $ac_cv_type_long_long_int = yes; then | |
23 | HAVE_LONG_LONG_INT=1 | |
24 | else | |
25 | HAVE_LONG_LONG_INT=0 | |
26 | fi | |
27 | AC_SUBST([HAVE_LONG_LONG_INT]) | |
28 | AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) | |
29 | if test $ac_cv_type_unsigned_long_long_int = yes; then | |
30 | HAVE_UNSIGNED_LONG_LONG_INT=1 | |
31 | else | |
32 | HAVE_UNSIGNED_LONG_LONG_INT=0 | |
33 | fi | |
34 | AC_SUBST([HAVE_UNSIGNED_LONG_LONG_INT]) | |
35 | ||
770d76d7 PA |
36 | dnl Check for <wchar.h>, in the same way as gl_WCHAR_H does. |
37 | AC_CHECK_HEADERS_ONCE([wchar.h]) | |
38 | if test $ac_cv_header_wchar_h = yes; then | |
39 | HAVE_WCHAR_H=1 | |
40 | else | |
41 | HAVE_WCHAR_H=0 | |
42 | fi | |
43 | AC_SUBST([HAVE_WCHAR_H]) | |
44 | ||
f6ea5628 DJ |
45 | dnl Check for <inttypes.h>. |
46 | dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h. | |
47 | if test $ac_cv_header_inttypes_h = yes; then | |
48 | HAVE_INTTYPES_H=1 | |
49 | else | |
50 | HAVE_INTTYPES_H=0 | |
51 | fi | |
52 | AC_SUBST([HAVE_INTTYPES_H]) | |
53 | ||
54 | dnl Check for <sys/types.h>. | |
55 | dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h. | |
56 | if test $ac_cv_header_sys_types_h = yes; then | |
57 | HAVE_SYS_TYPES_H=1 | |
58 | else | |
59 | HAVE_SYS_TYPES_H=0 | |
60 | fi | |
61 | AC_SUBST([HAVE_SYS_TYPES_H]) | |
62 | ||
63 | gl_CHECK_NEXT_HEADERS([stdint.h]) | |
64 | if test $ac_cv_header_stdint_h = yes; then | |
65 | HAVE_STDINT_H=1 | |
66 | else | |
67 | HAVE_STDINT_H=0 | |
68 | fi | |
69 | AC_SUBST([HAVE_STDINT_H]) | |
70 | ||
71 | dnl Now see whether we need a substitute <stdint.h>. | |
72 | if test $ac_cv_header_stdint_h = yes; then | |
73 | AC_CACHE_CHECK([whether stdint.h conforms to C99], | |
74 | [gl_cv_header_working_stdint_h], | |
75 | [gl_cv_header_working_stdint_h=no | |
76 | AC_COMPILE_IFELSE([ | |
77 | AC_LANG_PROGRAM([[ | |
f6ea5628 | 78 | #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ |
49e4877c PA |
79 | #define __STDC_CONSTANT_MACROS 1 |
80 | #define __STDC_LIMIT_MACROS 1 | |
f6ea5628 DJ |
81 | #include <stdint.h> |
82 | /* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>. */ | |
83 | #if !(defined WCHAR_MIN && defined WCHAR_MAX) | |
84 | #error "WCHAR_MIN, WCHAR_MAX not defined in <stdint.h>" | |
85 | #endif | |
86 | ] | |
87 | gl_STDINT_INCLUDES | |
88 | [ | |
89 | #ifdef INT8_MAX | |
90 | int8_t a1 = INT8_MAX; | |
91 | int8_t a1min = INT8_MIN; | |
92 | #endif | |
93 | #ifdef INT16_MAX | |
94 | int16_t a2 = INT16_MAX; | |
95 | int16_t a2min = INT16_MIN; | |
96 | #endif | |
97 | #ifdef INT32_MAX | |
98 | int32_t a3 = INT32_MAX; | |
99 | int32_t a3min = INT32_MIN; | |
100 | #endif | |
101 | #ifdef INT64_MAX | |
102 | int64_t a4 = INT64_MAX; | |
103 | int64_t a4min = INT64_MIN; | |
104 | #endif | |
105 | #ifdef UINT8_MAX | |
106 | uint8_t b1 = UINT8_MAX; | |
107 | #else | |
108 | typedef int b1[(unsigned char) -1 != 255 ? 1 : -1]; | |
109 | #endif | |
110 | #ifdef UINT16_MAX | |
111 | uint16_t b2 = UINT16_MAX; | |
112 | #endif | |
113 | #ifdef UINT32_MAX | |
114 | uint32_t b3 = UINT32_MAX; | |
115 | #endif | |
116 | #ifdef UINT64_MAX | |
117 | uint64_t b4 = UINT64_MAX; | |
118 | #endif | |
119 | int_least8_t c1 = INT8_C (0x7f); | |
120 | int_least8_t c1max = INT_LEAST8_MAX; | |
121 | int_least8_t c1min = INT_LEAST8_MIN; | |
122 | int_least16_t c2 = INT16_C (0x7fff); | |
123 | int_least16_t c2max = INT_LEAST16_MAX; | |
124 | int_least16_t c2min = INT_LEAST16_MIN; | |
125 | int_least32_t c3 = INT32_C (0x7fffffff); | |
126 | int_least32_t c3max = INT_LEAST32_MAX; | |
127 | int_least32_t c3min = INT_LEAST32_MIN; | |
128 | int_least64_t c4 = INT64_C (0x7fffffffffffffff); | |
129 | int_least64_t c4max = INT_LEAST64_MAX; | |
130 | int_least64_t c4min = INT_LEAST64_MIN; | |
131 | uint_least8_t d1 = UINT8_C (0xff); | |
132 | uint_least8_t d1max = UINT_LEAST8_MAX; | |
133 | uint_least16_t d2 = UINT16_C (0xffff); | |
134 | uint_least16_t d2max = UINT_LEAST16_MAX; | |
135 | uint_least32_t d3 = UINT32_C (0xffffffff); | |
136 | uint_least32_t d3max = UINT_LEAST32_MAX; | |
137 | uint_least64_t d4 = UINT64_C (0xffffffffffffffff); | |
138 | uint_least64_t d4max = UINT_LEAST64_MAX; | |
139 | int_fast8_t e1 = INT_FAST8_MAX; | |
140 | int_fast8_t e1min = INT_FAST8_MIN; | |
141 | int_fast16_t e2 = INT_FAST16_MAX; | |
142 | int_fast16_t e2min = INT_FAST16_MIN; | |
143 | int_fast32_t e3 = INT_FAST32_MAX; | |
144 | int_fast32_t e3min = INT_FAST32_MIN; | |
145 | int_fast64_t e4 = INT_FAST64_MAX; | |
146 | int_fast64_t e4min = INT_FAST64_MIN; | |
147 | uint_fast8_t f1 = UINT_FAST8_MAX; | |
148 | uint_fast16_t f2 = UINT_FAST16_MAX; | |
149 | uint_fast32_t f3 = UINT_FAST32_MAX; | |
150 | uint_fast64_t f4 = UINT_FAST64_MAX; | |
151 | #ifdef INTPTR_MAX | |
152 | intptr_t g = INTPTR_MAX; | |
153 | intptr_t gmin = INTPTR_MIN; | |
154 | #endif | |
155 | #ifdef UINTPTR_MAX | |
156 | uintptr_t h = UINTPTR_MAX; | |
157 | #endif | |
158 | intmax_t i = INTMAX_MAX; | |
159 | uintmax_t j = UINTMAX_MAX; | |
160 | ||
4c62b19f PA |
161 | /* Check that SIZE_MAX has the correct type, if possible. */ |
162 | #if 201112 <= __STDC_VERSION__ | |
163 | int k = _Generic (SIZE_MAX, size_t: 0); | |
164 | #elif (2 <= __GNUC__ || defined __IBM__TYPEOF__ \ | |
165 | || (0x5110 <= __SUNPRO_C && !__STDC__)) | |
166 | extern size_t k; | |
167 | extern __typeof__ (SIZE_MAX) k; | |
168 | #endif | |
169 | ||
f6ea5628 DJ |
170 | #include <limits.h> /* for CHAR_BIT */ |
171 | #define TYPE_MINIMUM(t) \ | |
770d76d7 | 172 | ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ TYPE_MAXIMUM (t))) |
f6ea5628 | 173 | #define TYPE_MAXIMUM(t) \ |
770d76d7 PA |
174 | ((t) ((t) 0 < (t) -1 \ |
175 | ? (t) -1 \ | |
176 | : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) | |
f6ea5628 DJ |
177 | struct s { |
178 | int check_PTRDIFF: | |
179 | PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t) | |
180 | && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t) | |
181 | ? 1 : -1; | |
182 | /* Detect bug in FreeBSD 6.0 / ia64. */ | |
183 | int check_SIG_ATOMIC: | |
184 | SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t) | |
185 | && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t) | |
186 | ? 1 : -1; | |
187 | int check_SIZE: SIZE_MAX == TYPE_MAXIMUM (size_t) ? 1 : -1; | |
188 | int check_WCHAR: | |
189 | WCHAR_MIN == TYPE_MINIMUM (wchar_t) | |
190 | && WCHAR_MAX == TYPE_MAXIMUM (wchar_t) | |
191 | ? 1 : -1; | |
192 | /* Detect bug in mingw. */ | |
193 | int check_WINT: | |
194 | WINT_MIN == TYPE_MINIMUM (wint_t) | |
195 | && WINT_MAX == TYPE_MAXIMUM (wint_t) | |
196 | ? 1 : -1; | |
197 | ||
198 | /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */ | |
199 | int check_UINT8_C: | |
200 | (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1; | |
201 | int check_UINT16_C: | |
202 | (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1; | |
203 | ||
204 | /* Detect bugs in OpenBSD 3.9 stdint.h. */ | |
205 | #ifdef UINT8_MAX | |
206 | int check_uint8: (uint8_t) -1 == UINT8_MAX ? 1 : -1; | |
207 | #endif | |
208 | #ifdef UINT16_MAX | |
209 | int check_uint16: (uint16_t) -1 == UINT16_MAX ? 1 : -1; | |
210 | #endif | |
211 | #ifdef UINT32_MAX | |
212 | int check_uint32: (uint32_t) -1 == UINT32_MAX ? 1 : -1; | |
213 | #endif | |
214 | #ifdef UINT64_MAX | |
215 | int check_uint64: (uint64_t) -1 == UINT64_MAX ? 1 : -1; | |
216 | #endif | |
217 | int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1; | |
218 | int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1; | |
219 | int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1; | |
220 | int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1; | |
221 | int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1; | |
222 | int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1; | |
223 | int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1; | |
224 | int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1; | |
225 | int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1; | |
226 | int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1; | |
227 | int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1; | |
228 | }; | |
229 | ]])], | |
f434ba03 PA |
230 | [dnl Determine whether the various *_MIN, *_MAX macros are usable |
231 | dnl in preprocessor expression. We could do it by compiling a test | |
232 | dnl program for each of these macros. It is faster to run a program | |
233 | dnl that inspects the macro expansion. | |
234 | dnl This detects a bug on HP-UX 11.23/ia64. | |
235 | AC_RUN_IFELSE([ | |
236 | AC_LANG_PROGRAM([[ | |
f434ba03 | 237 | #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ |
49e4877c PA |
238 | #define __STDC_CONSTANT_MACROS 1 |
239 | #define __STDC_LIMIT_MACROS 1 | |
f434ba03 PA |
240 | #include <stdint.h> |
241 | ] | |
242 | gl_STDINT_INCLUDES | |
243 | [ | |
244 | #include <stdio.h> | |
245 | #include <string.h> | |
246 | #define MVAL(macro) MVAL1(macro) | |
247 | #define MVAL1(expression) #expression | |
248 | static const char *macro_values[] = | |
249 | { | |
250 | #ifdef INT8_MAX | |
251 | MVAL (INT8_MAX), | |
252 | #endif | |
253 | #ifdef INT16_MAX | |
254 | MVAL (INT16_MAX), | |
255 | #endif | |
256 | #ifdef INT32_MAX | |
257 | MVAL (INT32_MAX), | |
258 | #endif | |
259 | #ifdef INT64_MAX | |
260 | MVAL (INT64_MAX), | |
261 | #endif | |
262 | #ifdef UINT8_MAX | |
263 | MVAL (UINT8_MAX), | |
264 | #endif | |
265 | #ifdef UINT16_MAX | |
266 | MVAL (UINT16_MAX), | |
267 | #endif | |
268 | #ifdef UINT32_MAX | |
269 | MVAL (UINT32_MAX), | |
270 | #endif | |
271 | #ifdef UINT64_MAX | |
272 | MVAL (UINT64_MAX), | |
273 | #endif | |
274 | NULL | |
275 | }; | |
276 | ]], [[ | |
277 | const char **mv; | |
278 | for (mv = macro_values; *mv != NULL; mv++) | |
279 | { | |
280 | const char *value = *mv; | |
281 | /* Test whether it looks like a cast expression. */ | |
282 | if (strncmp (value, "((unsigned int)"/*)*/, 15) == 0 | |
283 | || strncmp (value, "((unsigned short)"/*)*/, 17) == 0 | |
284 | || strncmp (value, "((unsigned char)"/*)*/, 16) == 0 | |
285 | || strncmp (value, "((int)"/*)*/, 6) == 0 | |
286 | || strncmp (value, "((signed short)"/*)*/, 15) == 0 | |
287 | || strncmp (value, "((signed char)"/*)*/, 14) == 0) | |
770d76d7 | 288 | return mv - macro_values + 1; |
f434ba03 PA |
289 | } |
290 | return 0; | |
291 | ]])], | |
292 | [gl_cv_header_working_stdint_h=yes], | |
293 | [], | |
c0c3707f CB |
294 | [case "$host_os" in |
295 | # Guess yes on native Windows. | |
296 | mingw*) gl_cv_header_working_stdint_h="guessing yes" ;; | |
297 | # In general, assume it works. | |
298 | *) gl_cv_header_working_stdint_h="guessing yes" ;; | |
299 | esac | |
f434ba03 PA |
300 | ]) |
301 | ]) | |
302 | ]) | |
f6ea5628 | 303 | fi |
49e4877c PA |
304 | |
305 | HAVE_C99_STDINT_H=0 | |
306 | HAVE_SYS_BITYPES_H=0 | |
307 | HAVE_SYS_INTTYPES_H=0 | |
308 | STDINT_H=stdint.h | |
c0c3707f CB |
309 | case "$gl_cv_header_working_stdint_h" in |
310 | *yes) | |
311 | HAVE_C99_STDINT_H=1 | |
312 | dnl Now see whether the system <stdint.h> works without | |
313 | dnl __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined. | |
314 | AC_CACHE_CHECK([whether stdint.h predates C++11], | |
315 | [gl_cv_header_stdint_predates_cxx11_h], | |
316 | [gl_cv_header_stdint_predates_cxx11_h=yes | |
317 | AC_COMPILE_IFELSE([ | |
318 | AC_LANG_PROGRAM([[ | |
49e4877c PA |
319 | #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ |
320 | #include <stdint.h> | |
321 | ] | |
322 | gl_STDINT_INCLUDES | |
323 | [ | |
324 | intmax_t im = INTMAX_MAX; | |
325 | int32_t i32 = INT32_C (0x7fffffff); | |
c0c3707f CB |
326 | ]])], |
327 | [gl_cv_header_stdint_predates_cxx11_h=no])]) | |
49e4877c | 328 | |
c0c3707f CB |
329 | if test "$gl_cv_header_stdint_predates_cxx11_h" = yes; then |
330 | AC_DEFINE([__STDC_CONSTANT_MACROS], [1], | |
331 | [Define to 1 if the system <stdint.h> predates C++11.]) | |
332 | AC_DEFINE([__STDC_LIMIT_MACROS], [1], | |
333 | [Define to 1 if the system <stdint.h> predates C++11.]) | |
334 | fi | |
335 | AC_CACHE_CHECK([whether stdint.h has UINTMAX_WIDTH etc.], | |
336 | [gl_cv_header_stdint_width], | |
337 | [gl_cv_header_stdint_width=no | |
338 | AC_COMPILE_IFELSE( | |
339 | [AC_LANG_PROGRAM([[ | |
340 | /* Work if build is not clean. */ | |
341 | #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 | |
342 | #ifndef __STDC_WANT_IEC_60559_BFP_EXT__ | |
343 | #define __STDC_WANT_IEC_60559_BFP_EXT__ 1 | |
344 | #endif | |
345 | #include <stdint.h> | |
346 | ]gl_STDINT_INCLUDES[ | |
347 | int iw = UINTMAX_WIDTH; | |
348 | ]])], | |
349 | [gl_cv_header_stdint_width=yes])]) | |
350 | if test "$gl_cv_header_stdint_width" = yes; then | |
351 | STDINT_H= | |
352 | fi | |
353 | ;; | |
354 | *) | |
355 | dnl Check for <sys/inttypes.h>, and for | |
356 | dnl <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5). | |
357 | AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h]) | |
358 | if test $ac_cv_header_sys_inttypes_h = yes; then | |
359 | HAVE_SYS_INTTYPES_H=1 | |
360 | fi | |
361 | if test $ac_cv_header_sys_bitypes_h = yes; then | |
362 | HAVE_SYS_BITYPES_H=1 | |
363 | fi | |
364 | gl_STDINT_TYPE_PROPERTIES | |
365 | ;; | |
366 | esac | |
49e4877c | 367 | |
c0c3707f CB |
368 | dnl The substitute stdint.h needs the substitute limit.h's _GL_INTEGER_WIDTH. |
369 | gl_REPLACE_LIMITS_H | |
49e4877c PA |
370 | |
371 | AC_SUBST([HAVE_C99_STDINT_H]) | |
372 | AC_SUBST([HAVE_SYS_BITYPES_H]) | |
373 | AC_SUBST([HAVE_SYS_INTTYPES_H]) | |
f434ba03 | 374 | AC_SUBST([STDINT_H]) |
770d76d7 | 375 | AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"]) |
f6ea5628 DJ |
376 | ]) |
377 | ||
378 | dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES) | |
379 | dnl Determine the size of each of the given types in bits. | |
380 | AC_DEFUN([gl_STDINT_BITSIZEOF], | |
381 | [ | |
382 | dnl Use a shell loop, to avoid bloating configure, and | |
383 | dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into | |
384 | dnl config.h.in, | |
385 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | |
f434ba03 | 386 | m4_foreach_w([gltype], [$1], |
770d76d7 | 387 | [AH_TEMPLATE([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), |
f6ea5628 DJ |
388 | [Define to the number of bits in type ']gltype['.])]) |
389 | for gltype in $1 ; do | |
390 | AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}], | |
391 | [AC_COMPUTE_INT([result], [sizeof ($gltype) * CHAR_BIT], | |
392 | [$2 | |
393 | #include <limits.h>], [result=unknown]) | |
394 | eval gl_cv_bitsizeof_${gltype}=\$result | |
395 | ]) | |
396 | eval result=\$gl_cv_bitsizeof_${gltype} | |
397 | if test $result = unknown; then | |
398 | dnl Use a nonempty default, because some compilers, such as IRIX 5 cc, | |
399 | dnl do a syntax check even on unused #if conditions and give an error | |
400 | dnl on valid C code like this: | |
401 | dnl #if 0 | |
402 | dnl # if > 32 | |
403 | dnl # endif | |
404 | dnl #endif | |
405 | result=0 | |
406 | fi | |
407 | GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` | |
408 | AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result]) | |
409 | eval BITSIZEOF_${GLTYPE}=\$result | |
410 | done | |
f434ba03 | 411 | m4_foreach_w([gltype], [$1], |
770d76d7 | 412 | [AC_SUBST([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) |
f6ea5628 DJ |
413 | ]) |
414 | ||
415 | dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES) | |
416 | dnl Determine the signedness of each of the given types. | |
417 | dnl Define HAVE_SIGNED_TYPE if type is signed. | |
418 | AC_DEFUN([gl_CHECK_TYPES_SIGNED], | |
419 | [ | |
420 | dnl Use a shell loop, to avoid bloating configure, and | |
421 | dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into | |
422 | dnl config.h.in, | |
423 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | |
f434ba03 | 424 | m4_foreach_w([gltype], [$1], |
770d76d7 | 425 | [AH_TEMPLATE([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), |
f6ea5628 DJ |
426 | [Define to 1 if ']gltype[' is a signed integer type.])]) |
427 | for gltype in $1 ; do | |
428 | AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed], | |
429 | [AC_COMPILE_IFELSE( | |
430 | [AC_LANG_PROGRAM([$2[ | |
431 | int verify[2 * (($gltype) -1 < ($gltype) 0) - 1];]])], | |
432 | result=yes, result=no) | |
433 | eval gl_cv_type_${gltype}_signed=\$result | |
434 | ]) | |
435 | eval result=\$gl_cv_type_${gltype}_signed | |
436 | GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` | |
437 | if test "$result" = yes; then | |
f434ba03 | 438 | AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], [1]) |
f6ea5628 DJ |
439 | eval HAVE_SIGNED_${GLTYPE}=1 |
440 | else | |
441 | eval HAVE_SIGNED_${GLTYPE}=0 | |
442 | fi | |
443 | done | |
f434ba03 | 444 | m4_foreach_w([gltype], [$1], |
770d76d7 | 445 | [AC_SUBST([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) |
f6ea5628 DJ |
446 | ]) |
447 | ||
448 | dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES) | |
449 | dnl Determine the suffix to use for integer constants of the given types. | |
450 | dnl Define t_SUFFIX for each such type. | |
451 | AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], | |
452 | [ | |
453 | dnl Use a shell loop, to avoid bloating configure, and | |
454 | dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into | |
455 | dnl config.h.in, | |
456 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | |
f434ba03 | 457 | m4_foreach_w([gltype], [$1], |
770d76d7 | 458 | [AH_TEMPLATE(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX], |
f6ea5628 DJ |
459 | [Define to l, ll, u, ul, ull, etc., as suitable for |
460 | constants of type ']gltype['.])]) | |
461 | for gltype in $1 ; do | |
462 | AC_CACHE_CHECK([for $gltype integer literal suffix], | |
463 | [gl_cv_type_${gltype}_suffix], | |
464 | [eval gl_cv_type_${gltype}_suffix=no | |
465 | eval result=\$gl_cv_type_${gltype}_signed | |
466 | if test "$result" = yes; then | |
467 | glsufu= | |
468 | else | |
469 | glsufu=u | |
470 | fi | |
471 | for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do | |
472 | case $glsuf in | |
473 | '') gltype1='int';; | |
f434ba03 PA |
474 | l) gltype1='long int';; |
475 | ll) gltype1='long long int';; | |
476 | i64) gltype1='__int64';; | |
477 | u) gltype1='unsigned int';; | |
478 | ul) gltype1='unsigned long int';; | |
479 | ull) gltype1='unsigned long long int';; | |
f6ea5628 DJ |
480 | ui64)gltype1='unsigned __int64';; |
481 | esac | |
482 | AC_COMPILE_IFELSE( | |
f434ba03 | 483 | [AC_LANG_PROGRAM([$2[ |
f6ea5628 | 484 | extern $gltype foo; |
f434ba03 | 485 | extern $gltype1 foo;]])], |
f6ea5628 DJ |
486 | [eval gl_cv_type_${gltype}_suffix=\$glsuf]) |
487 | eval result=\$gl_cv_type_${gltype}_suffix | |
488 | test "$result" != no && break | |
489 | done]) | |
490 | GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` | |
491 | eval result=\$gl_cv_type_${gltype}_suffix | |
492 | test "$result" = no && result= | |
493 | eval ${GLTYPE}_SUFFIX=\$result | |
f434ba03 | 494 | AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], [$result]) |
f6ea5628 | 495 | done |
f434ba03 | 496 | m4_foreach_w([gltype], [$1], |
770d76d7 | 497 | [AC_SUBST(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])]) |
f6ea5628 DJ |
498 | ]) |
499 | ||
500 | dnl gl_STDINT_INCLUDES | |
501 | AC_DEFUN([gl_STDINT_INCLUDES], | |
502 | [[ | |
503 | /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be | |
504 | included before <wchar.h>. */ | |
505 | #include <stddef.h> | |
506 | #include <signal.h> | |
507 | #if HAVE_WCHAR_H | |
508 | # include <stdio.h> | |
509 | # include <time.h> | |
510 | # include <wchar.h> | |
511 | #endif | |
512 | ]]) | |
513 | ||
514 | dnl gl_STDINT_TYPE_PROPERTIES | |
515 | dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t | |
516 | dnl of interest to stdint.in.h. | |
517 | AC_DEFUN([gl_STDINT_TYPE_PROPERTIES], | |
518 | [ | |
f434ba03 PA |
519 | AC_REQUIRE([gl_MULTIARCH]) |
520 | if test $APPLE_UNIVERSAL_BUILD = 0; then | |
521 | gl_STDINT_BITSIZEOF([ptrdiff_t size_t], | |
522 | [gl_STDINT_INCLUDES]) | |
523 | fi | |
524 | gl_STDINT_BITSIZEOF([sig_atomic_t wchar_t wint_t], | |
f6ea5628 DJ |
525 | [gl_STDINT_INCLUDES]) |
526 | gl_CHECK_TYPES_SIGNED([sig_atomic_t wchar_t wint_t], | |
527 | [gl_STDINT_INCLUDES]) | |
528 | gl_cv_type_ptrdiff_t_signed=yes | |
529 | gl_cv_type_size_t_signed=no | |
f434ba03 PA |
530 | if test $APPLE_UNIVERSAL_BUILD = 0; then |
531 | gl_INTEGER_TYPE_SUFFIX([ptrdiff_t size_t], | |
532 | [gl_STDINT_INCLUDES]) | |
533 | fi | |
534 | gl_INTEGER_TYPE_SUFFIX([sig_atomic_t wchar_t wint_t], | |
f6ea5628 | 535 | [gl_STDINT_INCLUDES]) |
770d76d7 PA |
536 | |
537 | dnl If wint_t is smaller than 'int', it cannot satisfy the ISO C 99 | |
538 | dnl requirement that wint_t is "unchanged by default argument promotions". | |
539 | dnl In this case gnulib's <wchar.h> and <wctype.h> override wint_t. | |
540 | dnl Set the variable BITSIZEOF_WINT_T accordingly. | |
c0c3707f | 541 | if test $GNULIB_OVERRIDES_WINT_T = 1; then |
770d76d7 PA |
542 | BITSIZEOF_WINT_T=32 |
543 | fi | |
f6ea5628 | 544 | ]) |