+[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,[#include <sys/types.h>
+#include <$i>])
+ AC_CHECK_TYPE(uintptr_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
+#include <$i>])
+ AC_CHECK_TYPE(int_least32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
+#include <$i>])
+ AC_CHECK_TYPE(int_fast32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
+#include <$i>])
+ AC_CHECK_TYPE(uint64_t,,[acx_cv_header_stdint_kind="(lacks uint64_t)"], [#include <sys/types.h>
+#include <$i>])
+ 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,[#include <sys/types.h>
+#include <$i>])
+ AC_CHECK_TYPE(uint64_t,,,[#include <sys/types.h>
+#include <$i>])
+ AC_CHECK_TYPE(uintptr_t,,,[#include <sys/types.h>
+#include <$i>])
+ 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,[#include <sys/types.h>
+#include <$i>])
+ AC_CHECK_TYPE(u_int64_t,,,[#include <sys/types.h>
+#include <$i>])
+ 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
+
+# ----------------- Summarize what we found so far
+
+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)
+
+# ----------------- done included file, check C basic types --------
+
+# Lacking an uintptr_t? Test size of void *
+case "$acx_cv_header_stdint:$ac_cv_type_uintptr_t" in
+ stddef.h:* | *:no) AC_CHECK_SIZEOF(void *) ;;
+esac
+
+# Lacking an uint64_t? Test size of long
+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
+ # Lacking a good header? Test size of everything and deduce all types.
+ 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
+
+# These tests are here to make the output prettier