1 dnl @synopsis GCC_HEADER_STDINT [( HEADER-TO-GENERATE [, HEADERS-TO-CHECK])]
3 dnl the "ISO C9X: 7.18 Integer types <stdint.h>" section requires the
4 dnl existence of an include file <stdint.h> that defines a set of
5 dnl typedefs, especially uint8_t,int32_t,uintptr_t.
6 dnl Many older installations will not provide this file, but some will
7 dnl have the very same definitions in <inttypes.h>. In other enviroments
8 dnl we can use the inet-types in <sys/types.h> which would define the
9 dnl typedefs int8_t and u_int8_t respectivly.
11 dnl This macros will create a local "_stdint.h" or the headerfile given as
12 dnl an argument. In many cases that file will pick the definition from a
13 dnl "#include <stdint.h>" or "#include <inttypes.h>" statement, while
14 dnl in other environments it will provide the set of basic 'stdint's defined:
15 dnl int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,intptr_t,uintptr_t
16 dnl int_least32_t.. int_fast32_t.. intmax_t
17 dnl which may or may not rely on the definitions of other files.
19 dnl Sometimes the stdint.h or inttypes.h headers conflict with sys/types.h,
20 dnl so we test the headers together with sys/types.h and always include it
21 dnl into the generated header (to match the tests with the generated file).
22 dnl Hopefully this is not a big annoyance.
24 dnl If your installed header files require the stdint-types you will want to
25 dnl create an installable file mylib-int.h that all your other installable
26 dnl header may include. So, for a library package named "mylib", just use
27 dnl GCC_HEADER_STDINT(mylib-int.h)
28 dnl in configure.in and install that header file in Makefile.am along with
29 dnl the other headers (mylib.h). The mylib-specific headers can simply
30 dnl use "#include <mylib-int.h>" to obtain the stdint-types.
32 dnl Remember, if the system already had a valid <stdint.h>, the generated
33 dnl file will include it directly. No need for fuzzy HAVE_STDINT_H things...
35 dnl @author Guido Draheim <guidod@gmx.de>, Paolo Bonzini <bonzini@gnu.org>
37 AC_DEFUN([GCC_HEADER_STDINT],
38 [m4_define(_GCC_STDINT_H, m4_ifval($1, $1, _stdint.h))
40 inttype_headers=`echo inttypes.h sys/inttypes.h $2 | sed -e 's/,/ /g'`
42 acx_cv_header_stdint=stddef.h
43 acx_cv_header_stdint_kind="(already complete)"
44 for i in stdint.h $inttype_headers; do
45 unset ac_cv_type_uintptr_t
46 unset ac_cv_type_uintmax_t
47 unset ac_cv_type_int_least32_t
48 unset ac_cv_type_int_fast32_t
49 unset ac_cv_type_uint64_t
50 _AS_ECHO_N([looking for a compliant stdint.h in $i, ])
51 AC_CHECK_TYPE(uintmax_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h>
53 AC_CHECK_TYPE(uintptr_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
55 AC_CHECK_TYPE(int_least32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
57 AC_CHECK_TYPE(int_fast32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
59 AC_CHECK_TYPE(uint64_t,,[acx_cv_header_stdint_kind="(lacks uint64_t)"], [#include <sys/types.h>
63 if test "$acx_cv_header_stdint" = stddef.h; then
64 acx_cv_header_stdint_kind="(lacks uintptr_t)"
65 for i in stdint.h $inttype_headers; do
66 unset ac_cv_type_uint32_t
67 unset ac_cv_type_uint64_t
68 _AS_ECHO_N([looking for an incomplete stdint.h in $i, ])
69 AC_CHECK_TYPE(uint32_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h>
71 AC_CHECK_TYPE(uint64_t,,[acx_cv_header_stdint_kind="(lacks uintptr_t and uint64_t)"], [#include <sys/types.h>
76 if test "$acx_cv_header_stdint" = stddef.h; then
77 acx_cv_header_stdint_kind="(u_intXX_t style)"
78 for i in sys/types.h $inttype_headers; do
79 unset ac_cv_type_u_int32_t
80 unset ac_cv_type_u_int64_t
81 _AS_ECHO_N([looking for u_intXX_t types in $i, ])
82 AC_CHECK_TYPE(u_int32_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h>
84 AC_CHECK_TYPE(u_int64_t,,[acx_cv_header_stdint_kind="(u_intXX_t style, lacks u_int64_t)"], [#include <sys/types.h>
89 if test "$acx_cv_header_stdint" = stddef.h; then
90 acx_cv_header_stdint_kind="(using manual detection)"
93 test -z "$ac_cv_type_uintptr_t" && ac_cv_type_uintptr_t=no
94 test -z "$ac_cv_type_uint64_t" && ac_cv_type_uint64_t=no
95 test -z "$ac_cv_type_u_int64_t" && ac_cv_type_u_int64_t=no
96 test -z "$ac_cv_type_int_least32_t" && ac_cv_type_int_least32_t=no
97 test -z "$ac_cv_type_int_fast32_t" && ac_cv_type_int_fast32_t=no
99 # ----------------- Summarize what we found so far
101 AC_MSG_CHECKING([what to include in _GCC_STDINT_H])
103 case `AS_BASENAME(_GCC_STDINT_H)` in
104 stdint.h) AC_MSG_WARN([are you sure you want it there?]) ;;
105 inttypes.h) AC_MSG_WARN([are you sure you want it there?]) ;;
109 AC_MSG_RESULT($acx_cv_header_stdint $acx_cv_header_stdint_kind)
111 # ----------------- done included file, check C basic types --------
113 # Lacking an uintptr_t? Test size of void *
114 case "$acx_cv_header_stdint:$ac_cv_type_uintptr_t" in
115 stddef.h:* | *:no) AC_CHECK_SIZEOF(void *) ;;
118 # Lacking an uint64_t? Test size of long
119 case "$acx_cv_header_stdint:$ac_cv_type_uint64_t:$ac_cv_type_u_int64_t" in
120 stddef.h:*:* | *:no:no) AC_CHECK_SIZEOF(long) ;;
123 if test $acx_cv_header_stdint = stddef.h; then
124 # Lacking a good header? Test size of everything and deduce all types.
126 AC_CHECK_SIZEOF(short)
127 AC_CHECK_SIZEOF(char)
129 AC_MSG_CHECKING(for type equivalent to int8_t)
130 case "$ac_cv_sizeof_char" in
131 1) acx_cv_type_int8_t=char ;;
132 *) AC_MSG_ERROR(no 8-bit type, please report a bug)
134 AC_MSG_RESULT($acx_cv_type_int8_t)
136 AC_MSG_CHECKING(for type equivalent to int16_t)
137 case "$ac_cv_sizeof_int:$ac_cv_sizeof_short" in
138 2:*) acx_cv_type_int16_t=int ;;
139 *:2) acx_cv_type_int16_t=short ;;
140 *) AC_MSG_ERROR(no 16-bit type, please report a bug)
142 AC_MSG_RESULT($acx_cv_type_int16_t)
144 AC_MSG_CHECKING(for type equivalent to int32_t)
145 case "$ac_cv_sizeof_int:$ac_cv_sizeof_long" in
146 4:*) acx_cv_type_int32_t=int ;;
147 *:4) acx_cv_type_int32_t=long ;;
148 *) AC_MSG_ERROR(no 32-bit type, please report a bug)
150 AC_MSG_RESULT($acx_cv_type_int32_t)
153 # These tests are here to make the output prettier
155 if test "$ac_cv_type_uint64_t" != yes && test "$ac_cv_type_u_int64_t" != yes; then
156 case "$ac_cv_sizeof_long" in
157 8) acx_cv_type_int64_t=long ;;
159 AC_MSG_CHECKING(for type equivalent to int64_t)
160 AC_MSG_RESULT(${acx_cv_type_int64_t-'using preprocessor symbols'})
163 # Now we can use the above types
165 if test "$ac_cv_type_uintptr_t" != yes; then
166 AC_MSG_CHECKING(for type equivalent to intptr_t)
167 case $ac_cv_sizeof_void_p in
168 2) acx_cv_type_intptr_t=int16_t ;;
169 4) acx_cv_type_intptr_t=int32_t ;;
170 8) acx_cv_type_intptr_t=int64_t ;;
171 *) AC_MSG_ERROR(no equivalent for intptr_t, please report a bug)
173 AC_MSG_RESULT($acx_cv_type_intptr_t)
176 # ----------------- done all checks, emit header -------------
177 AC_CONFIG_COMMANDS(_GCC_STDINT_H, [
178 if test "$GCC" = yes; then
179 echo "/* generated for " `$CC --version | sed 1q` "*/" > tmp-stdint.h
181 echo "/* generated for $CC */" > tmp-stdint.h
184 sed 's/^ *//' >> tmp-stdint.h <<EOF
186 #ifndef GCC_GENERATED_STDINT_H
187 #define GCC_GENERATED_STDINT_H 1
189 #include <sys/types.h>
192 if test "$acx_cv_header_stdint" != stdint.h; then
193 echo "#include <stddef.h>" >> tmp-stdint.h
195 if test "$acx_cv_header_stdint" != stddef.h; then
196 echo "#include <$acx_cv_header_stdint>" >> tmp-stdint.h
199 sed 's/^ *//' >> tmp-stdint.h <<EOF
200 /* glibc uses these symbols as guards to prevent redefinitions. */
201 #ifdef __int8_t_defined
206 #ifdef __uint32_t_defined
212 # ----------------- done header, emit basic int types -------------
213 if test "$acx_cv_header_stdint" = stddef.h; then
214 sed 's/^ *//' >> tmp-stdint.h <<EOF
218 typedef unsigned $acx_cv_type_int8_t uint8_t;
223 typedef unsigned $acx_cv_type_int16_t uint16_t;
228 typedef unsigned $acx_cv_type_int32_t uint32_t;
233 typedef $acx_cv_type_int8_t int8_t;
238 typedef $acx_cv_type_int16_t int16_t;
243 typedef $acx_cv_type_int32_t int32_t;
246 elif test "$ac_cv_type_u_int32_t" = yes; then
247 sed 's/^ *//' >> tmp-stdint.h <<EOF
249 /* int8_t int16_t int32_t defined by inet code, we do the u_intXX types */
262 typedef u_int8_t uint8_t;
267 typedef u_int16_t uint16_t;
272 typedef u_int32_t uint32_t;
276 sed 's/^ *//' >> tmp-stdint.h <<EOF
278 /* Some systems have guard macros to prevent redefinitions, define them. */
300 # ------------- done basic int types, emit int64_t types ------------
301 if test "$ac_cv_type_uint64_t" = yes; then
302 sed 's/^ *//' >> tmp-stdint.h <<EOF
304 /* system headers have good uint64_t and int64_t */
312 elif test "$ac_cv_type_u_int64_t" = yes; then
313 sed 's/^ *//' >> tmp-stdint.h <<EOF
315 /* system headers have an u_int64_t (and int64_t) */
321 typedef u_int64_t uint64_t;
324 elif test -n "$acx_cv_type_int64_t"; then
325 sed 's/^ *//' >> tmp-stdint.h <<EOF
327 /* architecture has a 64-bit type, $acx_cv_type_int64_t */
330 typedef $acx_cv_type_int64_t int64_t;
334 typedef unsigned $acx_cv_type_int64_t uint64_t;
338 sed 's/^ *//' >> tmp-stdint.h <<EOF
340 /* some common heuristics for int64_t, using compiler-specific tests */
341 #if defined __STDC_VERSION__ && (__STDC_VERSION__-0) >= 199901L
344 typedef long long int64_t;
348 typedef unsigned long long uint64_t;
351 #elif defined __GNUC__ && defined (__STDC__) && __STDC__-0
352 /* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
353 does not implement __extension__. But that compiler doesn't define
355 # if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
356 # define __extension__
361 __extension__ typedef long long int64_t;
365 __extension__ typedef unsigned long long uint64_t;
368 #elif !defined __STRICT_ANSI__
369 # if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
373 typedef __int64 int64_t;
377 typedef unsigned __int64 uint64_t;
379 # endif /* compiler */
381 #endif /* ANSI version */
385 # ------------- done int64_t types, emit intptr types ------------
386 if test "$ac_cv_type_uintptr_t" != yes; then
387 sed 's/^ *//' >> tmp-stdint.h <<EOF
389 /* Define intptr_t based on sizeof(void*) = $ac_cv_sizeof_void_p */
390 typedef u$acx_cv_type_intptr_t uintptr_t;
391 typedef $acx_cv_type_intptr_t intptr_t;
395 # ------------- done intptr types, emit int_least types ------------
396 if test "$ac_cv_type_int_least32_t" != yes; then
397 sed 's/^ *//' >> tmp-stdint.h <<EOF
399 /* Define int_least types */
400 typedef int8_t int_least8_t;
401 typedef int16_t int_least16_t;
402 typedef int32_t int_least32_t;
404 typedef int64_t int_least64_t;
407 typedef uint8_t uint_least8_t;
408 typedef uint16_t uint_least16_t;
409 typedef uint32_t uint_least32_t;
411 typedef uint64_t uint_least64_t;
416 # ------------- done intptr types, emit int_fast types ------------
417 if test "$ac_cv_type_int_fast32_t" != yes; then
418 dnl NOTE: The following code assumes that sizeof (int) > 1.
419 dnl Fix when strange machines are reported.
420 sed 's/^ *//' >> tmp-stdint.h <<EOF
422 /* Define int_fast types. short is often slow */
423 typedef int8_t int_fast8_t;
424 typedef int int_fast16_t;
425 typedef int32_t int_fast32_t;
427 typedef int64_t int_fast64_t;
430 typedef uint8_t uint_fast8_t;
431 typedef unsigned int uint_fast16_t;
432 typedef uint32_t uint_fast32_t;
434 typedef uint64_t uint_fast64_t;
439 if test "$ac_cv_type_uintmax_t" != yes; then
440 sed 's/^ *//' >> tmp-stdint.h <<EOF
442 /* Define intmax based on what we found */
444 typedef int64_t intmax_t;
446 typedef long intmax_t;
449 typedef uint64_t uintmax_t;
451 typedef unsigned long uintmax_t;
456 sed 's/^ *//' >> tmp-stdint.h <<EOF
458 #endif /* GCC_GENERATED_STDINT_H */
461 if test -r ]_GCC_STDINT_H[ && cmp -s tmp-stdint.h ]_GCC_STDINT_H[; then
464 mv -f tmp-stdint.h ]_GCC_STDINT_H[
470 acx_cv_header_stdint="$acx_cv_header_stdint"
471 acx_cv_type_int8_t="$acx_cv_type_int8_t"
472 acx_cv_type_int16_t="$acx_cv_type_int16_t"
473 acx_cv_type_int32_t="$acx_cv_type_int32_t"
474 acx_cv_type_int64_t="$acx_cv_type_int64_t"
475 acx_cv_type_intptr_t="$acx_cv_type_intptr_t"
476 ac_cv_type_uintmax_t="$ac_cv_type_uintmax_t"
477 ac_cv_type_uintptr_t="$ac_cv_type_uintptr_t"
478 ac_cv_type_uint64_t="$ac_cv_type_uint64_t"
479 ac_cv_type_u_int64_t="$ac_cv_type_u_int64_t"
480 ac_cv_type_u_int32_t="$ac_cv_type_u_int32_t"
481 ac_cv_type_int_least32_t="$ac_cv_type_int_least32_t"
482 ac_cv_type_int_fast32_t="$ac_cv_type_int_fast32_t"
483 ac_cv_sizeof_void_p="$ac_cv_sizeof_void_p"