resync with xstrtoumax.m4
[gnulib.git] / m4 / xstrtoimax.m4
1 #serial 1
2 dnl Cloned from xstrtoumax.m4.  Keep these files in sync.
3
4 # autoconf tests required for use of xstrtoimax.c
5
6 AC_DEFUN([jm_AC_PREREQ_XSTRTOIMAX],
7 [
8   AC_REQUIRE([jm_AC_TYPE_INTMAX_T])
9   AC_REQUIRE([jm_AC_HEADER_INTTYPES_H])
10   AC_REQUIRE([jm_AC_TYPE_LONG_LONG])
11   AC_CHECK_DECLS([strtol, strtoll])
12   AC_CHECK_HEADERS(limits.h stdlib.h)
13
14   AC_CACHE_CHECK([whether <inttypes.h> defines strtoimax as a macro],
15     jm_cv_func_strtoimax_macro,
16     AC_EGREP_CPP([inttypes_h_defines_strtoimax], [#include <inttypes.h>
17 #ifdef strtoimax
18  inttypes_h_defines_strtoimax
19 #endif],
20       jm_cv_func_strtoimax_macro=yes,
21       jm_cv_func_strtoimax_macro=no))
22
23   if test "$jm_cv_func_strtoimax_macro" != yes; then
24     AC_REPLACE_FUNCS(strtoimax)
25   fi
26
27   dnl We don't need (and can't compile) the replacement strtoll
28   dnl unless the type `long long' exists.
29   dnl Also, only the replacement strtoimax invokes strtoll,
30   dnl so we need the replacement strtoll only if strtoimax does not exist.
31   case "$ac_cv_type_long_long,$jm_cv_func_strtoimax_macro,$ac_cv_func_strtoimax" in
32     yes,no,no)
33       AC_REPLACE_FUNCS(strtoll)
34
35       dnl Check for strtol.  Mainly as a cue to cause automake to include
36       dnl strtol.c -- that file is included by each of strtoul.c and strtoull.c.
37       AC_REPLACE_FUNCS(strtol)
38       ;;
39   esac
40
41   case "$jm_cv_func_strtoimax_macro,$ac_cv_func_strtoimax" in
42     no,no)
43       AC_REPLACE_FUNCS(strtoul)
44
45       dnl See explanation above.
46       AC_REPLACE_FUNCS(strtol)
47       ;;
48   esac
49
50 ])