New module 'stdint'.
[gnulib.git] / m4 / stdint.m4
1 # stdint.m4 serial 2
2 dnl Copyright (C) 2001-2002, 2004 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 Bruno Haible.
10 dnl Test whether <stdint.h> is supported or must be substituted.
11
12 AC_DEFUN([gl_STDINT_H],
13 [dnl Check for <inttypes.h>.
14 AC_REQUIRE([gt_HEADER_INTTYPES_H])
15 dnl Check for <sys/inttypes.h>.
16 AC_CHECK_HEADERS([sys/inttypes.h])
17
18 AC_MSG_CHECKING([for stdint.h])
19 AC_CACHE_VAL(gl_cv_header_stdint_h, [
20   AC_TRY_COMPILE([#include <stdint.h>], [],
21     gl_cv_header_stdint_h=yes, gl_cv_header_stdint_h=no)])
22 AC_MSG_RESULT([$gl_cv_header_stdint_h])
23 if test $gl_cv_header_stdint_h = yes; then
24   AC_DEFINE(HAVE_STDINT_H, 1,
25             [Define if you have a working <stdint.h> header file.])
26   STDINT_H=''
27 else
28   STDINT_H='stdint.h'
29
30   dnl Is long == int64_t ?
31   AC_CACHE_CHECK([whether 'long' is 64 bit wide], gl_cv_long_bitsize_64, [
32     AC_TRY_COMPILE([
33 #define POW63  ((((((long) 1 << 15) << 15) << 15) << 15) << 3)
34 #define POW64  ((((((long) 1 << 15) << 15) << 15) << 15) << 4)
35 typedef int array [2 * (POW63 != 0 && POW64 == 0) - 1];
36 ], , gl_cv_long_bitsize_64=yes, gl_cv_long_bitsize_64=no)])
37   if test $gl_cv_long_bitsize_64 = yes; then
38     HAVE_LONG_64BIT=1
39   else
40     HAVE_LONG_64BIT=0
41   fi
42   AC_SUBST(HAVE_LONG_64BIT)
43
44   dnl Is long long == int64_t ?
45   AC_CACHE_CHECK([whether 'long long' is 64 bit wide], gl_cv_longlong_bitsize_64, [
46     AC_TRY_COMPILE([
47 #define POW63  ((((((long long) 1 << 15) << 15) << 15) << 15) << 3)
48 #define POW64  ((((((long long) 1 << 15) << 15) << 15) << 15) << 4)
49 typedef int array [2 * (POW63 != 0 && POW64 == 0) - 1];
50 ], , gl_cv_longlong_bitsize_64=yes, gl_cv_longlong_bitsize_64=no)])
51   if test $gl_cv_longlong_bitsize_64 = yes; then
52     HAVE_LONGLONG_64BIT=1
53   else
54     HAVE_LONGLONG_64BIT=0
55   fi
56   AC_SUBST(HAVE_LONGLONG_64BIT)
57
58 fi
59 AC_SUBST(STDINT_H)
60 ])