16ca2c52aSchristosAC_DEFUN([GCC_STDINT_TYPES],
26ca2c52aSchristos[AC_REQUIRE([AC_TYPE_INT8_T])
36ca2c52aSchristosAC_REQUIRE([AC_TYPE_INT16_T])
46ca2c52aSchristosAC_REQUIRE([AC_TYPE_INT32_T])
56ca2c52aSchristosAC_REQUIRE([AC_TYPE_INT64_T])
66ca2c52aSchristosAC_REQUIRE([AC_TYPE_INTMAX_T])
76ca2c52aSchristosAC_REQUIRE([AC_TYPE_INTPTR_T])
86ca2c52aSchristosAC_REQUIRE([AC_TYPE_UINT8_T])
96ca2c52aSchristosAC_REQUIRE([AC_TYPE_UINT16_T])
106ca2c52aSchristosAC_REQUIRE([AC_TYPE_UINT32_T])
116ca2c52aSchristosAC_REQUIRE([AC_TYPE_UINT64_T])
126ca2c52aSchristosAC_REQUIRE([AC_TYPE_UINTMAX_T])
136ca2c52aSchristosAC_REQUIRE([AC_TYPE_UINTPTR_T])])
146ca2c52aSchristos
156ca2c52aSchristosdnl @synopsis GCC_HEADER_STDINT [( HEADER-TO-GENERATE [, HEADERS-TO-CHECK])]
166ca2c52aSchristosdnl
176ca2c52aSchristosdnl the "ISO C9X: 7.18 Integer types <stdint.h>" section requires the
186ca2c52aSchristosdnl existence of an include file <stdint.h> that defines a set of
196ca2c52aSchristosdnl typedefs, especially uint8_t,int32_t,uintptr_t.
206ca2c52aSchristosdnl Many older installations will not provide this file, but some will
216ca2c52aSchristosdnl have the very same definitions in <inttypes.h>. In other environments
226ca2c52aSchristosdnl we can use the inet-types in <sys/types.h> which would define the
236ca2c52aSchristosdnl typedefs int8_t and u_int8_t respectivly.
246ca2c52aSchristosdnl
256ca2c52aSchristosdnl This macros will create a local "_stdint.h" or the headerfile given as
266ca2c52aSchristosdnl an argument. In many cases that file will pick the definition from a
276ca2c52aSchristosdnl "#include <stdint.h>" or "#include <inttypes.h>" statement, while
286ca2c52aSchristosdnl in other environments it will provide the set of basic 'stdint's defined:
296ca2c52aSchristosdnl int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,intptr_t,uintptr_t
306ca2c52aSchristosdnl int_least32_t.. int_fast32_t.. intmax_t
316ca2c52aSchristosdnl which may or may not rely on the definitions of other files.
326ca2c52aSchristosdnl
336ca2c52aSchristosdnl Sometimes the stdint.h or inttypes.h headers conflict with sys/types.h,
346ca2c52aSchristosdnl so we test the headers together with sys/types.h and always include it
356ca2c52aSchristosdnl into the generated header (to match the tests with the generated file).
366ca2c52aSchristosdnl Hopefully this is not a big annoyance.
376ca2c52aSchristosdnl
386ca2c52aSchristosdnl If your installed header files require the stdint-types you will want to
396ca2c52aSchristosdnl create an installable file mylib-int.h that all your other installable
406ca2c52aSchristosdnl header may include. So, for a library package named "mylib", just use
416ca2c52aSchristosdnl      GCC_HEADER_STDINT(mylib-int.h)
42*b2396a7bSchristosdnl in configure.ac and install that header file in Makefile.am along with
436ca2c52aSchristosdnl the other headers (mylib.h).  The mylib-specific headers can simply
446ca2c52aSchristosdnl use "#include <mylib-int.h>" to obtain the stdint-types.
456ca2c52aSchristosdnl
466ca2c52aSchristosdnl Remember, if the system already had a valid <stdint.h>, the generated
476ca2c52aSchristosdnl file will include it directly. No need for fuzzy HAVE_STDINT_H things...
486ca2c52aSchristosdnl
496ca2c52aSchristosdnl @author  Guido Draheim <guidod@gmx.de>, Paolo Bonzini <bonzini@gnu.org>
506ca2c52aSchristos
516ca2c52aSchristosAC_DEFUN([GCC_HEADER_STDINT],
526ca2c52aSchristos[m4_define(_GCC_STDINT_H, m4_ifval($1, $1, _stdint.h))
536ca2c52aSchristos
546ca2c52aSchristosinttype_headers=`echo inttypes.h sys/inttypes.h $2 | sed -e 's/,/ /g'`
556ca2c52aSchristos
566ca2c52aSchristosacx_cv_header_stdint=stddef.h
576ca2c52aSchristosacx_cv_header_stdint_kind="(already complete)"
586ca2c52aSchristosfor i in stdint.h $inttype_headers; do
596ca2c52aSchristos  unset ac_cv_type_uintptr_t
606ca2c52aSchristos  unset ac_cv_type_uintmax_t
616ca2c52aSchristos  unset ac_cv_type_int_least32_t
626ca2c52aSchristos  unset ac_cv_type_int_fast32_t
636ca2c52aSchristos  unset ac_cv_type_uint64_t
646ca2c52aSchristos  _AS_ECHO_N([looking for a compliant stdint.h in $i, ])
656ca2c52aSchristos  AC_CHECK_TYPE(uintmax_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h>
666ca2c52aSchristos#include <$i>])
676ca2c52aSchristos  AC_CHECK_TYPE(uintptr_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
686ca2c52aSchristos#include <$i>])
696ca2c52aSchristos  AC_CHECK_TYPE(int_least32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
706ca2c52aSchristos#include <$i>])
716ca2c52aSchristos  AC_CHECK_TYPE(int_fast32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
726ca2c52aSchristos#include <$i>])
736ca2c52aSchristos  AC_CHECK_TYPE(uint64_t,,[acx_cv_header_stdint_kind="(lacks uint64_t)"], [#include <sys/types.h>
746ca2c52aSchristos#include <$i>])
756ca2c52aSchristos  break
766ca2c52aSchristosdone
776ca2c52aSchristosif test "$acx_cv_header_stdint" = stddef.h; then
786ca2c52aSchristos  acx_cv_header_stdint_kind="(lacks uintmax_t)"
796ca2c52aSchristos  for i in stdint.h $inttype_headers; do
806ca2c52aSchristos    unset ac_cv_type_uintptr_t
816ca2c52aSchristos    unset ac_cv_type_uint32_t
826ca2c52aSchristos    unset ac_cv_type_uint64_t
836ca2c52aSchristos    _AS_ECHO_N([looking for an incomplete stdint.h in $i, ])
846ca2c52aSchristos    AC_CHECK_TYPE(uint32_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h>
856ca2c52aSchristos#include <$i>])
866ca2c52aSchristos    AC_CHECK_TYPE(uint64_t,,,[#include <sys/types.h>
876ca2c52aSchristos#include <$i>])
886ca2c52aSchristos    AC_CHECK_TYPE(uintptr_t,,,[#include <sys/types.h>
896ca2c52aSchristos#include <$i>])
906ca2c52aSchristos    break
916ca2c52aSchristos  done
926ca2c52aSchristosfi
936ca2c52aSchristosif test "$acx_cv_header_stdint" = stddef.h; then
946ca2c52aSchristos  acx_cv_header_stdint_kind="(u_intXX_t style)"
956ca2c52aSchristos  for i in sys/types.h $inttype_headers; do
966ca2c52aSchristos    unset ac_cv_type_u_int32_t
976ca2c52aSchristos    unset ac_cv_type_u_int64_t
986ca2c52aSchristos    _AS_ECHO_N([looking for u_intXX_t types in $i, ])
996ca2c52aSchristos    AC_CHECK_TYPE(u_int32_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h>
1006ca2c52aSchristos#include <$i>])
1016ca2c52aSchristos    AC_CHECK_TYPE(u_int64_t,,,[#include <sys/types.h>
1026ca2c52aSchristos#include <$i>])
1036ca2c52aSchristos    break
1046ca2c52aSchristos  done
1056ca2c52aSchristosfi
1066ca2c52aSchristosif test "$acx_cv_header_stdint" = stddef.h; then
1076ca2c52aSchristos  acx_cv_header_stdint_kind="(using manual detection)"
1086ca2c52aSchristosfi
1096ca2c52aSchristos
1106ca2c52aSchristostest -z "$ac_cv_type_uintptr_t" && ac_cv_type_uintptr_t=no
1116ca2c52aSchristostest -z "$ac_cv_type_uint64_t" && ac_cv_type_uint64_t=no
1126ca2c52aSchristostest -z "$ac_cv_type_u_int64_t" && ac_cv_type_u_int64_t=no
1136ca2c52aSchristostest -z "$ac_cv_type_int_least32_t" && ac_cv_type_int_least32_t=no
1146ca2c52aSchristostest -z "$ac_cv_type_int_fast32_t" && ac_cv_type_int_fast32_t=no
1156ca2c52aSchristos
1166ca2c52aSchristos# ----------------- Summarize what we found so far
1176ca2c52aSchristos
1186ca2c52aSchristosAC_MSG_CHECKING([what to include in _GCC_STDINT_H])
1196ca2c52aSchristos
1206ca2c52aSchristoscase `AS_BASENAME(_GCC_STDINT_H)` in
1216ca2c52aSchristos  stdint.h) AC_MSG_WARN([are you sure you want it there?]) ;;
1226ca2c52aSchristos  inttypes.h) AC_MSG_WARN([are you sure you want it there?]) ;;
1236ca2c52aSchristos  *) ;;
1246ca2c52aSchristosesac
1256ca2c52aSchristos
1266ca2c52aSchristosAC_MSG_RESULT($acx_cv_header_stdint $acx_cv_header_stdint_kind)
1276ca2c52aSchristos
1286ca2c52aSchristos# ----------------- done included file, check C basic types --------
1296ca2c52aSchristos
1306ca2c52aSchristos# Lacking an uintptr_t?  Test size of void *
1316ca2c52aSchristoscase "$acx_cv_header_stdint:$ac_cv_type_uintptr_t" in
1326ca2c52aSchristos  stddef.h:* | *:no) AC_CHECK_SIZEOF(void *) ;;
1336ca2c52aSchristosesac
1346ca2c52aSchristos
1356ca2c52aSchristos# Lacking an uint64_t?  Test size of long
1366ca2c52aSchristoscase "$acx_cv_header_stdint:$ac_cv_type_uint64_t:$ac_cv_type_u_int64_t" in
1376ca2c52aSchristos  stddef.h:*:* | *:no:no) AC_CHECK_SIZEOF(long) ;;
1386ca2c52aSchristosesac
1396ca2c52aSchristos
1406ca2c52aSchristosif test $acx_cv_header_stdint = stddef.h; then
1416ca2c52aSchristos  # Lacking a good header?  Test size of everything and deduce all types.
1426ca2c52aSchristos  AC_CHECK_SIZEOF(int)
1436ca2c52aSchristos  AC_CHECK_SIZEOF(short)
1446ca2c52aSchristos  AC_CHECK_SIZEOF(char)
1456ca2c52aSchristos
1466ca2c52aSchristos  AC_MSG_CHECKING(for type equivalent to int8_t)
1476ca2c52aSchristos  case "$ac_cv_sizeof_char" in
1486ca2c52aSchristos    1) acx_cv_type_int8_t=char ;;
1496ca2c52aSchristos    *) AC_MSG_ERROR([no 8-bit type, please report a bug])
1506ca2c52aSchristos  esac
1516ca2c52aSchristos  AC_MSG_RESULT($acx_cv_type_int8_t)
1526ca2c52aSchristos
1536ca2c52aSchristos  AC_MSG_CHECKING(for type equivalent to int16_t)
1546ca2c52aSchristos  case "$ac_cv_sizeof_int:$ac_cv_sizeof_short" in
1556ca2c52aSchristos    2:*) acx_cv_type_int16_t=int ;;
1566ca2c52aSchristos    *:2) acx_cv_type_int16_t=short ;;
1576ca2c52aSchristos    *) AC_MSG_ERROR([no 16-bit type, please report a bug])
1586ca2c52aSchristos  esac
1596ca2c52aSchristos  AC_MSG_RESULT($acx_cv_type_int16_t)
1606ca2c52aSchristos
1616ca2c52aSchristos  AC_MSG_CHECKING(for type equivalent to int32_t)
1626ca2c52aSchristos  case "$ac_cv_sizeof_int:$ac_cv_sizeof_long" in
1636ca2c52aSchristos    4:*) acx_cv_type_int32_t=int ;;
1646ca2c52aSchristos    *:4) acx_cv_type_int32_t=long ;;
1656ca2c52aSchristos    *) AC_MSG_ERROR([no 32-bit type, please report a bug])
1666ca2c52aSchristos  esac
1676ca2c52aSchristos  AC_MSG_RESULT($acx_cv_type_int32_t)
1686ca2c52aSchristosfi
1696ca2c52aSchristos
1706ca2c52aSchristos# These tests are here to make the output prettier
1716ca2c52aSchristos
1726ca2c52aSchristosif test "$ac_cv_type_uint64_t" != yes && test "$ac_cv_type_u_int64_t" != yes; then
1736ca2c52aSchristos  case "$ac_cv_sizeof_long" in
1746ca2c52aSchristos    8) acx_cv_type_int64_t=long ;;
1756ca2c52aSchristos  esac
1766ca2c52aSchristos  AC_MSG_CHECKING(for type equivalent to int64_t)
1776ca2c52aSchristos  AC_MSG_RESULT(${acx_cv_type_int64_t-'using preprocessor symbols'})
1786ca2c52aSchristosfi
1796ca2c52aSchristos
1806ca2c52aSchristos# Now we can use the above types
1816ca2c52aSchristos
1826ca2c52aSchristosif test "$ac_cv_type_uintptr_t" != yes; then
1836ca2c52aSchristos  AC_MSG_CHECKING(for type equivalent to intptr_t)
1846ca2c52aSchristos  case $ac_cv_sizeof_void_p in
1856ca2c52aSchristos    2) acx_cv_type_intptr_t=int16_t ;;
1866ca2c52aSchristos    4) acx_cv_type_intptr_t=int32_t ;;
1876ca2c52aSchristos    8) acx_cv_type_intptr_t=int64_t ;;
1886ca2c52aSchristos    *) AC_MSG_ERROR([no equivalent for intptr_t, please report a bug])
1896ca2c52aSchristos  esac
1906ca2c52aSchristos  AC_MSG_RESULT($acx_cv_type_intptr_t)
1916ca2c52aSchristosfi
1926ca2c52aSchristos
1936ca2c52aSchristos# ----------------- done all checks, emit header -------------
1946ca2c52aSchristosAC_CONFIG_COMMANDS(_GCC_STDINT_H, [
1956ca2c52aSchristosif test "$GCC" = yes; then
1966ca2c52aSchristos  echo "/* generated for " `$CC --version | sed 1q` "*/" > tmp-stdint.h
1976ca2c52aSchristoselse
1986ca2c52aSchristos  echo "/* generated for $CC */" > tmp-stdint.h
1996ca2c52aSchristosfi
2006ca2c52aSchristos
2016ca2c52aSchristossed 's/^ *//' >> tmp-stdint.h <<EOF
2026ca2c52aSchristos
2036ca2c52aSchristos  #ifndef GCC_GENERATED_STDINT_H
2046ca2c52aSchristos  #define GCC_GENERATED_STDINT_H 1
2056ca2c52aSchristos
2066ca2c52aSchristos  #include <sys/types.h>
2076ca2c52aSchristosEOF
2086ca2c52aSchristos
2096ca2c52aSchristosif test "$acx_cv_header_stdint" != stdint.h; then
2106ca2c52aSchristos  echo "#include <stddef.h>" >> tmp-stdint.h
2116ca2c52aSchristosfi
2126ca2c52aSchristosif test "$acx_cv_header_stdint" != stddef.h; then
2136ca2c52aSchristos  echo "#include <$acx_cv_header_stdint>" >> tmp-stdint.h
2146ca2c52aSchristosfi
2156ca2c52aSchristos
2166ca2c52aSchristossed 's/^ *//' >> tmp-stdint.h <<EOF
2176ca2c52aSchristos  /* glibc uses these symbols as guards to prevent redefinitions.  */
2186ca2c52aSchristos  #ifdef __int8_t_defined
2196ca2c52aSchristos  #define _INT8_T
2206ca2c52aSchristos  #define _INT16_T
2216ca2c52aSchristos  #define _INT32_T
2226ca2c52aSchristos  #endif
2236ca2c52aSchristos  #ifdef __uint32_t_defined
2246ca2c52aSchristos  #define _UINT32_T
2256ca2c52aSchristos  #endif
2266ca2c52aSchristos
2276ca2c52aSchristosEOF
2286ca2c52aSchristos
2296ca2c52aSchristos# ----------------- done header, emit basic int types -------------
2306ca2c52aSchristosif test "$acx_cv_header_stdint" = stddef.h; then
2316ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
2326ca2c52aSchristos
2336ca2c52aSchristos    #ifndef _UINT8_T
2346ca2c52aSchristos    #define _UINT8_T
2356ca2c52aSchristos    #ifndef __uint8_t_defined
2366ca2c52aSchristos    #define __uint8_t_defined
2376ca2c52aSchristos    #ifndef uint8_t
2386ca2c52aSchristos    typedef unsigned $acx_cv_type_int8_t uint8_t;
2396ca2c52aSchristos    #endif
2406ca2c52aSchristos    #endif
2416ca2c52aSchristos    #endif
2426ca2c52aSchristos
2436ca2c52aSchristos    #ifndef _UINT16_T
2446ca2c52aSchristos    #define _UINT16_T
2456ca2c52aSchristos    #ifndef __uint16_t_defined
2466ca2c52aSchristos    #define __uint16_t_defined
2476ca2c52aSchristos    #ifndef uint16_t
2486ca2c52aSchristos    typedef unsigned $acx_cv_type_int16_t uint16_t;
2496ca2c52aSchristos    #endif
2506ca2c52aSchristos    #endif
2516ca2c52aSchristos    #endif
2526ca2c52aSchristos
2536ca2c52aSchristos    #ifndef _UINT32_T
2546ca2c52aSchristos    #define _UINT32_T
2556ca2c52aSchristos    #ifndef __uint32_t_defined
2566ca2c52aSchristos    #define __uint32_t_defined
2576ca2c52aSchristos    #ifndef uint32_t
2586ca2c52aSchristos    typedef unsigned $acx_cv_type_int32_t uint32_t;
2596ca2c52aSchristos    #endif
2606ca2c52aSchristos    #endif
2616ca2c52aSchristos    #endif
2626ca2c52aSchristos
2636ca2c52aSchristos    #ifndef _INT8_T
2646ca2c52aSchristos    #define _INT8_T
2656ca2c52aSchristos    #ifndef __int8_t_defined
2666ca2c52aSchristos    #define __int8_t_defined
2676ca2c52aSchristos    #ifndef int8_t
2686ca2c52aSchristos    typedef $acx_cv_type_int8_t int8_t;
2696ca2c52aSchristos    #endif
2706ca2c52aSchristos    #endif
2716ca2c52aSchristos    #endif
2726ca2c52aSchristos
2736ca2c52aSchristos    #ifndef _INT16_T
2746ca2c52aSchristos    #define _INT16_T
2756ca2c52aSchristos    #ifndef __int16_t_defined
2766ca2c52aSchristos    #define __int16_t_defined
2776ca2c52aSchristos    #ifndef int16_t
2786ca2c52aSchristos    typedef $acx_cv_type_int16_t int16_t;
2796ca2c52aSchristos    #endif
2806ca2c52aSchristos    #endif
2816ca2c52aSchristos    #endif
2826ca2c52aSchristos
2836ca2c52aSchristos    #ifndef _INT32_T
2846ca2c52aSchristos    #define _INT32_T
2856ca2c52aSchristos    #ifndef __int32_t_defined
2866ca2c52aSchristos    #define __int32_t_defined
2876ca2c52aSchristos    #ifndef int32_t
2886ca2c52aSchristos    typedef $acx_cv_type_int32_t int32_t;
2896ca2c52aSchristos    #endif
2906ca2c52aSchristos    #endif
2916ca2c52aSchristos    #endif
2926ca2c52aSchristosEOF
2936ca2c52aSchristoselif test "$ac_cv_type_u_int32_t" = yes; then
2946ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
2956ca2c52aSchristos
2966ca2c52aSchristos    /* int8_t int16_t int32_t defined by inet code, we do the u_intXX types */
2976ca2c52aSchristos    #ifndef _INT8_T
2986ca2c52aSchristos    #define _INT8_T
2996ca2c52aSchristos    #endif
3006ca2c52aSchristos    #ifndef _INT16_T
3016ca2c52aSchristos    #define _INT16_T
3026ca2c52aSchristos    #endif
3036ca2c52aSchristos    #ifndef _INT32_T
3046ca2c52aSchristos    #define _INT32_T
3056ca2c52aSchristos    #endif
3066ca2c52aSchristos
3076ca2c52aSchristos    #ifndef _UINT8_T
3086ca2c52aSchristos    #define _UINT8_T
3096ca2c52aSchristos    #ifndef __uint8_t_defined
3106ca2c52aSchristos    #define __uint8_t_defined
3116ca2c52aSchristos    #ifndef uint8_t
3126ca2c52aSchristos    typedef u_int8_t uint8_t;
3136ca2c52aSchristos    #endif
3146ca2c52aSchristos    #endif
3156ca2c52aSchristos    #endif
3166ca2c52aSchristos
3176ca2c52aSchristos    #ifndef _UINT16_T
3186ca2c52aSchristos    #define _UINT16_T
3196ca2c52aSchristos    #ifndef __uint16_t_defined
3206ca2c52aSchristos    #define __uint16_t_defined
3216ca2c52aSchristos    #ifndef uint16_t
3226ca2c52aSchristos    typedef u_int16_t uint16_t;
3236ca2c52aSchristos    #endif
3246ca2c52aSchristos    #endif
3256ca2c52aSchristos    #endif
3266ca2c52aSchristos
3276ca2c52aSchristos    #ifndef _UINT32_T
3286ca2c52aSchristos    #define _UINT32_T
3296ca2c52aSchristos    #ifndef __uint32_t_defined
3306ca2c52aSchristos    #define __uint32_t_defined
3316ca2c52aSchristos    #ifndef uint32_t
3326ca2c52aSchristos    typedef u_int32_t uint32_t;
3336ca2c52aSchristos    #endif
3346ca2c52aSchristos    #endif
3356ca2c52aSchristos    #endif
3366ca2c52aSchristosEOF
3376ca2c52aSchristoselse
3386ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
3396ca2c52aSchristos
3406ca2c52aSchristos    /* Some systems have guard macros to prevent redefinitions, define them.  */
3416ca2c52aSchristos    #ifndef _INT8_T
3426ca2c52aSchristos    #define _INT8_T
3436ca2c52aSchristos    #endif
3446ca2c52aSchristos    #ifndef _INT16_T
3456ca2c52aSchristos    #define _INT16_T
3466ca2c52aSchristos    #endif
3476ca2c52aSchristos    #ifndef _INT32_T
3486ca2c52aSchristos    #define _INT32_T
3496ca2c52aSchristos    #endif
3506ca2c52aSchristos    #ifndef _UINT8_T
3516ca2c52aSchristos    #define _UINT8_T
3526ca2c52aSchristos    #endif
3536ca2c52aSchristos    #ifndef _UINT16_T
3546ca2c52aSchristos    #define _UINT16_T
3556ca2c52aSchristos    #endif
3566ca2c52aSchristos    #ifndef _UINT32_T
3576ca2c52aSchristos    #define _UINT32_T
3586ca2c52aSchristos    #endif
3596ca2c52aSchristosEOF
3606ca2c52aSchristosfi
3616ca2c52aSchristos
3626ca2c52aSchristos# ------------- done basic int types, emit int64_t types ------------
3636ca2c52aSchristosif test "$ac_cv_type_uint64_t" = yes; then
3646ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
3656ca2c52aSchristos
3666ca2c52aSchristos    /* system headers have good uint64_t and int64_t */
3676ca2c52aSchristos    #ifndef _INT64_T
3686ca2c52aSchristos    #define _INT64_T
3696ca2c52aSchristos    #endif
3706ca2c52aSchristos    #ifndef _UINT64_T
3716ca2c52aSchristos    #define _UINT64_T
3726ca2c52aSchristos    #endif
3736ca2c52aSchristosEOF
3746ca2c52aSchristoselif test "$ac_cv_type_u_int64_t" = yes; then
3756ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
3766ca2c52aSchristos
3776ca2c52aSchristos    /* system headers have an u_int64_t (and int64_t) */
3786ca2c52aSchristos    #ifndef _INT64_T
3796ca2c52aSchristos    #define _INT64_T
3806ca2c52aSchristos    #endif
3816ca2c52aSchristos    #ifndef _UINT64_T
3826ca2c52aSchristos    #define _UINT64_T
3836ca2c52aSchristos    #ifndef __uint64_t_defined
3846ca2c52aSchristos    #define __uint64_t_defined
3856ca2c52aSchristos    #ifndef uint64_t
3866ca2c52aSchristos    typedef u_int64_t uint64_t;
3876ca2c52aSchristos    #endif
3886ca2c52aSchristos    #endif
3896ca2c52aSchristos    #endif
3906ca2c52aSchristosEOF
3916ca2c52aSchristoselif test -n "$acx_cv_type_int64_t"; then
3926ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
3936ca2c52aSchristos
3946ca2c52aSchristos    /* architecture has a 64-bit type, $acx_cv_type_int64_t */
3956ca2c52aSchristos    #ifndef _INT64_T
3966ca2c52aSchristos    #define _INT64_T
3976ca2c52aSchristos    #ifndef int64_t
3986ca2c52aSchristos    typedef $acx_cv_type_int64_t int64_t;
3996ca2c52aSchristos    #endif
4006ca2c52aSchristos    #endif
4016ca2c52aSchristos    #ifndef _UINT64_T
4026ca2c52aSchristos    #define _UINT64_T
4036ca2c52aSchristos    #ifndef __uint64_t_defined
4046ca2c52aSchristos    #define __uint64_t_defined
4056ca2c52aSchristos    #ifndef uint64_t
4066ca2c52aSchristos    typedef unsigned $acx_cv_type_int64_t uint64_t;
4076ca2c52aSchristos    #endif
4086ca2c52aSchristos    #endif
4096ca2c52aSchristos    #endif
4106ca2c52aSchristosEOF
4116ca2c52aSchristoselse
4126ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
4136ca2c52aSchristos
4146ca2c52aSchristos    /* some common heuristics for int64_t, using compiler-specific tests */
4156ca2c52aSchristos    #if defined __STDC_VERSION__ && (__STDC_VERSION__-0) >= 199901L
4166ca2c52aSchristos    #ifndef _INT64_T
4176ca2c52aSchristos    #define _INT64_T
4186ca2c52aSchristos    #ifndef __int64_t_defined
4196ca2c52aSchristos    #ifndef int64_t
4206ca2c52aSchristos    typedef long long int64_t;
4216ca2c52aSchristos    #endif
4226ca2c52aSchristos    #endif
4236ca2c52aSchristos    #endif
4246ca2c52aSchristos    #ifndef _UINT64_T
4256ca2c52aSchristos    #define _UINT64_T
4266ca2c52aSchristos    #ifndef uint64_t
4276ca2c52aSchristos    typedef unsigned long long uint64_t;
4286ca2c52aSchristos    #endif
4296ca2c52aSchristos    #endif
4306ca2c52aSchristos
4316ca2c52aSchristos    #elif defined __GNUC__ && defined (__STDC__) && __STDC__-0
4326ca2c52aSchristos    /* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
4336ca2c52aSchristos       does not implement __extension__.  But that compiler doesn't define
4346ca2c52aSchristos       __GNUC_MINOR__.  */
4356ca2c52aSchristos    # if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
4366ca2c52aSchristos    # define __extension__
4376ca2c52aSchristos    # endif
4386ca2c52aSchristos
4396ca2c52aSchristos    # ifndef _INT64_T
4406ca2c52aSchristos    # define _INT64_T
4416ca2c52aSchristos    # ifndef int64_t
4426ca2c52aSchristos    __extension__ typedef long long int64_t;
4436ca2c52aSchristos    # endif
4446ca2c52aSchristos    # endif
4456ca2c52aSchristos    # ifndef _UINT64_T
4466ca2c52aSchristos    # define _UINT64_T
4476ca2c52aSchristos    # ifndef uint64_t
4486ca2c52aSchristos    __extension__ typedef unsigned long long uint64_t;
4496ca2c52aSchristos    # endif
4506ca2c52aSchristos    # endif
4516ca2c52aSchristos
4526ca2c52aSchristos    #elif !defined __STRICT_ANSI__
4536ca2c52aSchristos    # if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
4546ca2c52aSchristos
4556ca2c52aSchristos    #  ifndef _INT64_T
4566ca2c52aSchristos    #  define _INT64_T
4576ca2c52aSchristos    #  ifndef int64_t
4586ca2c52aSchristos    typedef __int64 int64_t;
4596ca2c52aSchristos    #  endif
4606ca2c52aSchristos    #  endif
4616ca2c52aSchristos    #  ifndef _UINT64_T
4626ca2c52aSchristos    #  define _UINT64_T
4636ca2c52aSchristos    #  ifndef uint64_t
4646ca2c52aSchristos    typedef unsigned __int64 uint64_t;
4656ca2c52aSchristos    #  endif
4666ca2c52aSchristos    #  endif
4676ca2c52aSchristos    # endif /* compiler */
4686ca2c52aSchristos
4696ca2c52aSchristos    #endif /* ANSI version */
4706ca2c52aSchristosEOF
4716ca2c52aSchristosfi
4726ca2c52aSchristos
4736ca2c52aSchristos# ------------- done int64_t types, emit intptr types ------------
4746ca2c52aSchristosif test "$ac_cv_type_uintptr_t" != yes; then
4756ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
4766ca2c52aSchristos
4776ca2c52aSchristos    /* Define intptr_t based on sizeof(void*) = $ac_cv_sizeof_void_p */
4786ca2c52aSchristos    #ifndef __uintptr_t_defined
4796ca2c52aSchristos    #ifndef uintptr_t
4806ca2c52aSchristos    typedef u$acx_cv_type_intptr_t uintptr_t;
4816ca2c52aSchristos    #endif
4826ca2c52aSchristos    #endif
4836ca2c52aSchristos    #ifndef __intptr_t_defined
4846ca2c52aSchristos    #ifndef intptr_t
4856ca2c52aSchristos    typedef $acx_cv_type_intptr_t  intptr_t;
4866ca2c52aSchristos    #endif
4876ca2c52aSchristos    #endif
4886ca2c52aSchristosEOF
4896ca2c52aSchristosfi
4906ca2c52aSchristos
4916ca2c52aSchristos# ------------- done intptr types, emit int_least types ------------
4926ca2c52aSchristosif test "$ac_cv_type_int_least32_t" != yes; then
4936ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
4946ca2c52aSchristos
4956ca2c52aSchristos    /* Define int_least types */
4966ca2c52aSchristos    typedef int8_t     int_least8_t;
4976ca2c52aSchristos    typedef int16_t    int_least16_t;
4986ca2c52aSchristos    typedef int32_t    int_least32_t;
4996ca2c52aSchristos    #ifdef _INT64_T
5006ca2c52aSchristos    typedef int64_t    int_least64_t;
5016ca2c52aSchristos    #endif
5026ca2c52aSchristos
5036ca2c52aSchristos    typedef uint8_t    uint_least8_t;
5046ca2c52aSchristos    typedef uint16_t   uint_least16_t;
5056ca2c52aSchristos    typedef uint32_t   uint_least32_t;
5066ca2c52aSchristos    #ifdef _UINT64_T
5076ca2c52aSchristos    typedef uint64_t   uint_least64_t;
5086ca2c52aSchristos    #endif
5096ca2c52aSchristosEOF
5106ca2c52aSchristosfi
5116ca2c52aSchristos
5126ca2c52aSchristos# ------------- done intptr types, emit int_fast types ------------
5136ca2c52aSchristosif test "$ac_cv_type_int_fast32_t" != yes; then
5146ca2c52aSchristos  dnl NOTE: The following code assumes that sizeof (int) > 1.
5156ca2c52aSchristos  dnl Fix when strange machines are reported.
5166ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
5176ca2c52aSchristos
5186ca2c52aSchristos    /* Define int_fast types.  short is often slow */
5196ca2c52aSchristos    typedef int8_t       int_fast8_t;
5206ca2c52aSchristos    typedef int          int_fast16_t;
5216ca2c52aSchristos    typedef int32_t      int_fast32_t;
5226ca2c52aSchristos    #ifdef _INT64_T
5236ca2c52aSchristos    typedef int64_t      int_fast64_t;
5246ca2c52aSchristos    #endif
5256ca2c52aSchristos
5266ca2c52aSchristos    typedef uint8_t      uint_fast8_t;
5276ca2c52aSchristos    typedef unsigned int uint_fast16_t;
5286ca2c52aSchristos    typedef uint32_t     uint_fast32_t;
5296ca2c52aSchristos    #ifdef _UINT64_T
5306ca2c52aSchristos    typedef uint64_t     uint_fast64_t;
5316ca2c52aSchristos    #endif
5326ca2c52aSchristosEOF
5336ca2c52aSchristosfi
5346ca2c52aSchristos
5356ca2c52aSchristosif test "$ac_cv_type_uintmax_t" != yes; then
5366ca2c52aSchristos  sed 's/^ *//' >> tmp-stdint.h <<EOF
5376ca2c52aSchristos
5386ca2c52aSchristos    /* Define intmax based on what we found */
5396ca2c52aSchristos    #ifndef intmax_t
5406ca2c52aSchristos    #ifdef _INT64_T
5416ca2c52aSchristos    typedef int64_t       intmax_t;
5426ca2c52aSchristos    #else
5436ca2c52aSchristos    typedef long          intmax_t;
5446ca2c52aSchristos    #endif
5456ca2c52aSchristos    #endif
5466ca2c52aSchristos    #ifndef uintmax_t
5476ca2c52aSchristos    #ifdef _UINT64_T
5486ca2c52aSchristos    typedef uint64_t      uintmax_t;
5496ca2c52aSchristos    #else
5506ca2c52aSchristos    typedef unsigned long uintmax_t;
5516ca2c52aSchristos    #endif
5526ca2c52aSchristos    #endif
5536ca2c52aSchristosEOF
5546ca2c52aSchristosfi
5556ca2c52aSchristos
5566ca2c52aSchristossed 's/^ *//' >> tmp-stdint.h <<EOF
5576ca2c52aSchristos
5586ca2c52aSchristos  #endif /* GCC_GENERATED_STDINT_H */
5596ca2c52aSchristosEOF
5606ca2c52aSchristos
5616ca2c52aSchristosif test -r ]_GCC_STDINT_H[ && cmp -s tmp-stdint.h ]_GCC_STDINT_H[; then
5626ca2c52aSchristos  rm -f tmp-stdint.h
5636ca2c52aSchristoselse
5646ca2c52aSchristos  mv -f tmp-stdint.h ]_GCC_STDINT_H[
5656ca2c52aSchristosfi
5666ca2c52aSchristos
5676ca2c52aSchristos], [
5686ca2c52aSchristosGCC="$GCC"
5696ca2c52aSchristosCC="$CC"
5706ca2c52aSchristosacx_cv_header_stdint="$acx_cv_header_stdint"
5716ca2c52aSchristosacx_cv_type_int8_t="$acx_cv_type_int8_t"
5726ca2c52aSchristosacx_cv_type_int16_t="$acx_cv_type_int16_t"
5736ca2c52aSchristosacx_cv_type_int32_t="$acx_cv_type_int32_t"
5746ca2c52aSchristosacx_cv_type_int64_t="$acx_cv_type_int64_t"
5756ca2c52aSchristosacx_cv_type_intptr_t="$acx_cv_type_intptr_t"
5766ca2c52aSchristosac_cv_type_uintmax_t="$ac_cv_type_uintmax_t"
5776ca2c52aSchristosac_cv_type_uintptr_t="$ac_cv_type_uintptr_t"
5786ca2c52aSchristosac_cv_type_uint64_t="$ac_cv_type_uint64_t"
5796ca2c52aSchristosac_cv_type_u_int64_t="$ac_cv_type_u_int64_t"
5806ca2c52aSchristosac_cv_type_u_int32_t="$ac_cv_type_u_int32_t"
5816ca2c52aSchristosac_cv_type_int_least32_t="$ac_cv_type_int_least32_t"
5826ca2c52aSchristosac_cv_type_int_fast32_t="$ac_cv_type_int_fast32_t"
5836ca2c52aSchristosac_cv_sizeof_void_p="$ac_cv_sizeof_void_p"
5846ca2c52aSchristos])
5856ca2c52aSchristos
5866ca2c52aSchristos])
587