Tizen 2.0 Release
[external/tizen-coreutils.git] / m4 / inttypes.m4
1 # inttypes.m4 serial 8
2 dnl Copyright (C) 2006-2007 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Derek Price, Bruno Haible.
8 dnl Test whether <inttypes.h> is supported or must be substituted.
9
10 AC_DEFUN([gl_INTTYPES_H],
11 [
12   AC_REQUIRE([gl_STDINT_H])
13   AC_REQUIRE([gt_INTTYPES_PRI])
14   AC_CHECK_DECLS_ONCE([imaxabs])
15   AC_CHECK_DECLS_ONCE([imaxdiv])
16   AC_CHECK_DECLS_ONCE([strtoimax])
17   AC_CHECK_DECLS_ONCE([strtoumax])
18
19   dnl Now see if we need a substitute <inttypes.h>.
20   dnl A complete <inttypes.h> requires
21   dnl   - a complete <stdint.h>,
22   dnl   - the existence of an <inttypes.h>,
23   dnl   - that imaxabs, imaxdiv, strtoimax, strtoumax are declared,
24   dnl   - some additional tests.
25   AC_CACHE_CHECK([whether inttypes.h conforms to C99],
26     [gl_cv_header_working_inttypes_h],
27     [gl_cv_header_working_inttypes_h=no
28      if test "$gl_cv_header_working_stdint_h" = yes \
29         && test $ac_cv_header_inttypes_h = yes \
30         && test "$ac_cv_have_decl_imaxabs" = yes \
31         && test "$ac_cv_have_decl_imaxdiv" = yes \
32         && test "$ac_cv_have_decl_strtoimax" = yes \
33         && test "$ac_cv_have_decl_strtoumax" = yes; then
34        AC_COMPILE_IFELSE([
35          AC_LANG_PROGRAM([
36 #include <stddef.h>
37 #define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
38 #define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */
39 #define __STDC_FORMAT_MACROS 1 /* to make it work also in C++ mode */
40 #include ABSOLUTE_INTTYPES_H
41
42 /* No need to duplicate the tests of stdint.m4; they are subsumed by
43    $gl_cv_header_working_stdint_h = yes.  */
44
45 /* Tests for macros supposed to be defined in inttypes.h.  */
46
47 const char *k = /* implicit string concatenation */
48 #ifdef INT8_MAX
49   PRId8 PRIi8
50 #endif
51 #ifdef UINT8_MAX
52   PRIo8 PRIu8 PRIx8 PRIX8
53 #endif
54 #ifdef INT16_MAX
55   PRId16 PRIi16
56 #endif
57 #ifdef UINT16_MAX
58   PRIo16 PRIu16 PRIx16 PRIX16
59 #endif
60 #ifdef INT32_MAX
61   PRId32 PRIi32
62 #endif
63 #ifdef UINT32_MAX
64   PRIo32 PRIu32 PRIx32 PRIX32
65 #endif
66 #ifdef INT64_MAX
67   PRId64 PRIi64
68 #endif
69 #ifdef UINT64_MAX
70   PRIo64 PRIu64 PRIx64 PRIX64
71 #endif
72   PRIdLEAST8 PRIiLEAST8 PRIoLEAST8 PRIuLEAST8 PRIxLEAST8 PRIXLEAST8
73   PRIdLEAST16 PRIiLEAST16 PRIoLEAST16 PRIuLEAST16 PRIxLEAST16 PRIXLEAST16
74   PRIdLEAST32 PRIiLEAST32 PRIoLEAST32 PRIuLEAST32 PRIxLEAST32 PRIXLEAST32
75   PRIdLEAST64 PRIiLEAST64
76   PRIoLEAST64 PRIuLEAST64 PRIxLEAST64 PRIXLEAST64
77   PRIdFAST8 PRIiFAST8 PRIoFAST8 PRIuFAST8 PRIxFAST8 PRIXFAST8
78   PRIdFAST16 PRIiFAST16 PRIoFAST16 PRIuFAST16 PRIxFAST16 PRIXFAST16
79   PRIdFAST32 PRIiFAST32 PRIoFAST32 PRIuFAST32 PRIxFAST32 PRIXFAST32
80   PRIdFAST64 PRIiFAST64
81   PRIoFAST64 PRIuFAST64 PRIxFAST64 PRIXFAST64
82   PRIdMAX PRIiMAX PRIoMAX PRIuMAX PRIxMAX PRIXMAX
83 #ifdef INTPTR_MAX
84   PRIdPTR PRIiPTR
85 #endif
86 #ifdef UINTPTR_MAX
87   PRIoPTR PRIuPTR PRIxPTR PRIXPTR
88 #endif
89   ;
90 const char *l = /* implicit string concatenation */
91 #ifdef INT8_MAX
92   SCNd8 SCNi8
93 #endif
94 #ifdef UINT8_MAX
95   SCNo8 SCNu8 SCNx8
96 #endif
97 #ifdef INT16_MAX
98   SCNd16 SCNi16
99 #endif
100 #ifdef UINT16_MAX
101   SCNo16 SCNu16 SCNx16
102 #endif
103 #ifdef INT32_MAX
104   SCNd32 SCNi32
105 #endif
106 #ifdef UINT32_MAX
107   SCNo32 SCNu32 SCNx32
108 #endif
109 #ifdef INT64_MAX
110   SCNd64 SCNi64
111 #endif
112 #ifdef UINT64_MAX
113   SCNo64 SCNu64 SCNx64
114 #endif
115   SCNdLEAST8 SCNiLEAST8 SCNoLEAST8 SCNuLEAST8 SCNxLEAST8
116   SCNdLEAST16 SCNiLEAST16 SCNoLEAST16 SCNuLEAST16 SCNxLEAST16
117   SCNdLEAST32 SCNiLEAST32 SCNoLEAST32 SCNuLEAST32 SCNxLEAST32
118   SCNdLEAST64 SCNiLEAST64
119   SCNoLEAST64 SCNuLEAST64 SCNxLEAST64
120   SCNdFAST8 SCNiFAST8 SCNoFAST8 SCNuFAST8 SCNxFAST8
121   SCNdFAST16 SCNiFAST16 SCNoFAST16 SCNuFAST16 SCNxFAST16
122   SCNdFAST32 SCNiFAST32 SCNoFAST32 SCNuFAST32 SCNxFAST32
123   SCNdFAST64 SCNiFAST64
124   SCNoFAST64 SCNuFAST64 SCNxFAST64
125   SCNdMAX SCNiMAX SCNoMAX SCNuMAX SCNxMAX
126 #ifdef INTPTR_MAX
127   SCNdPTR SCNiPTR
128 #endif
129 #ifdef UINTPTR_MAX
130   SCNoPTR SCNuPTR SCNxPTR
131 #endif
132   ;
133          ])],
134          [gl_cv_header_working_inttypes_h=yes])
135      fi])
136
137   dnl Override <inttypes.h> always, so that the portability warnings work.
138   if false && test $gl_cv_header_working_inttypes_h = yes; then
139     dnl Use the existing <inttypes.h>.
140     INTTYPES_H=''
141   else
142
143     AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
144     dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h.
145     if test $ac_cv_header_inttypes_h = yes; then
146       gl_ABSOLUTE_HEADER([inttypes.h])
147       ABSOLUTE_INTTYPES_H=\"$gl_cv_absolute_inttypes_h\"
148     else
149       ABSOLUTE_INTTYPES_H=\"no/such/file/inttypes.h\"
150     fi
151     AC_SUBST([ABSOLUTE_INTTYPES_H])
152
153     PRIPTR_PREFIX=
154     if test -n "$STDINT_H"; then
155       dnl Using the gnulib <stdint.h>. It always defines intptr_t to 'long'.
156       PRIPTR_PREFIX='"l"'
157     else
158       dnl Using the system's <stdint.h>.
159       for glpfx in '' l ll I64; do
160         case $glpfx in
161           '')  gltype1='int';;
162           l)   gltype1='long int';;
163           ll)  gltype1='long long int';;
164           I64) gltype1='__int64';;
165         esac
166         AC_COMPILE_IFELSE(
167           [AC_LANG_PROGRAM([#include <stdint.h>
168              extern intptr_t foo;
169              extern $gltype1 foo;])],
170           [PRIPTR_PREFIX='"'$glpfx'"'])
171         test -n "$PRIPTR_PREFIX" && break
172       done
173     fi
174     AC_SUBST([PRIPTR_PREFIX])
175
176     if test "$ac_cv_have_decl_imaxabs" = yes; then
177       HAVE_DECL_IMAXABS=1
178     else
179       HAVE_DECL_IMAXABS=0
180     fi
181
182     if test "$ac_cv_have_decl_imaxdiv" = yes; then
183       HAVE_DECL_IMAXDIV=1
184     else
185       HAVE_DECL_IMAXDIV=0
186     fi
187
188     if test "$ac_cv_have_decl_strtoimax" = yes; then
189       HAVE_DECL_STRTOIMAX=1
190     else
191       HAVE_DECL_STRTOIMAX=0
192     fi
193
194     if test "$ac_cv_have_decl_strtoumax" = yes; then
195       HAVE_DECL_STRTOUMAX=1
196     else
197       HAVE_DECL_STRTOUMAX=0
198     fi
199
200     INTTYPES_H='inttypes.h'
201   fi
202   AC_SUBST(INTTYPES_H)
203 ])
204
205 AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
206 [
207   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
208   AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
209   GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
210 ])
211
212 AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
213 [
214   GNULIB_IMAXABS=0;      AC_SUBST([GNULIB_IMAXABS])
215   GNULIB_IMAXDIV=0;      AC_SUBST([GNULIB_IMAXDIV])
216   GNULIB_STRTOIMAX=0;    AC_SUBST([GNULIB_STRTOIMAX])
217   GNULIB_STRTOUMAX=0;    AC_SUBST([GNULIB_STRTOUMAX])
218   dnl Assume proper GNU behavior unless another module says otherwise.
219   HAVE_DECL_IMAXABS=1;   AC_SUBST([HAVE_DECL_IMAXABS])
220   HAVE_DECL_IMAXDIV=1;   AC_SUBST([HAVE_DECL_IMAXDIV])
221   HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
222   HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])
223 ])