AC_DEFUN([GCC_HEADER_STDINT],
[m4_define(_GCC_STDINT_H, m4_ifval($1, $1, _stdint.h))
inttype_headers=`echo inttypes.h sys/inttypes.h $2 | sed -e 's/,/ /g'`
acx_cv_header_stdint=stddef.h
acx_cv_header_stdint_kind="(already complete)"
for i in stdint.h $inttype_headers; do
unset ac_cv_type_uintptr_t
unset ac_cv_type_uintmax_t
unset ac_cv_type_int_least32_t
unset ac_cv_type_int_fast32_t
unset ac_cv_type_uint64_t
_AS_ECHO_N([looking for a compliant stdint.h in $i, ])
AC_CHECK_TYPE(uintmax_t,[acx_cv_header_stdint=$i],continue,[ AC_CHECK_TYPE(uintptr_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [ AC_CHECK_TYPE(int_least32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [ AC_CHECK_TYPE(int_fast32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [ AC_CHECK_TYPE(uint64_t,,[acx_cv_header_stdint_kind="(lacks uint64_t)"], [ break
done
if test "$acx_cv_header_stdint" = stddef.h; then
acx_cv_header_stdint_kind="(lacks uintmax_t)"
for i in stdint.h $inttype_headers; do
unset ac_cv_type_uintptr_t
unset ac_cv_type_uint32_t
unset ac_cv_type_uint64_t
_AS_ECHO_N([looking for an incomplete stdint.h in $i, ])
AC_CHECK_TYPE(uint32_t,[acx_cv_header_stdint=$i],continue,[ AC_CHECK_TYPE(uint64_t,,,[ AC_CHECK_TYPE(uintptr_t,,,[ break
done
fi
if test "$acx_cv_header_stdint" = stddef.h; then
acx_cv_header_stdint_kind="(u_intXX_t style)"
for i in sys/types.h $inttype_headers; do
unset ac_cv_type_u_int32_t
unset ac_cv_type_u_int64_t
_AS_ECHO_N([looking for u_intXX_t types in $i, ])
AC_CHECK_TYPE(u_int32_t,[acx_cv_header_stdint=$i],continue,[ AC_CHECK_TYPE(u_int64_t,,,[ break
done
fi
if test "$acx_cv_header_stdint" = stddef.h; then
acx_cv_header_stdint_kind="(using manual detection)"
fi
test -z "$ac_cv_type_uintptr_t" && ac_cv_type_uintptr_t=no
test -z "$ac_cv_type_uint64_t" && ac_cv_type_uint64_t=no
test -z "$ac_cv_type_u_int64_t" && ac_cv_type_u_int64_t=no
test -z "$ac_cv_type_int_least32_t" && ac_cv_type_int_least32_t=no
test -z "$ac_cv_type_int_fast32_t" && ac_cv_type_int_fast32_t=no
AC_MSG_CHECKING([what to include in _GCC_STDINT_H])
case `AS_BASENAME(_GCC_STDINT_H)` in
stdint.h) AC_MSG_WARN([are you sure you want it there?]) ;;
inttypes.h) AC_MSG_WARN([are you sure you want it there?]) ;;
*) ;;
esac
AC_MSG_RESULT($acx_cv_header_stdint $acx_cv_header_stdint_kind)
case "$acx_cv_header_stdint:$ac_cv_type_uintptr_t" in
stddef.h:* | *:no) AC_CHECK_SIZEOF(void *) ;;
esac
case "$acx_cv_header_stdint:$ac_cv_type_uint64_t:$ac_cv_type_u_int64_t" in
stddef.h:*:* | *:no:no) AC_CHECK_SIZEOF(long) ;;
esac
if test $acx_cv_header_stdint = stddef.h; then
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(char)
AC_MSG_CHECKING(for type equivalent to int8_t)
case "$ac_cv_sizeof_char" in
1) acx_cv_type_int8_t=char ;;
*) AC_MSG_ERROR(no 8-bit type, please report a bug)
esac
AC_MSG_RESULT($acx_cv_type_int8_t)
AC_MSG_CHECKING(for type equivalent to int16_t)
case "$ac_cv_sizeof_int:$ac_cv_sizeof_short" in
2:*) acx_cv_type_int16_t=int ;;
*:2) acx_cv_type_int16_t=short ;;
*) AC_MSG_ERROR(no 16-bit type, please report a bug)
esac
AC_MSG_RESULT($acx_cv_type_int16_t)
AC_MSG_CHECKING(for type equivalent to int32_t)
case "$ac_cv_sizeof_int:$ac_cv_sizeof_long" in
4:*) acx_cv_type_int32_t=int ;;
*:4) acx_cv_type_int32_t=long ;;
*) AC_MSG_ERROR(no 32-bit type, please report a bug)
esac
AC_MSG_RESULT($acx_cv_type_int32_t)
fi
if test "$ac_cv_type_uint64_t" != yes && test "$ac_cv_type_u_int64_t" != yes; then
case "$ac_cv_sizeof_long" in
8) acx_cv_type_int64_t=long ;;
esac
AC_MSG_CHECKING(for type equivalent to int64_t)
AC_MSG_RESULT(${acx_cv_type_int64_t-'using preprocessor symbols'})
fi
if test "$ac_cv_type_uintptr_t" != yes; then
AC_MSG_CHECKING(for type equivalent to intptr_t)
case $ac_cv_sizeof_void_p in
2) acx_cv_type_intptr_t=int16_t ;;
4) acx_cv_type_intptr_t=int32_t ;;
8) acx_cv_type_intptr_t=int64_t ;;
*) AC_MSG_ERROR(no equivalent for intptr_t, please report a bug)
esac
AC_MSG_RESULT($acx_cv_type_intptr_t)
fi
AC_CONFIG_COMMANDS(_GCC_STDINT_H, [
if test "$GCC" = yes; then
echo "/* generated for " `$CC --version | sed 1q` "*/" > tmp-stdint.h
else
echo "/* generated for $CC */" > tmp-stdint.h
fi
sed 's/^ *//' >> tmp-stdint.h <<EOF
EOF
if test "$acx_cv_header_stdint" != stdint.h; then
echo "fi
if test "$acx_cv_header_stdint" != stddef.h; then
echo "fi
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* glibc uses these symbols as guards to prevent redefinitions. */
EOF
if test "$acx_cv_header_stdint" = stddef.h; then
sed 's/^ *//' >> tmp-stdint.h <<EOF
typedef unsigned $acx_cv_type_int8_t uint8_t;
typedef unsigned $acx_cv_type_int16_t uint16_t;
typedef unsigned $acx_cv_type_int32_t uint32_t;
typedef $acx_cv_type_int8_t int8_t;
typedef $acx_cv_type_int16_t int16_t;
typedef $acx_cv_type_int32_t int32_t;
EOF
elif test "$ac_cv_type_u_int32_t" = yes; then
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* int8_t int16_t int32_t defined by inet code, we do the u_intXX types */
typedef u_int8_t uint8_t;
typedef u_int16_t uint16_t;
typedef u_int32_t uint32_t;
EOF
else
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* Some systems have guard macros to prevent redefinitions, define them. */
EOF
fi
if test "$ac_cv_type_uint64_t" = yes; then
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* system headers have good uint64_t and int64_t */
EOF
elif test "$ac_cv_type_u_int64_t" = yes; then
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* system headers have an u_int64_t (and int64_t) */
typedef u_int64_t uint64_t;
EOF
elif test -n "$acx_cv_type_int64_t"; then
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* architecture has a 64-bit type, $acx_cv_type_int64_t */
typedef $acx_cv_type_int64_t int64_t;
typedef unsigned $acx_cv_type_int64_t uint64_t;
EOF
else
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* some common heuristics for int64_t, using compiler-specific tests */
typedef long long int64_t;
typedef unsigned long long uint64_t;
/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
does not implement __extension__. But that compiler doesn't define
__GNUC_MINOR__. */
__extension__ typedef long long int64_t;
__extension__ typedef unsigned long long uint64_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
EOF
fi
if test "$ac_cv_type_uintptr_t" != yes; then
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* Define intptr_t based on sizeof(void*) = $ac_cv_sizeof_void_p */
typedef u$acx_cv_type_intptr_t uintptr_t;
typedef $acx_cv_type_intptr_t intptr_t;
EOF
fi
if test "$ac_cv_type_int_least32_t" != yes; then
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* Define int_least types */
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
typedef int32_t int_least32_t;
typedef int64_t int_least64_t;
typedef uint8_t uint_least8_t;
typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
typedef uint64_t uint_least64_t;
EOF
fi
if test "$ac_cv_type_int_fast32_t" != yes; then
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* Define int_fast types. short is often slow */
typedef int8_t int_fast8_t;
typedef int int_fast16_t;
typedef int32_t int_fast32_t;
typedef int64_t int_fast64_t;
typedef uint8_t uint_fast8_t;
typedef unsigned int uint_fast16_t;
typedef uint32_t uint_fast32_t;
typedef uint64_t uint_fast64_t;
EOF
fi
if test "$ac_cv_type_uintmax_t" != yes; then
sed 's/^ *//' >> tmp-stdint.h <<EOF
/* Define intmax based on what we found */
typedef int64_t intmax_t;
typedef long intmax_t;
typedef uint64_t uintmax_t;
typedef unsigned long uintmax_t;
EOF
fi
sed 's/^ *//' >> tmp-stdint.h <<EOF
EOF
if test -r ]_GCC_STDINT_H[ && cmp -s tmp-stdint.h ]_GCC_STDINT_H[; then
rm -f tmp-stdint.h
else
mv -f tmp-stdint.h ]_GCC_STDINT_H[
fi
], [
GCC="$GCC"
CC="$CC"
acx_cv_header_stdint="$acx_cv_header_stdint"
acx_cv_type_int8_t="$acx_cv_type_int8_t"
acx_cv_type_int16_t="$acx_cv_type_int16_t"
acx_cv_type_int32_t="$acx_cv_type_int32_t"
acx_cv_type_int64_t="$acx_cv_type_int64_t"
acx_cv_type_intptr_t="$acx_cv_type_intptr_t"
ac_cv_type_uintmax_t="$ac_cv_type_uintmax_t"
ac_cv_type_uintptr_t="$ac_cv_type_uintptr_t"
ac_cv_type_uint64_t="$ac_cv_type_uint64_t"
ac_cv_type_u_int64_t="$ac_cv_type_u_int64_t"
ac_cv_type_u_int32_t="$ac_cv_type_u_int32_t"
ac_cv_type_int_least32_t="$ac_cv_type_int_least32_t"
ac_cv_type_int_fast32_t="$ac_cv_type_int_fast32_t"
ac_cv_sizeof_void_p="$ac_cv_sizeof_void_p"
])
])