Add AC_PREREQ(2.13).
[gnulib.git] / m4 / inttypes.m4
1 #serial 6
2
3 dnl From Paul Eggert.
4
5 AC_PREREQ(2.13)
6
7 # Define HAVE_INTTYPES_H if <inttypes.h> exists,
8 # doesn't clash with <sys/types.h>, and declares intmax_t and uintmax_t.
9
10 AC_DEFUN([jm_AC_HEADER_INTTYPES_H],
11 [
12   AC_CACHE_CHECK([for inttypes.h], jm_ac_cv_header_inttypes_h,
13   [AC_TRY_COMPILE(
14     [#include <sys/types.h>
15 #include <inttypes.h>],
16     [intmax_t i = (intmax_t) -1; uintmax_t ui = (uintmax_t) -1;],
17     jm_ac_cv_header_inttypes_h=yes,
18     jm_ac_cv_header_inttypes_h=no)])
19   if test $jm_ac_cv_header_inttypes_h = yes; then
20     AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H, 1,
21 [Define if <inttypes.h> exists, doesn't clash with <sys/types.h>,
22    and declares intmax_t and uintmax_t.])
23   fi
24 ])
25
26 # Define intmax_t to long or long long if <inttypes.h> doesn't define.
27
28 AC_DEFUN([jm_AC_TYPE_INTMAX_T],
29 [
30   AC_REQUIRE([jm_AC_HEADER_INTTYPES_H])
31   if test $jm_ac_cv_header_inttypes_h = no; then
32     AC_REQUIRE([jm_AC_TYPE_LONG_LONG])
33     test $ac_cv_type_long_long = yes \
34       && ac_type='long long' \
35       || ac_type='long'
36     AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
37       [Define to long or long long if <inttypes.h> doesn't define.])
38   fi
39 ])
40
41 # Define uintmax_t to unsigned long or unsigned long long
42 # if <inttypes.h> doesn't define.
43
44 AC_DEFUN([jm_AC_TYPE_UINTMAX_T],
45 [
46   AC_REQUIRE([jm_AC_HEADER_INTTYPES_H])
47   if test $jm_ac_cv_header_inttypes_h = no; then
48     AC_REQUIRE([jm_AC_TYPE_UNSIGNED_LONG_LONG])
49     test $ac_cv_type_unsigned_long_long = yes \
50       && ac_type='unsigned long long' \
51       || ac_type='unsigned long'
52     AC_DEFINE_UNQUOTED(uintmax_t, $ac_type,
53 [Define to unsigned long or unsigned long long
54    if <inttypes.h> doesn't define.])
55   fi
56 ])