Tweak for SGI cc.
[gnulib.git] / m4 / stdint.m4
1 # stdint.m4 serial 10
2 dnl Copyright (C) 2001-2002, 2004-2006 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 Bruno Haible.
8 dnl Test whether <stdint.h> is supported or must be substituted.
9
10 AC_DEFUN([gl_STDINT_H],
11 [
12   dnl Check for <stdint.h> that doesn't clash with <sys/types.h>.
13   gl_HEADER_STDINT_H
14   if test $gl_cv_header_stdint_h = yes; then
15     ac_cv_header_stdint_h=yes; dnl Hack for gl_FULL_HEADER_PATH.
16     gl_FULL_HEADER_PATH([stdint.h])
17     FULL_PATH_STDINT_H='<'$gl_cv_full_path_stdint_h'>'
18     AC_SUBST([FULL_PATH_STDINT_H])
19     HAVE_STDINT_H=1
20   else
21     HAVE_STDINT_H=0
22   fi
23   AC_SUBST([HAVE_STDINT_H])
24
25   dnl Check for <inttypes.h> that doesn't clash with <sys/types.h>.
26   gl_HEADER_INTTYPES_H
27   if test $gl_cv_header_inttypes_h = yes; then
28     ac_cv_header_inttypes_h=yes; dnl Hack for gl_FULL_HEADER_PATH.
29     gl_FULL_HEADER_PATH([inttypes.h])
30     FULL_PATH_INTTYPES_H='<'$gl_cv_full_path_inttypes_h'>'
31     AC_SUBST([FULL_PATH_INTTYPES_H])
32     HAVE_INTTYPES_H=1
33   else
34     HAVE_INTTYPES_H=0
35   fi
36   AC_SUBST([HAVE_INTTYPES_H])
37
38   dnl Check for <sys/inttypes.h>.
39   AC_CHECK_HEADERS([sys/inttypes.h])
40   if test $ac_cv_header_sys_inttypes_h = yes; then
41     HAVE_SYS_INTTYPES_H=1
42   else
43     HAVE_SYS_INTTYPES_H=0
44   fi
45   AC_SUBST([HAVE_SYS_INTTYPES_H])
46
47   dnl Check for <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5).
48   AC_CHECK_HEADERS([sys/bitypes.h])
49   if test $ac_cv_header_sys_bitypes_h = yes; then
50     HAVE_SYS_BITYPES_H=1
51   else
52     HAVE_SYS_BITYPES_H=0
53   fi
54   AC_SUBST([HAVE_SYS_BITYPES_H])
55
56   dnl Is long == int64_t ?
57   AC_CACHE_CHECK([whether 'long' is 64 bit wide], gl_cv_long_bitsize_64, [
58     AC_TRY_COMPILE([
59 #define POW63  ((((((long) 1 << 15) << 15) << 15) << 15) << 3)
60 #define POW64  ((((((long) 1 << 15) << 15) << 15) << 15) << 4)
61 typedef int array [2 * (POW63 != 0 && POW64 == 0) - 1];
62 ], , gl_cv_long_bitsize_64=yes, gl_cv_long_bitsize_64=no)])
63   if test $gl_cv_long_bitsize_64 = yes; then
64     HAVE_LONG_64BIT=1
65   else
66     HAVE_LONG_64BIT=0
67   fi
68   AC_SUBST(HAVE_LONG_64BIT)
69
70   dnl Is long long == int64_t ?
71   AC_CACHE_CHECK([whether 'long long' is 64 bit wide], gl_cv_longlong_bitsize_64, [
72     AC_TRY_COMPILE([
73 #define POW63  ((((((long long) 1 << 15) << 15) << 15) << 15) << 3)
74 #define POW64  ((((((long long) 1 << 15) << 15) << 15) << 15) << 4)
75 typedef int array [2 * (POW63 != 0 && POW64 == 0) - 1];
76 ], , gl_cv_longlong_bitsize_64=yes, gl_cv_longlong_bitsize_64=no)])
77   if test $gl_cv_longlong_bitsize_64 = yes; then
78     HAVE_LONG_LONG_64BIT=1
79   else
80     HAVE_LONG_LONG_64BIT=0
81   fi
82   AC_SUBST(HAVE_LONG_LONG_64BIT)
83
84   dnl Here we use FULL_PATH_INTTYPES_H and FULL_PATH_STDINT_H, not just
85   dnl <inttypes.h> and <stdint.h>, so that it also works during a
86   dnl "config.status --recheck" if an inttypes.h or stdint.h have been
87   dnl created in the build directory.
88   other_includes='
89 /* Get those types that are already defined in other system include files.  */
90 #if defined(__FreeBSD__) && (__FreeBSD__ >= 3) && (__FreeBSD__ <= 4)
91 # include <sys/inttypes.h>
92 #endif
93 #if defined(__OpenBSD__) || defined(__bsdi__) || defined(__sgi)
94 # include <sys/types.h>
95 # if HAVE_INTTYPES_H
96 #  include FULL_PATH_INTTYPES_H
97 # endif
98 #endif
99 #if defined(__linux__) && HAVE_SYS_BITYPES_H
100 # include <sys/bitypes.h>
101 #endif
102 #if defined(__sun) && HAVE_SYS_INTTYPES_H
103 # include <sys/inttypes.h>
104 #endif
105 #if (defined(__hpux) || defined(_AIX)) && HAVE_INTTYPES_H
106 # include FULL_PATH_INTTYPES_H
107 #endif
108 #if HAVE_STDINT_H && !(defined(__sgi) && HAVE_INTTYPES_H && !defined(_c99))
109 # include FULL_PATH_STDINT_H
110 #endif
111 '
112   gl_STDINT_CHECK_TYPES(
113     [int8_t int16_t int32_t int64_t \
114      uint8_t uint16_t uint32_t uint64_t \
115      int_least8_t int_least16_t int_least32_t int_least64_t \
116      uint_least8_t uint_least16_t uint_least32_t uint_least64_t \
117      int_fast8_t int_fast16_t int_fast32_t int_fast64_t \
118      uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t \
119      intptr_t uintptr_t \
120      intmax_t uintmax_t],
121     [$other_includes],
122     [gl_cv_type_], [], [])
123
124   dnl Now see if we need a substitute <stdint.h>.
125   gl_cv_header_working_stdint_h=no
126   if test $gl_cv_header_stdint_h = yes; then
127     gl_STDINT_CHECK_TYPES(
128       [int64_t uint64_t \
129        int_least64_t uint_least64_t \
130        int_fast64_t uint_fast64_t],
131       [#include <stdint.h>],
132       [gl_cv_stdint_], [_IN_STDINT_H], [in <stdint.h>])
133     AC_COMPILE_IFELSE([
134       AC_LANG_PROGRAM([
135 #define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
136 #include <stdint.h>
137 int8_t a1 = INT8_C (17);
138 int16_t a2 = INT16_C (17);
139 int32_t a3 = INT32_C (17);
140 #if HAVE_INT64_T_IN_STDINT_H
141 int64_t a4 = INT64_C (17);
142 #endif
143 uint8_t b1 = UINT8_C (17);
144 uint16_t b2 = UINT16_C (17);
145 uint32_t b3 = UINT32_C (17);
146 #if HAVE_UINT64_T_IN_STDINT_H
147 uint64_t b4 = UINT64_C (17);
148 #endif
149 int_least8_t c1 = 17;
150 int_least16_t c2 = 17;
151 int_least32_t c3 = 17;
152 #if HAVE_INT_LEAST64_T_IN_STDINT_H
153 int_least64_t c4 = 17;
154 #endif
155 uint_least8_t d1 = 17;
156 uint_least16_t d2 = 17;
157 uint_least32_t d3 = 17;
158 #if HAVE_UINT_LEAST64_T_IN_STDINT_H
159 uint_least64_t d4 = 17;
160 #endif
161 int_fast8_t e1 = 17;
162 int_fast16_t e2 = 17;
163 int_fast32_t e3 = 17;
164 #if HAVE_INT_FAST64_T_IN_STDINT_H
165 int_fast64_t e4 = 17;
166 #endif
167 uint_fast8_t f1 = 17;
168 uint_fast16_t f2 = 17;
169 uint_fast32_t f3 = 17;
170 #if HAVE_UINT_FAST64_T_IN_STDINT_H
171 uint_fast64_t f4 = 17;
172 #endif
173 intptr_t g = 17;
174 uintptr_t h = 17;
175 intmax_t i = INTMAX_C (17);
176 uintmax_t j = UINTMAX_C (17);
177       ])],
178       [gl_cv_header_working_stdint_h=yes])
179   fi
180   if test $gl_cv_header_working_stdint_h = yes; then
181     dnl Use the existing <stdint.h>, adding missing macro definitions.
182     suff64=
183     suffu64=
184     if test $HAVE_LONG_64BIT = 1; then
185       suff64=L
186       suffu64=UL
187     else
188       if test $HAVE_LONG_LONG_64BIT = 1; then
189         suff64=LL
190         suffu64=ULL
191       else
192         AC_EGREP_CPP([msvc compiler], [
193 #ifdef _MSC_VER
194 msvc compiler
195 #endif
196           ], [
197           suff64=i64
198           suffu64=ui64
199         ])
200       fi
201     fi
202     dnl Here we assume a standard architecture where the hardware integer
203     dnl types have 8, 16, 32, optionally 64 bits.
204     gl_STDINT_MISSING_BOUND([INT8_MIN], [-128],
205       [Define if <stdint.h> doesn't define it.])
206     gl_STDINT_MISSING_BOUND([INT8_MAX], [127],
207       [Define if <stdint.h> doesn't define it.])
208     gl_STDINT_MISSING_BOUND([UINT8_MAX], [255],
209       [Define if <stdint.h> doesn't define it.])
210     gl_STDINT_MISSING_BOUND([INT16_MIN], [-32768],
211       [Define if <stdint.h> doesn't define it.])
212     gl_STDINT_MISSING_BOUND([INT16_MAX], [32767],
213       [Define if <stdint.h> doesn't define it.])
214     gl_STDINT_MISSING_BOUND([UINT16_MAX], [65535],
215       [Define if <stdint.h> doesn't define it.])
216     gl_STDINT_MISSING_BOUND([INT32_MIN], [(~INT32_MAX)],
217       [Define if <stdint.h> doesn't define it.])
218     gl_STDINT_MISSING_BOUND([INT32_MAX], [2147483647],
219       [Define if <stdint.h> doesn't define it.])
220     gl_STDINT_MISSING_BOUND([UINT32_MAX], [4294967295U],
221       [Define if <stdint.h> doesn't define it.])
222     if test $gl_cv_stdint_int64_t = yes; then
223       gl_STDINT_MISSING_BOUND([INT64_MIN], [(~INT64_MAX)],
224         [Define if <stdint.h> doesn't define it but has the int64_t type.])
225       gl_STDINT_MISSING_BOUND([INT64_MAX], [9223372036854775807${suff64}],
226         [Define if <stdint.h> doesn't define it but has the int64_t type.])
227     fi
228     if test $gl_cv_stdint_uint64_t = yes; then
229       gl_STDINT_MISSING_BOUND([UINT64_MAX], [18446744073709551615${suffu64}],
230         [Define if <stdint.h> doesn't define it but has the uint64_t type.])
231     fi
232     dnl Here we assume a standard architecture where the hardware integer
233     dnl types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
234     dnl are the same as the corresponding N_t types.
235     gl_STDINT_MISSING_BOUND([INT_LEAST8_MIN], [INT8_MIN],
236       [Define if <stdint.h> doesn't define it.])
237     gl_STDINT_MISSING_BOUND([INT_LEAST8_MAX], [INT8_MAX],
238       [Define if <stdint.h> doesn't define it.])
239     gl_STDINT_MISSING_BOUND([UINT_LEAST8_MAX], [UINT8_MAX],
240       [Define if <stdint.h> doesn't define it.])
241     gl_STDINT_MISSING_BOUND([INT_LEAST16_MIN], [INT16_MIN],
242       [Define if <stdint.h> doesn't define it.])
243     gl_STDINT_MISSING_BOUND([INT_LEAST16_MAX], [INT16_MAX],
244       [Define if <stdint.h> doesn't define it.])
245     gl_STDINT_MISSING_BOUND([UINT_LEAST16_MAX], [UINT16_MAX],
246       [Define if <stdint.h> doesn't define it.])
247     gl_STDINT_MISSING_BOUND([INT_LEAST32_MIN], [INT32_MIN],
248       [Define if <stdint.h> doesn't define it.])
249     gl_STDINT_MISSING_BOUND([INT_LEAST32_MAX], [INT32_MAX],
250       [Define if <stdint.h> doesn't define it.])
251     gl_STDINT_MISSING_BOUND([UINT_LEAST32_MAX], [UINT32_MAX],
252       [Define if <stdint.h> doesn't define it.])
253     if test $gl_cv_stdint_int_least64_t = yes; then
254       gl_STDINT_MISSING_BOUND([INT_LEAST64_MIN], [INT64_MIN],
255         [Define if <stdint.h> doesn't define it but has the int_least64_t type.])
256       gl_STDINT_MISSING_BOUND([INT_LEAST64_MAX], [INT64_MAX],
257         [Define if <stdint.h> doesn't define it but has the int_least64_t type.])
258     fi
259     if test $gl_cv_stdint_uint_least64_t = yes; then
260       gl_STDINT_MISSING_BOUND([UINT_LEAST64_MAX], [UINT64_MAX],
261         [Define if <stdint.h> doesn't define it but has the uint_least64_t type.])
262     fi
263     dnl Here we assume a standard architecture where the hardware integer
264     dnl types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
265     dnl are taken from the same list of types.
266     gl_STDINT_MISSING_BOUNDS([INT_FAST8_MIN INT_FAST8_MAX UINT_FAST8_MAX \
267                               INT_FAST16_MIN INT_FAST16_MAX UINT_FAST16_MAX \
268                               INT_FAST32_MIN INT_FAST32_MAX UINT_FAST32_MAX])
269     if test $gl_cv_stdint_uint_fast64_t = yes; then
270       gl_STDINT_MISSING_BOUNDS([INT_FAST64_MIN INT_FAST64_MAX])
271     fi
272     if test $gl_cv_stdint_uint_fast64_t = yes; then
273       gl_STDINT_MISSING_BOUNDS([UINT_FAST64_MAX])
274     fi
275     gl_STDINT_MISSING_BOUNDS([INTPTR_MIN INTPTR_MAX UINTPTR_MAX \
276                               INTMAX_MIN INTMAX_MAX UINTMAX_MAX])
277     gl_STDINT_MISSING_BOUNDS([PTRDIFF_MIN PTRDIFF_MAX], [#include <stddef.h>])
278     gl_SIZE_MAX
279     gl_STDINT_MISSING_BOUNDS2([SIG_ATOMIC_MIN SIG_ATOMIC_MAX],
280       [#include <signal.h>])
281     dnl Don't bother defining WCHAR_MIN and WCHAR_MAX, since they should
282     dnl already be defined in <stddef.h>.
283     dnl For wint_t we need <wchar.h>.
284     dnl Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included
285     dnl before <wchar.h>.
286     dnl BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
287     dnl <wchar.h>.
288     gl_STDINT_MISSING_BOUNDS2([WINT_MIN WINT_MAX], [
289 #include <stdio.h>
290 #include <time.h>
291 #include <wchar.h>
292 ])
293     STDINT_H=''
294   else
295
296     gl_STDINT_BITSIZEOF(
297       [int8_t int16_t int32_t int64_t \
298        uint8_t uint16_t uint32_t uint64_t \
299        int_least8_t int_least16_t int_least32_t int_least64_t \
300        uint_least8_t uint_least16_t uint_least32_t uint_least64_t \
301        int_fast8_t int_fast16_t int_fast32_t int_fast64_t \
302        uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t \
303        intptr_t uintptr_t \
304        intmax_t uintmax_t],
305       [$other_includes])
306
307     gl_cv_type_unsigned_int=yes
308     gl_cv_type_long=yes
309     gl_cv_type_unsigned_long=yes
310     gl_STDINT_BITSIZEOF([unsigned_int long unsigned_long],
311       [typedef unsigned int unsigned_int;
312        typedef unsigned long unsigned_long;])
313
314     AC_CHECK_TYPES([ptrdiff_t])
315     gl_cv_type_ptrdiff_t=$ac_cv_type_ptrdiff_t
316     AC_REQUIRE([AC_TYPE_SIZE_T])
317     gl_cv_type_size_t=yes
318     gl_STDINT_BITSIZEOF([ptrdiff_t size_t], [#include <stddef.h>])
319     gl_CHECK_TYPE_SAME([ptrdiff_t], [long], [#include <stddef.h>])
320     gl_CHECK_TYPE_SAME([size_t], [unsigned long], [#include <stddef.h>])
321
322     AC_CHECK_TYPES([sig_atomic_t], , , [#include <signal.h>])
323     gl_cv_type_sig_atomic_t=$ac_cv_type_sig_atomic_t
324     gl_STDINT_BITSIZEOF([sig_atomic_t], [#include <signal.h>])
325     gl_CHECK_TYPES_SIGNED([sig_atomic_t], [#include <signal.h>])
326     if test $HAVE_SIGNED_SIG_ATOMIC_T = 1; then
327       gl_CHECK_TYPE_SAME([sig_atomic_t], [long], [#include <signal.h>])
328     else
329       gl_CHECK_TYPE_SAME([sig_atomic_t], [unsigned long], [#include <signal.h>])
330     fi
331
332     AC_REQUIRE([gt_TYPE_WCHAR_T])
333     gl_cv_type_wchar_t=$gt_cv_c_wchar_t
334     gl_STDINT_BITSIZEOF([wchar_t], [#include <stddef.h>])
335     gl_CHECK_TYPES_SIGNED([wchar_t], [#include <stddef.h>])
336     if test $HAVE_SIGNED_WCHAR_T = 1; then
337       gl_CHECK_TYPE_SAME([wchar_t], [long], [#include <stddef.h>])
338     else
339       gl_CHECK_TYPE_SAME([wchar_t], [unsigned long], [#include <stddef.h>])
340     fi
341
342     dnl For wint_t we need <wchar.h>.
343     dnl Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included
344     dnl before <wchar.h>.
345     dnl BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
346     dnl <wchar.h>.
347     AC_CHECK_TYPES([wint_t], , , [#include <stdio.h>
348 #include <time.h>
349 #include <wchar.h>
350 ])
351     gl_cv_type_wint_t=$ac_cv_type_wint_t
352     gl_STDINT_BITSIZEOF([wint_t], [#include <stdio.h>
353 #include <time.h>
354 #include <wchar.h>
355 ])
356     gl_CHECK_TYPES_SIGNED([wint_t], [#include <stdio.h>
357 #include <time.h>
358 #include <wchar.h>
359 ])
360     if test $HAVE_SIGNED_WINT_T = 1; then
361       gl_CHECK_TYPE_SAME([wint_t], [long], [#include <stdio.h>
362 #include <time.h>
363 #include <wchar.h>
364 ])
365     else
366       gl_CHECK_TYPE_SAME([wint_t], [unsigned long], [#include <stdio.h>
367 #include <time.h>
368 #include <wchar.h>
369 ])
370     fi
371
372     STDINT_H='stdint.h'
373   fi
374   AC_SUBST(STDINT_H)
375 ])
376
377 dnl Set gl_cv_header_stdint_h to yes and define HAVE_STDINT_H if
378 dnl <stdint.h> exists and doesn't clash with <sys/types.h>.
379 AC_DEFUN([gl_HEADER_STDINT_H],
380 [
381   dnl Check for <stdint.h> that doesn't clash with <sys/types.h>.
382   AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h, [
383     AC_TRY_COMPILE([
384 #include <sys/types.h>
385 #include <stdint.h>],
386       [], gl_cv_header_stdint_h=yes, gl_cv_header_stdint_h=no)
387   ])
388   if test $gl_cv_header_stdint_h = yes; then
389     AC_DEFINE_UNQUOTED(HAVE_STDINT_H, 1,
390       [Define if <stdint.h> exists and doesn't clash with <sys/types.h>.])
391   fi
392 ])
393
394 dnl Set gl_cv_header_inttypes_h to yes and define HAVE_INTTYPES_H if
395 dnl <inttypes.h> exists and doesn't clash with <sys/types.h>.
396 AC_DEFUN([gl_HEADER_INTTYPES_H],
397 [
398   dnl Check for <inttypes.h> that doesn't clash with <sys/types.h>.
399   dnl On IRIX 5.3, <inttypes.h> conflicts with <sys/types.h>.
400   AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h, [
401     AC_TRY_COMPILE([
402 #include <sys/types.h>
403 #include <inttypes.h>],
404       [], gl_cv_header_inttypes_h=yes, gl_cv_header_inttypes_h=no)
405   ])
406   if test $gl_cv_header_inttypes_h = yes; then
407     AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H, 1,
408       [Define if <inttypes.h> exists and doesn't clash with <sys/types.h>.])
409   fi
410 ])
411
412 dnl gl_STDINT_CHECK_TYPES(TYPES, INCLUDES, CACHE_VAR_PREFIX, MACRO_SUFFIX, DESCRIPTION_SUFFIX)
413 dnl Check each of the given types, whether they are defined in the given
414 dnl include files.
415 AC_DEFUN([gl_STDINT_CHECK_TYPES],
416 [
417   dnl Use a shell loop, to avoid bloating configure, and
418   dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
419   dnl   config.h.in,
420   dnl - extra AC_SUBST calls, so that the right substitutions are made.
421   AC_FOREACH([gltype], [$1],
422     [AH_TEMPLATE([HAVE_]translit(gltype,[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])[$4],
423        [Define to 1 if the type ']gltype[' is already defined$5.])])
424   for gltype in $1 ; do
425     AC_MSG_CHECKING([for $gltype])
426     AC_COMPILE_IFELSE([
427       AC_LANG_PROGRAM([$2
428 /* Test if the type exists.  */
429 $gltype x = 17;
430       ])],
431       result=yes, result=no)
432     eval $3${gltype}=\$result
433     AC_MSG_RESULT($result)
434     GLTYPE=`echo "$gltype" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
435     if test $result = yes; then
436       AC_DEFINE_UNQUOTED([HAVE_${GLTYPE}$4], 1)
437       eval HAVE_${GLTYPE}$4=1
438     else
439       eval HAVE_${GLTYPE}$4=0
440     fi
441   done
442   AC_FOREACH([gltype], [$1],
443     [AC_SUBST([HAVE_]translit(gltype,[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])[$4])])
444 ])
445
446 dnl gl_STDINT_MISSING_BOUND(TYPE_BOUND, DEFAULT, DESCRIPTION)
447 dnl assumes an otherwise complete <stdint.h> and defines TYPE_BOUND if
448 dnl <stdint.h> doesn't define it.
449 AC_DEFUN([gl_STDINT_MISSING_BOUND],
450 [
451   AC_CACHE_CHECK([for $1], [gl_cv_stdint_$1],
452     [AC_EGREP_CPP([found it], [#include <stdint.h>
453 #ifdef $1
454 found it
455 #endif
456        ], [gl_cv_stdint_$1=yes], [gl_cv_stdint_$1="$2"])])
457   if test "$gl_cv_stdint_$1" != yes; then
458     AC_DEFINE_UNQUOTED([$1], [$2], [$3])
459   fi
460 ])
461
462 dnl gl_STDINT_MISSING_BOUNDS(BOUNDS, INCLUDES)
463 dnl assumes an otherwise complete <stdint.h> and defines each element of BOUNDS
464 dnl if <stdint.h> doesn't define it.
465 dnl Use this for types whose signedness is determined by the first letter
466 dnl ('u' or not).
467 AC_DEFUN([gl_STDINT_MISSING_BOUNDS],
468 [
469   dnl Use a shell loop, to avoid bloating configure, and
470   dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
471   dnl   config.h.in.
472   AC_FOREACH([bound], [$1],
473     [AH_TEMPLATE(bound, [Define if <stdint.h> doesn't define it.])])
474 changequote(,)dnl
475   sed_unsigned='s,^\(U*\).*,\1,'
476   sed_limitkind='s,^.*\(_[^_]*\)$,\1,'
477 changequote([,])dnl
478   for bound in $1; do
479     type=`echo $bound | sed -e 's,_MAX,_t,' -e 's,_MIN,_t,' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
480     unsigned=`echo $bound | sed -e "$sed_unsigned" | tr U u`
481     width=`echo $bound | sed -e 's,^U*INT,,' -e 's,_MIN,,' -e 's,_MAX,,'`
482     limitkind=`echo $bound | sed -e "$sed_limitkind"`
483     AC_CACHE_CHECK([for $bound], [gl_cv_stdint_$bound],
484       [AC_EGREP_CPP([found it], [#include <stdint.h>
485 #ifdef $bound
486 found it
487 #endif
488          ], [eval gl_cv_stdint_$bound=yes],
489          [result=
490           case $width in
491             *8) widthlist="8 16 32 64" ;;
492             *16) widthlist="16 32 64" ;;
493             *32 | PTR | MAX | PTRDIFF) widthlist="32 64" ;;
494             *64) widthlist="64" ;;
495           esac
496           for w in $widthlist; do
497             if test -z "$result"; then
498               AC_COMPILE_IFELSE([[$2
499 #include <stdint.h>
500 int verify[2 * (sizeof ($type) == sizeof (${unsigned}int${w}_t)) - 1];
501                 ]], [result=`echo "$unsigned" | tr u U`INT${w}${limitkind}])
502             else
503               break
504             fi
505           done
506           if test -z "$result"; then
507             result=no
508           fi
509           eval gl_cv_stdint_$bound=\$result
510          ])])
511     eval result=\$gl_cv_stdint_$bound
512     if test "$result" != yes && test "$result" != no; then
513       AC_DEFINE_UNQUOTED([$bound], [$result],
514         [Define if <stdint.h> doesn't define it.])
515     fi
516   done
517 ])
518
519 dnl gl_STDINT_MISSING_BOUNDS2(BOUNDS, INCLUDES)
520 dnl assumes an otherwise complete <stdint.h> and defines each element of BOUNDS
521 dnl if <stdint.h> doesn't define it.
522 dnl Use this for types whose signedness is a priori unknown.
523 AC_DEFUN([gl_STDINT_MISSING_BOUNDS2],
524 [
525   dnl Use a shell loop, to avoid bloating configure, and
526   dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
527   dnl   config.h.in.
528   AC_FOREACH([bound], [$1],
529     [AH_TEMPLATE(bound, [Define if <stdint.h> doesn't define it.])])
530 changequote(,)dnl
531   sed_limitkind='s,^.*\(_[^_]*\)$,\1,'
532 changequote([,])dnl
533   for bound in $1; do
534     type=`echo $bound | sed -e 's,_MAX,_t,' -e 's,_MIN,_t,' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
535     limitkind=`echo $bound | sed -e "$sed_limitkind"`
536     AC_CACHE_CHECK([for $bound], [gl_cv_stdint_$bound],
537       [AC_EGREP_CPP([found it], [#include <stdint.h>
538 #ifdef $bound
539 found it
540 #endif
541          ], [eval gl_cv_stdint_$bound=yes],
542          [result=
543           AC_COMPILE_IFELSE([[$2
544             int verify[2 * (($type) -1 >= ($type) 0) - 1];
545             ]],
546             [eval gl_cv_${type}_signed=no],
547             [eval gl_cv_${type}_signed=yes])
548           if eval test \$gl_cv_${type}_signed = yes; then
549             for w in 8 16 32 64; do
550               if test -z "$result"; then
551                 AC_COMPILE_IFELSE([[$2
552 #include <stdint.h>
553 int verify[2 * (sizeof ($type) == sizeof (int${w}_t)) - 1];
554                   ]], [result=INT${w}${limitkind}])
555               else
556                 break
557               fi
558             done
559           else
560             if test ${limitkind} = _MIN; then
561               result=0
562             else
563               for w in 8 16 32 64; do
564                 if test -z "$result"; then
565                   AC_COMPILE_IFELSE([[$2
566 #include <stdint.h>
567 int verify[2 * (sizeof ($type) == sizeof (uint${w}_t)) - 1];
568                     ]], [result=UINT${w}${limitkind}])
569                 else
570                   break
571                 fi
572               done
573             fi
574           fi
575           if test -z "$result"; then
576             result=no
577           fi
578           eval gl_cv_stdint_$bound=\$result
579          ])])
580     eval result=\$gl_cv_stdint_$bound
581     if test "$result" != yes && test "$result" != no; then
582       AC_DEFINE_UNQUOTED([$bound], [$result],
583         [Define if <stdint.h> doesn't define it.])
584     fi
585   done
586 ])
587
588 dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES)
589 dnl Determine the size of each of the given types in bits.
590 AC_DEFUN([gl_STDINT_BITSIZEOF],
591 [
592   dnl Use a shell loop, to avoid bloating configure, and
593   dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
594   dnl   config.h.in,
595   dnl - extra AC_SUBST calls, so that the right substitutions are made.
596   AC_FOREACH([gltype], [$1],
597     [AH_TEMPLATE([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]),
598        [Define to the number of bits in type ']gltype['.])])
599   for gltype in $1 ; do
600     if eval test \$gl_cv_type_${gltype} = yes; then
601       AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}],
602         [_AC_COMPUTE_INT([sizeof ($gltype) * CHAR_BIT], result,
603            [$2
604 #include <limits.h>], result=unknown)
605          eval gl_cv_bitsizeof_${gltype}=\$result
606         ])
607       eval result=\$gl_cv_bitsizeof_${gltype}
608       GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
609       AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result])
610       eval BITSIZEOF_${GLTYPE}=\$result
611     fi
612   done
613   AC_FOREACH([gltype], [$1],
614     [AC_SUBST([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))])
615 ])
616
617 dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES)
618 dnl Determine the signedness of each of the given types.
619 dnl Define HAVE_SIGNED_TYPE if type is signed.
620 AC_DEFUN([gl_CHECK_TYPES_SIGNED],
621 [
622   dnl Use a shell loop, to avoid bloating configure, and
623   dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into
624   dnl   config.h.in,
625   dnl - extra AC_SUBST calls, so that the right substitutions are made.
626   AC_FOREACH([gltype], [$1],
627     [AH_TEMPLATE([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]),
628        [Define to 1 if ']gltype[' is a signed integer type.])])
629   for gltype in $1 ; do
630     AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed],
631       [AC_COMPILE_IFELSE(
632          [AC_LANG_PROGRAM([[$2
633             int verify[2 * (($1) -1 < ($1) 0) - 1];
634             ]])],
635          result=yes, result=no)
636        eval gl_cv_type_${gltype}_signed=\$result
637       ])
638     eval result=\$gl_cv_type_${gltype}_signed
639     GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`
640     if test "$result" = yes; then
641       AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], 1)
642       eval HAVE_SIGNED_${GLTYPE}=1
643     else
644       eval HAVE_SIGNED_${GLTYPE}=0
645     fi
646   done
647   AC_FOREACH([gltype], [$1],
648     [AC_SUBST([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))])
649 ])
650
651 dnl gl_CHECK_TYPE_SAME(TYPE, KNOWNTYPE, INCLUDES)
652 dnl Determines whether two types are the same.
653 AC_DEFUN([gl_CHECK_TYPE_SAME],
654 [
655   AC_TRY_COMPILE([$3
656     extern $1 foo;
657     extern $2 foo;], [],
658     [SAME_TYPE_]AS_TR_CPP([$1])[_]AS_TR_CPP([$2])[=1],
659     [SAME_TYPE_]AS_TR_CPP([$1])[_]AS_TR_CPP([$2])[=0])
660   AC_SUBST([SAME_TYPE_]AS_TR_CPP([$1])[_]AS_TR_CPP([$2]))
661 ])