Sync from gcc mainline.
[deliverable/binutils-gdb.git] / config / stdint.m4
CommitLineData
07c58694
PB
1AC_DEFUN([GCC_STDINT_TYPES],
2[AC_REQUIRE([AC_TYPE_INT8_T])
3AC_REQUIRE([AC_TYPE_INT16_T])
4AC_REQUIRE([AC_TYPE_INT32_T])
5AC_REQUIRE([AC_TYPE_INT64_T])
6AC_REQUIRE([AC_TYPE_INTMAX_T])
7AC_REQUIRE([AC_TYPE_INTPTR_T])
8AC_REQUIRE([AC_TYPE_UINT8_T])
9AC_REQUIRE([AC_TYPE_UINT16_T])
10AC_REQUIRE([AC_TYPE_UINT32_T])
11AC_REQUIRE([AC_TYPE_UINT64_T])
12AC_REQUIRE([AC_TYPE_UINTMAX_T])
13AC_REQUIRE([AC_TYPE_UINTPTR_T])])
8eb2f3f0 14
f3b4f6d0
PB
15dnl @synopsis GCC_HEADER_STDINT [( HEADER-TO-GENERATE [, HEADERS-TO-CHECK])]
16dnl
17dnl the "ISO C9X: 7.18 Integer types <stdint.h>" section requires the
18dnl existence of an include file <stdint.h> that defines a set of
19dnl typedefs, especially uint8_t,int32_t,uintptr_t.
20dnl Many older installations will not provide this file, but some will
21dnl have the very same definitions in <inttypes.h>. In other enviroments
22dnl we can use the inet-types in <sys/types.h> which would define the
23dnl typedefs int8_t and u_int8_t respectivly.
24dnl
25dnl This macros will create a local "_stdint.h" or the headerfile given as
26dnl an argument. In many cases that file will pick the definition from a
27dnl "#include <stdint.h>" or "#include <inttypes.h>" statement, while
28dnl in other environments it will provide the set of basic 'stdint's defined:
29dnl int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,intptr_t,uintptr_t
30dnl int_least32_t.. int_fast32_t.. intmax_t
31dnl which may or may not rely on the definitions of other files.
32dnl
33dnl Sometimes the stdint.h or inttypes.h headers conflict with sys/types.h,
34dnl so we test the headers together with sys/types.h and always include it
35dnl into the generated header (to match the tests with the generated file).
36dnl Hopefully this is not a big annoyance.
37dnl
38dnl If your installed header files require the stdint-types you will want to
39dnl create an installable file mylib-int.h that all your other installable
40dnl header may include. So, for a library package named "mylib", just use
41dnl GCC_HEADER_STDINT(mylib-int.h)
42dnl in configure.in and install that header file in Makefile.am along with
43dnl the other headers (mylib.h). The mylib-specific headers can simply
44dnl use "#include <mylib-int.h>" to obtain the stdint-types.
45dnl
46dnl Remember, if the system already had a valid <stdint.h>, the generated
47dnl file will include it directly. No need for fuzzy HAVE_STDINT_H things...
48dnl
49dnl @author Guido Draheim <guidod@gmx.de>, Paolo Bonzini <bonzini@gnu.org>
50
8eb2f3f0 51AC_DEFUN([GCC_HEADER_STDINT],
f3b4f6d0
PB
52[m4_define(_GCC_STDINT_H, m4_ifval($1, $1, _stdint.h))
53
54inttype_headers=`echo inttypes.h sys/inttypes.h $2 | sed -e 's/,/ /g'`
55
56acx_cv_header_stdint=stddef.h
57acx_cv_header_stdint_kind="(already complete)"
58for i in stdint.h $inttype_headers; do
59 unset ac_cv_type_uintptr_t
60 unset ac_cv_type_uintmax_t
61 unset ac_cv_type_int_least32_t
62 unset ac_cv_type_int_fast32_t
63 unset ac_cv_type_uint64_t
64 _AS_ECHO_N([looking for a compliant stdint.h in $i, ])
65 AC_CHECK_TYPE(uintmax_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h>
66#include <$i>])
67 AC_CHECK_TYPE(uintptr_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
68#include <$i>])
69 AC_CHECK_TYPE(int_least32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
70#include <$i>])
71 AC_CHECK_TYPE(int_fast32_t,,[acx_cv_header_stdint_kind="(mostly complete)"], [#include <sys/types.h>
72#include <$i>])
73 AC_CHECK_TYPE(uint64_t,,[acx_cv_header_stdint_kind="(lacks uint64_t)"], [#include <sys/types.h>
74#include <$i>])
75 break
76done
77if test "$acx_cv_header_stdint" = stddef.h; then
78 acx_cv_header_stdint_kind="(lacks uintmax_t)"
79 for i in stdint.h $inttype_headers; do
80 unset ac_cv_type_uintptr_t
81 unset ac_cv_type_uint32_t
82 unset ac_cv_type_uint64_t
83 _AS_ECHO_N([looking for an incomplete stdint.h in $i, ])
84 AC_CHECK_TYPE(uint32_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h>
85#include <$i>])
86 AC_CHECK_TYPE(uint64_t,,,[#include <sys/types.h>
87#include <$i>])
88 AC_CHECK_TYPE(uintptr_t,,,[#include <sys/types.h>
89#include <$i>])
90 break
91 done
92fi
93if test "$acx_cv_header_stdint" = stddef.h; then
94 acx_cv_header_stdint_kind="(u_intXX_t style)"
95 for i in sys/types.h $inttype_headers; do
96 unset ac_cv_type_u_int32_t
97 unset ac_cv_type_u_int64_t
98 _AS_ECHO_N([looking for u_intXX_t types in $i, ])
99 AC_CHECK_TYPE(u_int32_t,[acx_cv_header_stdint=$i],continue,[#include <sys/types.h>
100#include <$i>])
101 AC_CHECK_TYPE(u_int64_t,,,[#include <sys/types.h>
102#include <$i>])
103 break
104 done
105fi
106if test "$acx_cv_header_stdint" = stddef.h; then
107 acx_cv_header_stdint_kind="(using manual detection)"
108fi
109
110test -z "$ac_cv_type_uintptr_t" && ac_cv_type_uintptr_t=no
111test -z "$ac_cv_type_uint64_t" && ac_cv_type_uint64_t=no
112test -z "$ac_cv_type_u_int64_t" && ac_cv_type_u_int64_t=no
113test -z "$ac_cv_type_int_least32_t" && ac_cv_type_int_least32_t=no
114test -z "$ac_cv_type_int_fast32_t" && ac_cv_type_int_fast32_t=no
115
116# ----------------- Summarize what we found so far
117
118AC_MSG_CHECKING([what to include in _GCC_STDINT_H])
119
120case `AS_BASENAME(_GCC_STDINT_H)` in
121 stdint.h) AC_MSG_WARN([are you sure you want it there?]) ;;
122 inttypes.h) AC_MSG_WARN([are you sure you want it there?]) ;;
123 *) ;;
124esac
125
126AC_MSG_RESULT($acx_cv_header_stdint $acx_cv_header_stdint_kind)
127
128# ----------------- done included file, check C basic types --------
129
130# Lacking an uintptr_t? Test size of void *
131case "$acx_cv_header_stdint:$ac_cv_type_uintptr_t" in
132 stddef.h:* | *:no) AC_CHECK_SIZEOF(void *) ;;
133esac
134
135# Lacking an uint64_t? Test size of long
136case "$acx_cv_header_stdint:$ac_cv_type_uint64_t:$ac_cv_type_u_int64_t" in
137 stddef.h:*:* | *:no:no) AC_CHECK_SIZEOF(long) ;;
138esac
139
140if test $acx_cv_header_stdint = stddef.h; then
141 # Lacking a good header? Test size of everything and deduce all types.
142 AC_CHECK_SIZEOF(int)
143 AC_CHECK_SIZEOF(short)
144 AC_CHECK_SIZEOF(char)
145
146 AC_MSG_CHECKING(for type equivalent to int8_t)
147 case "$ac_cv_sizeof_char" in
148 1) acx_cv_type_int8_t=char ;;
149 *) AC_MSG_ERROR(no 8-bit type, please report a bug)
150 esac
151 AC_MSG_RESULT($acx_cv_type_int8_t)
152
153 AC_MSG_CHECKING(for type equivalent to int16_t)
154 case "$ac_cv_sizeof_int:$ac_cv_sizeof_short" in
155 2:*) acx_cv_type_int16_t=int ;;
156 *:2) acx_cv_type_int16_t=short ;;
157 *) AC_MSG_ERROR(no 16-bit type, please report a bug)
158 esac
159 AC_MSG_RESULT($acx_cv_type_int16_t)
160
161 AC_MSG_CHECKING(for type equivalent to int32_t)
162 case "$ac_cv_sizeof_int:$ac_cv_sizeof_long" in
163 4:*) acx_cv_type_int32_t=int ;;
164 *:4) acx_cv_type_int32_t=long ;;
165 *) AC_MSG_ERROR(no 32-bit type, please report a bug)
166 esac
167 AC_MSG_RESULT($acx_cv_type_int32_t)
168fi
169
170# These tests are here to make the output prettier
8eb2f3f0 171
f3b4f6d0
PB
172if test "$ac_cv_type_uint64_t" != yes && test "$ac_cv_type_u_int64_t" != yes; then
173 case "$ac_cv_sizeof_long" in
174 8) acx_cv_type_int64_t=long ;;
175 esac
176 AC_MSG_CHECKING(for type equivalent to int64_t)
177 AC_MSG_RESULT(${acx_cv_type_int64_t-'using preprocessor symbols'})
178fi
179
180# Now we can use the above types
181
182if test "$ac_cv_type_uintptr_t" != yes; then
183 AC_MSG_CHECKING(for type equivalent to intptr_t)
184 case $ac_cv_sizeof_void_p in
185 2) acx_cv_type_intptr_t=int16_t ;;
186 4) acx_cv_type_intptr_t=int32_t ;;
187 8) acx_cv_type_intptr_t=int64_t ;;
188 *) AC_MSG_ERROR(no equivalent for intptr_t, please report a bug)
189 esac
190 AC_MSG_RESULT($acx_cv_type_intptr_t)
191fi
192
193# ----------------- done all checks, emit header -------------
8eb2f3f0 194AC_CONFIG_COMMANDS(_GCC_STDINT_H, [
f3b4f6d0
PB
195if test "$GCC" = yes; then
196 echo "/* generated for " `$CC --version | sed 1q` "*/" > tmp-stdint.h
197else
198 echo "/* generated for $CC */" > tmp-stdint.h
199fi
200
201sed 's/^ *//' >> tmp-stdint.h <<EOF
202
203 #ifndef GCC_GENERATED_STDINT_H
204 #define GCC_GENERATED_STDINT_H 1
205
206 #include <sys/types.h>
8eb2f3f0 207EOF
8eb2f3f0 208
f3b4f6d0
PB
209if test "$acx_cv_header_stdint" != stdint.h; then
210 echo "#include <stddef.h>" >> tmp-stdint.h
211fi
212if test "$acx_cv_header_stdint" != stddef.h; then
213 echo "#include <$acx_cv_header_stdint>" >> tmp-stdint.h
214fi
215
216sed 's/^ *//' >> tmp-stdint.h <<EOF
217 /* glibc uses these symbols as guards to prevent redefinitions. */
218 #ifdef __int8_t_defined
219 #define _INT8_T
220 #define _INT16_T
221 #define _INT32_T
222 #endif
223 #ifdef __uint32_t_defined
224 #define _UINT32_T
225 #endif
226
227EOF
228
229# ----------------- done header, emit basic int types -------------
230if test "$acx_cv_header_stdint" = stddef.h; then
231 sed 's/^ *//' >> tmp-stdint.h <<EOF
232
233 #ifndef _UINT8_T
234 #define _UINT8_T
235 #ifndef __uint8_t_defined
236 #define __uint8_t_defined
237 typedef unsigned $acx_cv_type_int8_t uint8_t;
238 #endif
239 #endif
240
241 #ifndef _UINT16_T
242 #define _UINT16_T
243 #ifndef __uint16_t_defined
244 #define __uint16_t_defined
245 typedef unsigned $acx_cv_type_int16_t uint16_t;
246 #endif
247 #endif
248
249 #ifndef _UINT32_T
250 #define _UINT32_T
251 #ifndef __uint32_t_defined
252 #define __uint32_t_defined
253 typedef unsigned $acx_cv_type_int32_t uint32_t;
254 #endif
255 #endif
256
257 #ifndef _INT8_T
258 #define _INT8_T
259 #ifndef __int8_t_defined
260 #define __int8_t_defined
261 typedef $acx_cv_type_int8_t int8_t;
262 #endif
263 #endif
264
265 #ifndef _INT16_T
266 #define _INT16_T
267 #ifndef __int16_t_defined
268 #define __int16_t_defined
269 typedef $acx_cv_type_int16_t int16_t;
270 #endif
271 #endif
272
273 #ifndef _INT32_T
274 #define _INT32_T
275 #ifndef __int32_t_defined
276 #define __int32_t_defined
277 typedef $acx_cv_type_int32_t int32_t;
278 #endif
279 #endif
280EOF
281elif test "$ac_cv_type_u_int32_t" = yes; then
282 sed 's/^ *//' >> tmp-stdint.h <<EOF
283
284 /* int8_t int16_t int32_t defined by inet code, we do the u_intXX types */
285 #ifndef _INT8_T
286 #define _INT8_T
287 #endif
288 #ifndef _INT16_T
289 #define _INT16_T
290 #endif
291 #ifndef _INT32_T
292 #define _INT32_T
293 #endif
294
295 #ifndef _UINT8_T
296 #define _UINT8_T
297 #ifndef __uint8_t_defined
298 #define __uint8_t_defined
299 typedef u_int8_t uint8_t;
300 #endif
301 #endif
302
303 #ifndef _UINT16_T
304 #define _UINT16_T
305 #ifndef __uint16_t_defined
306 #define __uint16_t_defined
307 typedef u_int16_t uint16_t;
308 #endif
309 #endif
310
311 #ifndef _UINT32_T
312 #define _UINT32_T
313 #ifndef __uint32_t_defined
314 #define __uint32_t_defined
315 typedef u_int32_t uint32_t;
316 #endif
317 #endif
318EOF
319else
320 sed 's/^ *//' >> tmp-stdint.h <<EOF
321
322 /* Some systems have guard macros to prevent redefinitions, define them. */
323 #ifndef _INT8_T
324 #define _INT8_T
325 #endif
326 #ifndef _INT16_T
327 #define _INT16_T
328 #endif
329 #ifndef _INT32_T
330 #define _INT32_T
331 #endif
332 #ifndef _UINT8_T
333 #define _UINT8_T
334 #endif
335 #ifndef _UINT16_T
336 #define _UINT16_T
337 #endif
338 #ifndef _UINT32_T
339 #define _UINT32_T
340 #endif
341EOF
342fi
343
344# ------------- done basic int types, emit int64_t types ------------
345if test "$ac_cv_type_uint64_t" = yes; then
346 sed 's/^ *//' >> tmp-stdint.h <<EOF
347
348 /* system headers have good uint64_t and int64_t */
349 #ifndef _INT64_T
350 #define _INT64_T
351 #endif
352 #ifndef _UINT64_T
353 #define _UINT64_T
354 #endif
355EOF
356elif test "$ac_cv_type_u_int64_t" = yes; then
357 sed 's/^ *//' >> tmp-stdint.h <<EOF
358
359 /* system headers have an u_int64_t (and int64_t) */
360 #ifndef _INT64_T
361 #define _INT64_T
362 #endif
363 #ifndef _UINT64_T
364 #define _UINT64_T
365 #ifndef __uint64_t_defined
366 #define __uint64_t_defined
367 typedef u_int64_t uint64_t;
368 #endif
369 #endif
370EOF
371elif test -n "$acx_cv_type_int64_t"; then
372 sed 's/^ *//' >> tmp-stdint.h <<EOF
373
374 /* architecture has a 64-bit type, $acx_cv_type_int64_t */
375 #ifndef _INT64_T
376 #define _INT64_T
377 typedef $acx_cv_type_int64_t int64_t;
378 #endif
379 #ifndef _UINT64_T
380 #define _UINT64_T
381 #ifndef __uint64_t_defined
382 #define __uint64_t_defined
383 typedef unsigned $acx_cv_type_int64_t uint64_t;
384 #endif
385 #endif
386EOF
387else
388 sed 's/^ *//' >> tmp-stdint.h <<EOF
389
390 /* some common heuristics for int64_t, using compiler-specific tests */
391 #if defined __STDC_VERSION__ && (__STDC_VERSION__-0) >= 199901L
392 #ifndef _INT64_T
393 #define _INT64_T
394 #ifndef __int64_t_defined
395 typedef long long int64_t;
396 #endif
397 #endif
398 #ifndef _UINT64_T
399 #define _UINT64_T
400 typedef unsigned long long uint64_t;
401 #endif
402
403 #elif defined __GNUC__ && defined (__STDC__) && __STDC__-0
404 /* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
405 does not implement __extension__. But that compiler doesn't define
406 __GNUC_MINOR__. */
407 # if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
408 # define __extension__
409 # endif
410
411 # ifndef _INT64_T
412 # define _INT64_T
413 __extension__ typedef long long int64_t;
414 # endif
415 # ifndef _UINT64_T
416 # define _UINT64_T
417 __extension__ typedef unsigned long long uint64_t;
418 # endif
419
420 #elif !defined __STRICT_ANSI__
421 # if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
422
423 # ifndef _INT64_T
424 # define _INT64_T
425 typedef __int64 int64_t;
426 # endif
427 # ifndef _UINT64_T
428 # define _UINT64_T
429 typedef unsigned __int64 uint64_t;
430 # endif
431 # endif /* compiler */
432
433 #endif /* ANSI version */
434EOF
435fi
436
437# ------------- done int64_t types, emit intptr types ------------
438if test "$ac_cv_type_uintptr_t" != yes; then
439 sed 's/^ *//' >> tmp-stdint.h <<EOF
440
441 /* Define intptr_t based on sizeof(void*) = $ac_cv_sizeof_void_p */
442 #ifndef __uintptr_t_defined
443 typedef u$acx_cv_type_intptr_t uintptr_t;
444 #endif
445 #ifndef __intptr_t_defined
446 typedef $acx_cv_type_intptr_t intptr_t;
447 #endif
448EOF
449fi
450
451# ------------- done intptr types, emit int_least types ------------
8eb2f3f0 452if test "$ac_cv_type_int_least32_t" != yes; then
f3b4f6d0 453 sed 's/^ *//' >> tmp-stdint.h <<EOF
8eb2f3f0
PB
454
455 /* Define int_least types */
456 typedef int8_t int_least8_t;
457 typedef int16_t int_least16_t;
458 typedef int32_t int_least32_t;
f3b4f6d0 459 #ifdef _INT64_T
8eb2f3f0 460 typedef int64_t int_least64_t;
f3b4f6d0 461 #endif
8eb2f3f0
PB
462
463 typedef uint8_t uint_least8_t;
464 typedef uint16_t uint_least16_t;
465 typedef uint32_t uint_least32_t;
f3b4f6d0 466 #ifdef _UINT64_T
8eb2f3f0 467 typedef uint64_t uint_least64_t;
f3b4f6d0 468 #endif
8eb2f3f0
PB
469EOF
470fi
471
f3b4f6d0 472# ------------- done intptr types, emit int_fast types ------------
8eb2f3f0
PB
473if test "$ac_cv_type_int_fast32_t" != yes; then
474 dnl NOTE: The following code assumes that sizeof (int) > 1.
475 dnl Fix when strange machines are reported.
f3b4f6d0 476 sed 's/^ *//' >> tmp-stdint.h <<EOF
8eb2f3f0
PB
477
478 /* Define int_fast types. short is often slow */
479 typedef int8_t int_fast8_t;
480 typedef int int_fast16_t;
481 typedef int32_t int_fast32_t;
f3b4f6d0 482 #ifdef _INT64_T
8eb2f3f0 483 typedef int64_t int_fast64_t;
f3b4f6d0 484 #endif
8eb2f3f0
PB
485
486 typedef uint8_t uint_fast8_t;
487 typedef unsigned int uint_fast16_t;
488 typedef uint32_t uint_fast32_t;
f3b4f6d0 489 #ifdef _UINT64_T
8eb2f3f0 490 typedef uint64_t uint_fast64_t;
f3b4f6d0 491 #endif
8eb2f3f0
PB
492EOF
493fi
494
f3b4f6d0
PB
495if test "$ac_cv_type_uintmax_t" != yes; then
496 sed 's/^ *//' >> tmp-stdint.h <<EOF
497
498 /* Define intmax based on what we found */
499 #ifdef _INT64_T
500 typedef int64_t intmax_t;
501 #else
502 typedef long intmax_t;
503 #endif
504 #ifdef _UINT64_T
505 typedef uint64_t uintmax_t;
506 #else
507 typedef unsigned long uintmax_t;
508 #endif
509EOF
510fi
511
512sed 's/^ *//' >> tmp-stdint.h <<EOF
513
514 #endif /* GCC_GENERATED_STDINT_H */
515EOF
8eb2f3f0 516
f3b4f6d0
PB
517if test -r ]_GCC_STDINT_H[ && cmp -s tmp-stdint.h ]_GCC_STDINT_H[; then
518 rm -f tmp-stdint.h
8eb2f3f0 519else
f3b4f6d0 520 mv -f tmp-stdint.h ]_GCC_STDINT_H[
8eb2f3f0
PB
521fi
522
523], [
f3b4f6d0
PB
524GCC="$GCC"
525CC="$CC"
526acx_cv_header_stdint="$acx_cv_header_stdint"
527acx_cv_type_int8_t="$acx_cv_type_int8_t"
528acx_cv_type_int16_t="$acx_cv_type_int16_t"
529acx_cv_type_int32_t="$acx_cv_type_int32_t"
530acx_cv_type_int64_t="$acx_cv_type_int64_t"
531acx_cv_type_intptr_t="$acx_cv_type_intptr_t"
532ac_cv_type_uintmax_t="$ac_cv_type_uintmax_t"
533ac_cv_type_uintptr_t="$ac_cv_type_uintptr_t"
534ac_cv_type_uint64_t="$ac_cv_type_uint64_t"
535ac_cv_type_u_int64_t="$ac_cv_type_u_int64_t"
536ac_cv_type_u_int32_t="$ac_cv_type_u_int32_t"
8eb2f3f0
PB
537ac_cv_type_int_least32_t="$ac_cv_type_int_least32_t"
538ac_cv_type_int_fast32_t="$ac_cv_type_int_fast32_t"
f3b4f6d0 539ac_cv_sizeof_void_p="$ac_cv_sizeof_void_p"
8eb2f3f0
PB
540])
541
542])
This page took 0.200364 seconds and 4 git commands to generate.