An autoconf macro for its associated module.
[gnulib.git] / m4 / intmax_t.m4
1 # intmax_t.m4 serial 1
2 dnl Copyright (C) 1997-2002 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License.  As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 dnl From Paul Eggert.
10
11 AC_PREREQ(2.13)
12
13 # Define intmax_t to 'long' or 'long long'
14 # if it is not already defined in <stdint.h> or <inttypes.h>.
15
16 AC_DEFUN([jm_AC_TYPE_INTMAX_T],
17 [
18   dnl For simplicity, we assume that a header file defines 'intmax_t' if and
19   dnl only if it defines 'uintmax_t'.
20   AC_REQUIRE([jm_AC_HEADER_INTTYPES_H])
21   AC_REQUIRE([jm_AC_HEADER_STDINT_H])
22   if test $jm_ac_cv_header_inttypes_h = no && test $jm_ac_cv_header_stdint_h = no; then
23     AC_REQUIRE([jm_AC_TYPE_LONG_LONG])
24     test $ac_cv_type_long_long = yes \
25       && ac_type='long long' \
26       || ac_type='long'
27     AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
28      [Define to long or long long if <inttypes.h> and <stdint.h> don't define.])
29   else
30     AC_DEFINE(HAVE_INTMAX_T, 1,
31       [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
32   fi
33 ])
34
35 dnl An alternative would be to explicitly test for 'intmax_t'.
36
37 AC_DEFUN([gt_AC_TYPE_INTMAX_T],
38 [
39   AC_REQUIRE([jm_AC_HEADER_INTTYPES_H])
40   AC_REQUIRE([jm_AC_HEADER_STDINT_H])
41   AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t,
42     [AC_TRY_COMPILE([
43 #include <stddef.h> 
44 #include <stdlib.h>
45 #if HAVE_STDINT_H_WITH_UINTMAX
46 #include <stdint.h>
47 #endif
48 #if HAVE_INTTYPES_H_WITH_UINTMAX
49 #include <inttypes.h>
50 #endif
51 ], [intmax_t x = -1;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)])
52   if test $gt_cv_c_intmax_t = yes; then
53     AC_DEFINE(HAVE_INTMAX_T, 1,
54       [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.])
55   else
56     AC_REQUIRE([jm_AC_TYPE_LONG_LONG])
57     test $ac_cv_type_long_long = yes \
58       && ac_type='long long' \
59       || ac_type='long'
60     AC_DEFINE_UNQUOTED(intmax_t, $ac_type,
61      [Define to long or long long if <stdint.h> and <inttypes.h> don't define.])
62   fi
63 ])