1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Type related macros: existence, sizeof, and structure members.
4 # Copyright (C) 2000-2002, 2004-2011 Free Software Foundation, Inc.
6 # This file is part of Autoconf. This program is free
7 # software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the
9 # Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # Under Section 7 of GPL version 3, you are granted additional
18 # permissions described in the Autoconf Configure Script Exception,
19 # version 3.0, as published by the Free Software Foundation.
21 # You should have received a copy of the GNU General Public License
22 # and a copy of the Autoconf Configure Script Exception along with
23 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
24 # respectively. If not, see <http://www.gnu.org/licenses/>.
26 # Written by David MacKenzie, with help from
27 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
28 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
31 ## ---------------- ##
33 ## ---------------- ##
39 # Up to 2.13 included, Autoconf used to provide the macro
41 # AC_CHECK_TYPE(TYPE, DEFAULT)
43 # Since, it provides another version which fits better with the other
47 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
48 # [INCLUDES = DEFAULT-INCLUDES])
50 # In order to provide backward compatibility, the new scheme is
51 # implemented as _AC_CHECK_TYPE_NEW, the old scheme as _AC_CHECK_TYPE_OLD,
52 # and AC_CHECK_TYPE branches to one or the other, depending upon its
56 # _AC_CHECK_TYPE_NEW_BODY
57 # -----------------------
58 # Shell function body for _AC_CHECK_TYPE_NEW. This macro implements the
59 # former task of AC_CHECK_TYPE, with one big difference though: AC_CHECK_TYPE
60 # used to grep in the headers, which, BTW, led to many problems until the
61 # extended regular expression was correct and did not give false positives.
62 # It turned out there are even portability issues with egrep...
64 # The most obvious way to check for a TYPE is just to compile a variable
69 # (TYPE being the second parameter to the shell function, hence $[]2 in m4).
70 # Unfortunately this does not work for const qualified types in C++, where
71 # you need an initializer. So you think of
73 # TYPE my_var = (TYPE) 0;
75 # Unfortunately, again, this is not valid for some C++ classes.
77 # Then you look for another scheme. For instance you think of declaring
78 # a function which uses a parameter of type TYPE:
80 # int foo (TYPE param);
82 # but of course you soon realize this does not make it with K&R
83 # compilers. And by no ways you want to
89 # since this time it's C++ who is not happy.
91 # Don't even think of the return type of a function, since K&R cries
92 # there too. So you start thinking of declaring a *pointer* to this TYPE:
96 # but you know fairly well that this is legal in C for aggregates which
97 # are unknown (TYPE = struct does-not-exist).
99 # Then you think of using sizeof to make sure the TYPE is really
104 # But this succeeds if TYPE is a variable: you get the size of the
107 # So, to filter out the last possibility, you try this too:
111 # This fails if TYPE is a type, but succeeds if TYPE is actually a variable.
113 # Also note that we use
117 # to `read' sizeof (to avoid warnings), while not depending on its type
118 # (not necessarily size_t etc.).
120 # C++ disallows defining types inside `sizeof ()', but that's OK,
121 # since we don't want to consider unnamed structs to be types for C++,
122 # precisely because they don't work in cases like that.
123 m4_define([_AC_CHECK_TYPE_NEW_BODY],
124 [ AS_LINENO_PUSH([$[]1])
125 AC_CACHE_CHECK([for $[]2], [$[]3],
126 [AS_VAR_SET([$[]3], [no])
128 [AC_LANG_PROGRAM([$[]4],
132 [AC_LANG_PROGRAM([$[]4],
133 [if (sizeof (($[]2)))
136 [AS_VAR_SET([$[]3], [yes])])])])
140 # _AC_CHECK_TYPE_NEW(TYPE,
141 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
142 # [INCLUDES = DEFAULT-INCLUDES])
143 # ------------------------------------------------------------
144 # Check whether the type TYPE is supported by the system, maybe via the
145 # the provided includes.
146 AC_DEFUN([_AC_CHECK_TYPE_NEW],
147 [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_type],
148 [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_type],
149 [LINENO TYPE VAR INCLUDES],
150 [Tests whether TYPE exists after having included INCLUDES, setting
151 cache variable VAR accordingly.])],
153 [AS_VAR_PUSHDEF([ac_Type], [ac_cv_type_$1])]dnl
154 [ac_fn_[]_AC_LANG_ABBREV[]_check_type "$LINENO" "$1" "ac_Type" ]dnl
155 ["AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
156 AS_VAR_IF([ac_Type], [yes], [$2], [$3])
157 AS_VAR_POPDEF([ac_Type])dnl
158 ])# _AC_CHECK_TYPE_NEW
161 # _AC_CHECK_TYPES(TYPE)
162 # ---------------------
163 # Helper to AC_CHECK_TYPES, which generates two of the four arguments
164 # to _AC_CHECK_TYPE_NEW that are based on TYPE.
165 m4_define([_AC_CHECK_TYPES],
166 [[$1], [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1]), [1],
167 [Define to 1 if the system has the type `$1'.])]])
170 # AC_CHECK_TYPES(TYPES,
171 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
172 # [INCLUDES = DEFAULT-INCLUDES])
173 # --------------------------------------------------------
174 # TYPES is an m4 list. There are no ambiguities here, we mean the newer
176 AC_DEFUN([AC_CHECK_TYPES],
177 [m4_map_args_sep([_AC_CHECK_TYPE_NEW(_$0(], [)[
178 $2], [$3], [$4])], [], $1)])
181 # _AC_CHECK_TYPE_OLD(TYPE, DEFAULT)
182 # ---------------------------------
183 # FIXME: This is an extremely badly chosen name, since this
184 # macro actually performs an AC_REPLACE_TYPE. Some day we
185 # have to clean this up.
186 m4_define([_AC_CHECK_TYPE_OLD],
187 [_AC_CHECK_TYPE_NEW([$1],,
188 [AC_DEFINE_UNQUOTED([$1], [$2],
189 [Define to `$2' if <sys/types.h> does not define.])])dnl
190 ])# _AC_CHECK_TYPE_OLD
193 # _AC_CHECK_TYPE_REPLACEMENT_TYPE_P(STRING)
194 # -----------------------------------------
195 # Return `1' if STRING seems to be a builtin C/C++ type, i.e., if it
196 # starts with `_Bool', `bool', `char', `double', `float', `int',
197 # `long', `short', `signed', or `unsigned' followed by characters
198 # that are defining types.
199 # Because many people have used `off_t' and `size_t' too, they are added
200 # for better common-useward backward compatibility.
201 m4_define([_AC_CHECK_TYPE_REPLACEMENT_TYPE_P],
203 [^\(_Bool\|bool\|char\|double\|float\|int\|long\|short\|\(un\)?signed\|[_a-zA-Z][_a-zA-Z0-9]*_t\)[][_a-zA-Z0-9() *]*$],
205 ])# _AC_CHECK_TYPE_REPLACEMENT_TYPE_P
208 # _AC_CHECK_TYPE_MAYBE_TYPE_P(STRING)
209 # -----------------------------------
210 # Return `1' if STRING looks like a C/C++ type.
211 m4_define([_AC_CHECK_TYPE_MAYBE_TYPE_P],
212 [m4_bmatch([$1], [^[_a-zA-Z0-9 ]+\([_a-zA-Z0-9() *]\|\[\|\]\)*$],
214 ])# _AC_CHECK_TYPE_MAYBE_TYPE_P
217 # AC_CHECK_TYPE(TYPE, DEFAULT)
219 # AC_CHECK_TYPE(TYPE,
220 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
221 # [INCLUDES = DEFAULT-INCLUDES])
222 # -------------------------------------------------------
224 # Dispatch respectively to _AC_CHECK_TYPE_OLD or _AC_CHECK_TYPE_NEW.
225 # 1. More than two arguments => NEW
226 # 2. $2 seems to be replacement type => OLD
227 # See _AC_CHECK_TYPE_REPLACEMENT_TYPE_P for `replacement type'.
228 # 3. $2 seems to be a type => NEW plus a warning
230 AC_DEFUN([AC_CHECK_TYPE],
232 [_AC_CHECK_TYPE_NEW],
234 [_AC_CHECK_TYPE_NEW],
235 [_AC_CHECK_TYPE_REPLACEMENT_TYPE_P([$2])], [1],
236 [_AC_CHECK_TYPE_OLD],
237 [_AC_CHECK_TYPE_MAYBE_TYPE_P([$2])], [1],
238 [AC_DIAGNOSE([syntax],
239 [$0: assuming `$2' is not a type])_AC_CHECK_TYPE_NEW],
240 [_AC_CHECK_TYPE_NEW])($@)])# AC_CHECK_TYPE
244 # ---------------------------- #
245 # Types that must be checked. #
246 # ---------------------------- #
248 AN_IDENTIFIER([ptrdiff_t], [AC_CHECK_TYPES])
251 # ----------------- #
253 # ----------------- #
257 AC_DEFUN([AC_TYPE_GETGROUPS],
258 [AC_REQUIRE([AC_TYPE_UID_T])dnl
259 AC_CACHE_CHECK(type of array argument to getgroups, ac_cv_type_getgroups,
260 [AC_RUN_IFELSE([AC_LANG_SOURCE(
261 [[/* Thanks to Mike Rendell for this test. */
262 ]AC_INCLUDES_DEFAULT[
265 #define MAX(x, y) ((x) > (y) ? (x) : (y))
272 union { gid_t gval; long int lval; } val;
275 for (i = 0; i < NGID; i++)
276 gidset[i] = val.gval;
277 n = getgroups (sizeof (gidset) / MAX (sizeof (int), sizeof (gid_t)) - 1,
279 /* Exit non-zero if getgroups seems to require an array of ints. This
280 happens when gid_t is short int but getgroups modifies an array
282 return n > 0 && gidset[n] != val.gval;
284 [ac_cv_type_getgroups=gid_t],
285 [ac_cv_type_getgroups=int],
286 [ac_cv_type_getgroups=cross])
287 if test $ac_cv_type_getgroups = cross; then
288 dnl When we can't run the test program (we are cross compiling), presume
289 dnl that <unistd.h> has either an accurate prototype for getgroups or none.
290 dnl Old systems without prototypes probably use int.
291 AC_EGREP_HEADER([getgroups.*int.*gid_t], unistd.h,
292 ac_cv_type_getgroups=gid_t, ac_cv_type_getgroups=int)
294 AC_DEFINE_UNQUOTED(GETGROUPS_T, $ac_cv_type_getgroups,
295 [Define to the type of elements in the array set by
296 `getgroups'. Usually this is either `int' or `gid_t'.])
297 ])# AC_TYPE_GETGROUPS
300 # AU::AM_TYPE_PTRDIFF_T
301 # ---------------------
302 AU_DEFUN([AM_TYPE_PTRDIFF_T],
303 [AC_CHECK_TYPES(ptrdiff_t)])
308 AC_DEFUN([AC_TYPE_INTMAX_T],
310 AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
311 AC_CHECK_TYPE([intmax_t],
312 [AC_DEFINE([HAVE_INTMAX_T], 1,
313 [Define to 1 if the system has the type `intmax_t'.])],
314 [test $ac_cv_type_long_long_int = yes \
315 && ac_type='long long int' \
316 || ac_type='long int'
317 AC_DEFINE_UNQUOTED([intmax_t], [$ac_type],
318 [Define to the widest signed integer type
319 if <stdint.h> and <inttypes.h> do not define.])])
325 AC_DEFUN([AC_TYPE_UINTMAX_T],
327 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
328 AC_CHECK_TYPE([uintmax_t],
329 [AC_DEFINE([HAVE_UINTMAX_T], 1,
330 [Define to 1 if the system has the type `uintmax_t'.])],
331 [test $ac_cv_type_unsigned_long_long_int = yes \
332 && ac_type='unsigned long long int' \
333 || ac_type='unsigned long int'
334 AC_DEFINE_UNQUOTED([uintmax_t], [$ac_type],
335 [Define to the widest unsigned integer type
336 if <stdint.h> and <inttypes.h> do not define.])])
342 AC_DEFUN([AC_TYPE_INTPTR_T],
344 AC_CHECK_TYPE([intptr_t],
345 [AC_DEFINE([HAVE_INTPTR_T], 1,
346 [Define to 1 if the system has the type `intptr_t'.])],
347 [for ac_type in 'int' 'long int' 'long long int'; do
349 [AC_LANG_BOOL_COMPILE_TRY(
350 [AC_INCLUDES_DEFAULT],
351 [[sizeof (void *) <= sizeof ($ac_type)]])],
352 [AC_DEFINE_UNQUOTED([intptr_t], [$ac_type],
353 [Define to the type of a signed integer type wide enough to
354 hold a pointer, if such a type exists, and if the system
355 does not define it.])
357 test -z "$ac_type" && break
364 AC_DEFUN([AC_TYPE_UINTPTR_T],
366 AC_CHECK_TYPE([uintptr_t],
367 [AC_DEFINE([HAVE_UINTPTR_T], 1,
368 [Define to 1 if the system has the type `uintptr_t'.])],
369 [for ac_type in 'unsigned int' 'unsigned long int' \
370 'unsigned long long int'; do
372 [AC_LANG_BOOL_COMPILE_TRY(
373 [AC_INCLUDES_DEFAULT],
374 [[sizeof (void *) <= sizeof ($ac_type)]])],
375 [AC_DEFINE_UNQUOTED([uintptr_t], [$ac_type],
376 [Define to the type of an unsigned integer type wide enough to
377 hold a pointer, if such a type exists, and if the system
378 does not define it.])
380 test -z "$ac_type" && break
385 # AC_TYPE_LONG_DOUBLE
386 # -------------------
387 AC_DEFUN([AC_TYPE_LONG_DOUBLE],
389 AC_CACHE_CHECK([for long double], [ac_cv_type_long_double],
390 [if test "$GCC" = yes; then
391 ac_cv_type_long_double=yes
394 [AC_LANG_BOOL_COMPILE_TRY(
395 [[/* The Stardent Vistra knows sizeof (long double), but does
397 long double foo = 0.0L;]],
398 [[/* On Ultrix 4.3 cc, long double is 4 and double is 8. */
399 sizeof (double) <= sizeof (long double)]])],
400 [ac_cv_type_long_double=yes],
401 [ac_cv_type_long_double=no])
403 if test $ac_cv_type_long_double = yes; then
404 AC_DEFINE([HAVE_LONG_DOUBLE], 1,
405 [Define to 1 if the system has the type `long double'.])
410 # AC_TYPE_LONG_DOUBLE_WIDER
411 # -------------------------
412 AC_DEFUN([AC_TYPE_LONG_DOUBLE_WIDER],
415 [for long double with more range or precision than double],
416 [ac_cv_type_long_double_wider],
418 [AC_LANG_BOOL_COMPILE_TRY(
420 long double const a[] =
422 0.0L, DBL_MIN, DBL_MAX, DBL_EPSILON,
423 LDBL_MIN, LDBL_MAX, LDBL_EPSILON
428 return ((x + (unsigned long int) 10) * (-1 / x) + a[0]
429 + (x ? f (x) : 'c'));
432 [[(0 < ((DBL_MAX_EXP < LDBL_MAX_EXP)
433 + (DBL_MANT_DIG < LDBL_MANT_DIG)
434 - (LDBL_MAX_EXP < DBL_MAX_EXP)
435 - (LDBL_MANT_DIG < DBL_MANT_DIG)))
436 && (int) LDBL_EPSILON == 0
438 ac_cv_type_long_double_wider=yes,
439 ac_cv_type_long_double_wider=no)])
440 if test $ac_cv_type_long_double_wider = yes; then
441 AC_DEFINE([HAVE_LONG_DOUBLE_WIDER], 1,
442 [Define to 1 if the type `long double' works and has more range or
443 precision than `double'.])
445 ])# AC_TYPE_LONG_DOUBLE_WIDER
450 AU_DEFUN([AC_C_LONG_DOUBLE],
452 AC_TYPE_LONG_DOUBLE_WIDER
453 ac_cv_c_long_double=$ac_cv_type_long_double_wider
454 if test $ac_cv_c_long_double = yes; then
455 AC_DEFINE([HAVE_LONG_DOUBLE], 1,
456 [Define to 1 if the type `long double' works and has more range or
457 precision than `double'.])
460 [The macro `AC_C_LONG_DOUBLE' is obsolete.
461 You should use `AC_TYPE_LONG_DOUBLE' or `AC_TYPE_LONG_DOUBLE_WIDER' instead.]
465 # _AC_TYPE_LONG_LONG_SNIPPET
466 # --------------------------
467 # Expands to a C program that can be used to test for simultaneous support
468 # of 'long long' and 'unsigned long long'. We don't want to say that
469 # 'long long' is available if 'unsigned long long' is not, or vice versa,
470 # because too many programs rely on the symmetry between signed and unsigned
471 # integer types (excluding 'bool').
472 AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET],
475 [[/* For now, do not test the preprocessor; as of 2007 there are too many
476 implementations with broken preprocessors. Perhaps this can
477 be revisited in 2012. In the meantime, code should not expect
478 #if to work with literals wider than 32 bits. */
480 long long int ll = 9223372036854775807ll;
481 long long int nll = -9223372036854775807LL;
482 unsigned long long int ull = 18446744073709551615ULL;
483 /* Test constant expressions. */
484 typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
486 typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
489 [[/* Test availability of runtime routines for shift and division. */
490 long long int llmax = 9223372036854775807ll;
491 unsigned long long int ullmax = 18446744073709551615ull;
492 return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
493 | (llmax / ll) | (llmax % ll)
494 | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
495 | (ullmax / ull) | (ullmax % ull));]])
499 # AC_TYPE_LONG_LONG_INT
500 # ---------------------
501 AC_DEFUN([AC_TYPE_LONG_LONG_INT],
503 AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
505 [_AC_TYPE_LONG_LONG_SNIPPET],
506 [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
507 dnl If cross compiling, assume the bug isn't important, since
508 dnl nobody cross compiles for this platform as far as we know.
511 [[@%:@include <limits.h>
514 (1LL << (sizeof (long long int) * CHAR_BIT - 2))
515 @%:@ define LLONG_MAX (HALF - 1 + HALF)
517 [[long long int n = 1;
521 long long int m = n << i;
524 if (LLONG_MAX / 2 < m)
528 [ac_cv_type_long_long_int=yes],
529 [ac_cv_type_long_long_int=no],
530 [ac_cv_type_long_long_int=yes])],
531 [ac_cv_type_long_long_int=no])])
532 if test $ac_cv_type_long_long_int = yes; then
533 AC_DEFINE([HAVE_LONG_LONG_INT], 1,
534 [Define to 1 if the system has the type `long long int'.])
539 # AC_TYPE_UNSIGNED_LONG_LONG_INT
540 # ------------------------------
541 AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
543 AC_CACHE_CHECK([for unsigned long long int],
544 [ac_cv_type_unsigned_long_long_int],
546 [_AC_TYPE_LONG_LONG_SNIPPET],
547 [ac_cv_type_unsigned_long_long_int=yes],
548 [ac_cv_type_unsigned_long_long_int=no])])
549 if test $ac_cv_type_unsigned_long_long_int = yes; then
550 AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1,
551 [Define to 1 if the system has the type `unsigned long long int'.])
558 AC_DEFUN([AC_TYPE_MBSTATE_T],
559 [AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
563 # include <wchar.h>],
564 [mbstate_t x; return sizeof x;])],
565 [ac_cv_type_mbstate_t=yes],
566 [ac_cv_type_mbstate_t=no])])
567 if test $ac_cv_type_mbstate_t = yes; then
568 AC_DEFINE([HAVE_MBSTATE_T], 1,
569 [Define to 1 if <wchar.h> declares mbstate_t.])
571 AC_DEFINE([mbstate_t], int,
572 [Define to a type if <wchar.h> does not define.])
578 # FIXME: Rewrite using AC_CHECK_TYPE.
579 AN_IDENTIFIER([gid_t], [AC_TYPE_UID_T])
580 AN_IDENTIFIER([uid_t], [AC_TYPE_UID_T])
581 AC_DEFUN([AC_TYPE_UID_T],
582 [AC_CACHE_CHECK(for uid_t in sys/types.h, ac_cv_type_uid_t,
583 [AC_EGREP_HEADER(uid_t, sys/types.h,
584 ac_cv_type_uid_t=yes, ac_cv_type_uid_t=no)])
585 if test $ac_cv_type_uid_t = no; then
586 AC_DEFINE(uid_t, int, [Define to `int' if <sys/types.h> doesn't define.])
587 AC_DEFINE(gid_t, int, [Define to `int' if <sys/types.h> doesn't define.])
592 AN_IDENTIFIER([size_t], [AC_TYPE_SIZE_T])
593 AC_DEFUN([AC_TYPE_SIZE_T], [AC_CHECK_TYPE(size_t, unsigned int)])
595 AN_IDENTIFIER([ssize_t], [AC_TYPE_SSIZE_T])
596 AC_DEFUN([AC_TYPE_SSIZE_T], [AC_CHECK_TYPE(ssize_t, int)])
598 AN_IDENTIFIER([pid_t], [AC_TYPE_PID_T])
599 AC_DEFUN([AC_TYPE_PID_T], [AC_CHECK_TYPE(pid_t, int)])
601 AN_IDENTIFIER([off_t], [AC_TYPE_OFF_T])
602 AC_DEFUN([AC_TYPE_OFF_T], [AC_CHECK_TYPE(off_t, long int)])
604 AN_IDENTIFIER([mode_t], [AC_TYPE_MODE_T])
605 AC_DEFUN([AC_TYPE_MODE_T], [AC_CHECK_TYPE(mode_t, int)])
607 AN_IDENTIFIER([int8_t], [AC_TYPE_INT8_T])
608 AN_IDENTIFIER([int16_t], [AC_TYPE_INT16_T])
609 AN_IDENTIFIER([int32_t], [AC_TYPE_INT32_T])
610 AN_IDENTIFIER([int64_t], [AC_TYPE_INT64_T])
611 AN_IDENTIFIER([uint8_t], [AC_TYPE_UINT8_T])
612 AN_IDENTIFIER([uint16_t], [AC_TYPE_UINT16_T])
613 AN_IDENTIFIER([uint32_t], [AC_TYPE_UINT32_T])
614 AN_IDENTIFIER([uint64_t], [AC_TYPE_UINT64_T])
615 AC_DEFUN([AC_TYPE_INT8_T], [_AC_TYPE_INT(8)])
616 AC_DEFUN([AC_TYPE_INT16_T], [_AC_TYPE_INT(16)])
617 AC_DEFUN([AC_TYPE_INT32_T], [_AC_TYPE_INT(32)])
618 AC_DEFUN([AC_TYPE_INT64_T], [_AC_TYPE_INT(64)])
619 AC_DEFUN([AC_TYPE_UINT8_T], [_AC_TYPE_UNSIGNED_INT(8)])
620 AC_DEFUN([AC_TYPE_UINT16_T], [_AC_TYPE_UNSIGNED_INT(16)])
621 AC_DEFUN([AC_TYPE_UINT32_T], [_AC_TYPE_UNSIGNED_INT(32)])
622 AC_DEFUN([AC_TYPE_UINT64_T], [_AC_TYPE_UNSIGNED_INT(64)])
626 # Shell function body for _AC_TYPE_INT.
627 m4_define([_AC_TYPE_INT_BODY],
628 [ AS_LINENO_PUSH([$[]1])
629 AC_CACHE_CHECK([for int$[]2_t], [$[]3],
630 [AS_VAR_SET([$[]3], [no])
631 # Order is important - never check a type that is potentially smaller
632 # than half of the expected target width.
633 for ac_type in int$[]2_t 'int' 'long int' \
634 'long long int' 'short int' 'signed char'; do
636 [AC_LANG_BOOL_COMPILE_TRY(
638 enum { N = $[]2 / 2 - 1 };],
639 [0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)])],
641 [AC_LANG_BOOL_COMPILE_TRY(
643 enum { N = $[]2 / 2 - 1 };],
644 [($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)
645 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 2)])],
647 [AS_CASE([$ac_type], [int$[]2_t],
648 [AS_VAR_SET([$[]3], [yes])],
649 [AS_VAR_SET([$[]3], [$ac_type])])])])
650 AS_VAR_IF([$[]3], [no], [], [break])
653 ])# _AC_TYPE_INT_BODY
655 # _AC_TYPE_INT(NBITS)
656 # -------------------
657 # Set a variable ac_cv_c_intNBITS_t to `yes' if intNBITS_t is available,
658 # `no' if it is not and no replacement types could be found, and a C type
659 # if it is not available but a replacement signed integer type of width
660 # exactly NBITS bits was found. In the third case, intNBITS_t is AC_DEFINEd
662 AC_DEFUN([_AC_TYPE_INT],
663 [AC_REQUIRE_SHELL_FN([ac_fn_c_find_intX_t],
664 [AS_FUNCTION_DESCRIBE([ac_fn_c_find_intX_t], [LINENO BITS VAR],
665 [Finds a signed integer type with width BITS, setting cache variable VAR
668 [ac_fn_c_find_intX_t "$LINENO" "$1" "ac_cv_c_int$1_t"
669 case $ac_cv_c_int$1_t in #(
672 AC_DEFINE_UNQUOTED([int$1_t], [$ac_cv_c_int$1_t],
673 [Define to the type of a signed integer type of width exactly $1 bits
674 if such a type exists and the standard includes do not define it.]);;
678 # _AC_TYPE_UNSIGNED_INT_BODY
679 # --------------------------
680 # Shell function body for _AC_TYPE_UNSIGNED_INT.
681 m4_define([_AC_TYPE_UNSIGNED_INT_BODY],
682 [ AS_LINENO_PUSH([$[]1])
683 AC_CACHE_CHECK([for uint$[]2_t], $[]3,
684 [AS_VAR_SET([$[]3], [no])
685 # Order is important - never check a type that is potentially smaller
686 # than half of the expected target width.
687 for ac_type in uint$[]2_t 'unsigned int' 'unsigned long int' \
688 'unsigned long long int' 'unsigned short int' 'unsigned char'; do
690 [AC_LANG_BOOL_COMPILE_TRY(
691 [AC_INCLUDES_DEFAULT],
692 [(($ac_type) -1 >> ($[]2 / 2 - 1)) >> ($[]2 / 2 - 1) == 3])],
693 [AS_CASE([$ac_type], [uint$[]2_t],
694 [AS_VAR_SET([$[]3], [yes])],
695 [AS_VAR_SET([$[]3], [$ac_type])])])
696 AS_VAR_IF([$[]3], [no], [], [break])
699 ])# _AC_TYPE_UNSIGNED_INT_BODY
702 # _AC_TYPE_UNSIGNED_INT(NBITS)
703 # ----------------------------
704 # Set a variable ac_cv_c_uintNBITS_t to `yes' if uintNBITS_t is available,
705 # `no' if it is not and no replacement types could be found, and a C type
706 # if it is not available but a replacement unsigned integer type of width
707 # exactly NBITS bits was found. In the third case, uintNBITS_t is AC_DEFINEd
709 AC_DEFUN([_AC_TYPE_UNSIGNED_INT],
710 [AC_REQUIRE_SHELL_FN([ac_fn_c_find_uintX_t],
711 [AS_FUNCTION_DESCRIBE([ac_fn_c_find_uintX_t], [LINENO BITS VAR],
712 [Finds an unsigned integer type with width BITS, setting cache variable VAR
715 [ac_fn_c_find_uintX_t "$LINENO" "$1" "ac_cv_c_uint$1_t"
716 case $ac_cv_c_uint$1_t in #(
719 m4_bmatch([$1], [^\(8\|32\|64\)$],
720 [AC_DEFINE([_UINT$1_T], 1,
721 [Define for Solaris 2.5.1 so the uint$1_t typedef from
722 <sys/synch.h>, <pthread.h>, or <semaphore.h> is not used.
723 If the typedef were allowed, the #define below would cause a
725 AC_DEFINE_UNQUOTED([uint$1_t], [$ac_cv_c_uint$1_t],
726 [Define to the type of an unsigned integer type of width exactly $1 bits
727 if such a type exists and the standard includes do not define it.]);;
729 ])# _AC_TYPE_UNSIGNED_INT
733 # Note that identifiers starting with SIG are reserved by ANSI C.
734 # C89 requires signal handlers to return void; only K&R returned int;
735 # modern code does not need to worry about using this macro (not to
736 # mention that sigaction is better than signal).
737 AU_DEFUN([AC_TYPE_SIGNAL],
738 [AC_CACHE_CHECK([return type of signal handlers], ac_cv_type_signal,
740 [AC_LANG_PROGRAM([#include <sys/types.h>
743 [return *(signal (0, 0)) (0) == 1;])],
744 [ac_cv_type_signal=int],
745 [ac_cv_type_signal=void])])
746 AC_DEFINE_UNQUOTED(RETSIGTYPE, $ac_cv_type_signal,
747 [Define as the return type of signal handlers
749 ], [your code may safely assume C89 semantics that RETSIGTYPE is void.
750 Remove this warning and the `AC_CACHE_CHECK' when you adjust the code.])
753 ## ------------------------ ##
754 ## Checking size of types. ##
755 ## ------------------------ ##
762 # AC_CHECK_SIZEOF(TYPE, [IGNORED], [INCLUDES = DEFAULT-INCLUDES])
763 # ---------------------------------------------------------------
764 AC_DEFUN([AC_CHECK_SIZEOF],
765 [AS_LITERAL_IF(m4_translit([[$1]], [*], [p]), [],
766 [m4_fatal([$0: requires literal arguments])])]dnl
767 [# The cast to long int works around a bug in the HP C Compiler
768 # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
769 # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
770 # This bug is HP SR number 8606223364.
771 _AC_CACHE_CHECK_INT([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])],
772 [(long int) (sizeof ($1))],
773 [AC_INCLUDES_DEFAULT([$3])],
774 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
775 AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)
777 AS_TR_SH([ac_cv_sizeof_$1])=0
780 AC_DEFINE_UNQUOTED(AS_TR_CPP(sizeof_$1), $AS_TR_SH([ac_cv_sizeof_$1]),
781 [The size of `$1', as computed by sizeof.])
785 # AC_CHECK_ALIGNOF(TYPE, [INCLUDES = DEFAULT-INCLUDES])
786 # -----------------------------------------------------
787 # TYPE can include braces and semicolon, which AS_TR_CPP and AS_TR_SH
788 # (correctly) recognize as potential shell metacharacters. So we
789 # have to flatten problematic characters ourselves to guarantee that
790 # AC_DEFINE_UNQUOTED will see a literal.
791 AC_DEFUN([AC_CHECK_ALIGNOF],
792 [m4_if(m4_index(m4_translit([[$1]], [`\"], [$]), [$]), [-1], [],
793 [m4_fatal([$0: requires literal arguments])])]dnl
794 [_$0([$1], [$2], m4_translit([[$1]], [{;}], [___]))])
796 m4_define([_AC_CHECK_ALIGNOF],
797 [# The cast to long int works around a bug in the HP C Compiler,
798 # see AC_CHECK_SIZEOF for more information.
799 _AC_CACHE_CHECK_INT([alignment of $1], [AS_TR_SH([ac_cv_alignof_$3])],
800 [(long int) offsetof (ac__type_alignof_, y)],
801 [AC_INCLUDES_DEFAULT([$2])
803 # define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
805 typedef struct { char x; $1 y; } ac__type_alignof_;],
806 [if test "$AS_TR_SH([ac_cv_type_$3])" = yes; then
807 AC_MSG_FAILURE([cannot compute alignment of $1], 77)
809 AS_TR_SH([ac_cv_alignof_$3])=0
812 AC_DEFINE_UNQUOTED(AS_TR_CPP(alignof_$3), $AS_TR_SH([ac_cv_alignof_$3]),
813 [The normal alignment of `$1', in bytes.])
819 # What a great name :)
820 AU_DEFUN([AC_INT_16_BITS],
821 [AC_CHECK_SIZEOF([int])
822 test $ac_cv_sizeof_int = 2 &&
823 AC_DEFINE(INT_16_BITS, 1,
824 [Define to 1 if `sizeof (int)' = 2. Obsolete, use `SIZEOF_INT'.])
825 ], [your code should no longer depend upon `INT_16_BITS', but upon
826 `SIZEOF_INT == 2'. Remove this warning and the `AC_DEFINE' when you
830 # AU::AC_LONG_64_BITS
831 # -------------------
832 AU_DEFUN([AC_LONG_64_BITS],
833 [AC_CHECK_SIZEOF([long int])
834 test $ac_cv_sizeof_long_int = 8 &&
835 AC_DEFINE(LONG_64_BITS, 1,
836 [Define to 1 if `sizeof (long int)' = 8. Obsolete, use
838 ], [your code should no longer depend upon `LONG_64_BITS', but upon
839 `SIZEOF_LONG_INT == 8'. Remove this warning and the `AC_DEFINE' when
840 you adjust the code.])
844 ## -------------------------- ##
845 ## Generic structure checks. ##
846 ## -------------------------- ##
853 # _AC_CHECK_MEMBER_BODY
854 # ---------------------
855 # Shell function body for AC_CHECK_MEMBER.
856 m4_define([_AC_CHECK_MEMBER_BODY],
857 [ AS_LINENO_PUSH([$[]1])
858 AC_CACHE_CHECK([for $[]2.$[]3], [$[]4],
859 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$[]5],
860 [static $[]2 ac_aggr;
863 [AS_VAR_SET([$[]4], [yes])],
864 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$[]5],
865 [static $[]2 ac_aggr;
866 if (sizeof ac_aggr.$[]3)
868 [AS_VAR_SET([$[]4], [yes])],
869 [AS_VAR_SET([$[]4], [no])])])])
873 # AC_CHECK_MEMBER(AGGREGATE.MEMBER,
874 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
875 # [INCLUDES = DEFAULT-INCLUDES])
876 # ---------------------------------------------------------
877 # AGGREGATE.MEMBER is for instance `struct passwd.pw_gecos', shell
878 # variables are not a valid argument.
879 AC_DEFUN([AC_CHECK_MEMBER],
880 [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_member],
881 [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_member],
882 [LINENO AGGR MEMBER VAR INCLUDES],
883 [Tries to find if the field MEMBER exists in type AGGR, after including
884 INCLUDES, setting cache variable VAR accordingly.])],
886 [AS_LITERAL_IF([$1], [], [m4_fatal([$0: requires literal arguments])])]dnl
887 [m4_if(m4_index([$1], [.]), [-1],
888 [m4_fatal([$0: Did not see any dot in `$1'])])]dnl
889 [AS_VAR_PUSHDEF([ac_Member], [ac_cv_member_$1])]dnl
890 [ac_fn_[]_AC_LANG_ABBREV[]_check_member "$LINENO" ]dnl
891 [m4_bpatsubst([$1], [^\([^.]*\)\.\(.*\)], ["\1" "\2"]) "ac_Member" ]dnl
892 ["AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
893 AS_VAR_IF([ac_Member], [yes], [$2], [$3])
894 AS_VAR_POPDEF([ac_Member])dnl
898 # _AC_CHECK_MEMBERS(AGGREGATE.MEMBER)
899 # -----------------------------------
900 # Helper to AC_CHECK_MEMBERS, which generates two of the four
901 # arguments to AC_CHECK_MEMBER that are based on AGGREGATE and MEMBER.
902 m4_define([_AC_CHECK_MEMBERS],
903 [[$1], [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1]), [1],
904 [Define to 1 if `]m4_bpatsubst([$1],
905 [^\([^.]*\)\.\(.*\)], [[\2' is a member of `\1]])['.])]])
907 # AC_CHECK_MEMBERS([AGGREGATE.MEMBER, ...],
908 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
909 # [INCLUDES = DEFAULT-INCLUDES])
910 # ----------------------------------------------------------
911 # The first argument is an m4 list.
912 AC_DEFUN([AC_CHECK_MEMBERS],
913 [m4_map_args_sep([AC_CHECK_MEMBER(_$0(], [)[
914 $2], [$3], [$4])], [], $1)])
918 # ------------------------------------------------------- #
919 # Members that ought to be tested with AC_CHECK_MEMBERS. #
920 # ------------------------------------------------------- #
922 AN_IDENTIFIER([st_blksize], [AC_CHECK_MEMBERS([struct stat.st_blksize])])
923 AN_IDENTIFIER([st_rdev], [AC_CHECK_MEMBERS([struct stat.st_rdev])])
926 # Alphabetic order, please.
928 # _AC_STRUCT_DIRENT(MEMBER)
929 # -------------------------
930 AC_DEFUN([_AC_STRUCT_DIRENT],
932 AC_REQUIRE([AC_HEADER_DIRENT])
933 AC_CHECK_MEMBERS([struct dirent.$1], [], [],
935 #include <sys/types.h>
939 # define dirent direct
940 # ifdef HAVE_SYS_NDIR_H
941 # include <sys/ndir.h>
943 # ifdef HAVE_SYS_DIR_H
944 # include <sys/dir.h>
953 # AC_STRUCT_DIRENT_D_INO
954 # ----------------------
955 AC_DEFUN([AC_STRUCT_DIRENT_D_INO], [_AC_STRUCT_DIRENT([d_ino])])
957 # AC_STRUCT_DIRENT_D_TYPE
958 # -----------------------
959 AC_DEFUN([AC_STRUCT_DIRENT_D_TYPE], [_AC_STRUCT_DIRENT([d_type])])
962 # AC_STRUCT_ST_BLKSIZE
963 # --------------------
964 AU_DEFUN([AC_STRUCT_ST_BLKSIZE],
965 [AC_CHECK_MEMBERS([struct stat.st_blksize],
966 [AC_DEFINE(HAVE_ST_BLKSIZE, 1,
967 [Define to 1 if your `struct stat' has
968 `st_blksize'. Deprecated, use
969 `HAVE_STRUCT_STAT_ST_BLKSIZE' instead.])])
970 ], [your code should no longer depend upon `HAVE_ST_BLKSIZE', but
971 `HAVE_STRUCT_STAT_ST_BLKSIZE'. Remove this warning and
972 the `AC_DEFINE' when you adjust the code.])# AC_STRUCT_ST_BLKSIZE
975 # AC_STRUCT_ST_BLOCKS
976 # -------------------
977 # If `struct stat' contains an `st_blocks' member, define
978 # HAVE_STRUCT_STAT_ST_BLOCKS. Otherwise, add `fileblocks.o' to the
979 # output variable LIBOBJS. We still define HAVE_ST_BLOCKS for backward
980 # compatibility. In the future, we will activate specializations for
981 # this macro, so don't obsolete it right now.
983 # AC_OBSOLETE([$0], [; replace it with
984 # AC_CHECK_MEMBERS([struct stat.st_blocks],
985 # [AC_LIBOBJ([fileblocks])])
986 # Please note that it will define `HAVE_STRUCT_STAT_ST_BLOCKS',
987 # and not `HAVE_ST_BLOCKS'.])dnl
989 AN_IDENTIFIER([st_blocks], [AC_STRUCT_ST_BLOCKS])
990 AC_DEFUN([AC_STRUCT_ST_BLOCKS],
991 [AC_CHECK_MEMBERS([struct stat.st_blocks],
992 [AC_DEFINE(HAVE_ST_BLOCKS, 1,
993 [Define to 1 if your `struct stat' has
994 `st_blocks'. Deprecated, use
995 `HAVE_STRUCT_STAT_ST_BLOCKS' instead.])],
996 [AC_LIBOBJ([fileblocks])])
997 ])# AC_STRUCT_ST_BLOCKS
1002 AU_DEFUN([AC_STRUCT_ST_RDEV],
1003 [AC_CHECK_MEMBERS([struct stat.st_rdev],
1004 [AC_DEFINE(HAVE_ST_RDEV, 1,
1005 [Define to 1 if your `struct stat' has `st_rdev'.
1006 Deprecated, use `HAVE_STRUCT_STAT_ST_RDEV'
1008 ], [your code should no longer depend upon `HAVE_ST_RDEV', but
1009 `HAVE_STRUCT_STAT_ST_RDEV'. Remove this warning and
1010 the `AC_DEFINE' when you adjust the code.])# AC_STRUCT_ST_RDEV
1015 # FIXME: This macro is badly named, it should be AC_CHECK_TYPE_STRUCT_TM.
1016 # Or something else, but what? AC_CHECK_TYPE_STRUCT_TM_IN_SYS_TIME?
1017 AC_DEFUN([AC_STRUCT_TM],
1018 [AC_CACHE_CHECK([whether struct tm is in sys/time.h or time.h],
1020 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
1024 int *p = &tm.tm_sec;
1026 [ac_cv_struct_tm=time.h],
1027 [ac_cv_struct_tm=sys/time.h])])
1028 if test $ac_cv_struct_tm = sys/time.h; then
1029 AC_DEFINE(TM_IN_SYS_TIME, 1,
1030 [Define to 1 if your <sys/time.h> declares `struct tm'.])
1035 # AC_STRUCT_TIMEZONE
1036 # ------------------
1037 # Figure out how to get the current timezone. If `struct tm' has a
1038 # `tm_zone' member, define `HAVE_TM_ZONE'. Otherwise, if the
1039 # external array `tzname' is found, define `HAVE_TZNAME'.
1040 AN_IDENTIFIER([tm_zone], [AC_STRUCT_TIMEZONE])
1041 AC_DEFUN([AC_STRUCT_TIMEZONE],
1042 [AC_REQUIRE([AC_STRUCT_TM])dnl
1043 AC_CHECK_MEMBERS([struct tm.tm_zone],,,[#include <sys/types.h>
1044 #include <$ac_cv_struct_tm>
1046 if test "$ac_cv_member_struct_tm_tm_zone" = yes; then
1047 AC_DEFINE(HAVE_TM_ZONE, 1,
1048 [Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
1049 `HAVE_STRUCT_TM_TM_ZONE' instead.])
1051 AC_CHECK_DECLS([tzname], , , [#include <time.h>])
1052 AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
1053 [AC_LINK_IFELSE([AC_LANG_PROGRAM(
1055 #if !HAVE_DECL_TZNAME
1056 extern char *tzname[];
1059 [[return tzname[0][0];]])],
1060 [ac_cv_var_tzname=yes],
1061 [ac_cv_var_tzname=no])])
1062 if test $ac_cv_var_tzname = yes; then
1063 AC_DEFINE(HAVE_TZNAME, 1,
1064 [Define to 1 if you don't have `tm_zone' but do have the external
1068 ])# AC_STRUCT_TIMEZONE