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_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
504 AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
505 [ac_cv_type_long_long_int=yes
506 if test "x${ac_cv_prog_cc_c99-no}" = xno; then
507 ac_cv_type_long_long_int=$ac_cv_type_unsigned_long_long_int
508 if test $ac_cv_type_long_long_int = yes; then
509 dnl Catch a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
510 dnl If cross compiling, assume the bug is not important, since
511 dnl nobody cross compiles for this platform as far as we know.
514 [[@%:@include <limits.h>
517 (1LL << (sizeof (long long int) * CHAR_BIT - 2))
518 @%:@ define LLONG_MAX (HALF - 1 + HALF)
520 [[long long int n = 1;
524 long long int m = n << i;
527 if (LLONG_MAX / 2 < m)
532 [ac_cv_type_long_long_int=no])
535 if test $ac_cv_type_long_long_int = yes; then
536 AC_DEFINE([HAVE_LONG_LONG_INT], [1],
537 [Define to 1 if the system has the type `long long int'.])
542 # AC_TYPE_UNSIGNED_LONG_LONG_INT
543 # ------------------------------
544 AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
546 AC_CACHE_CHECK([for unsigned long long int],
547 [ac_cv_type_unsigned_long_long_int],
548 [ac_cv_type_unsigned_long_long_int=yes
549 if test "x${ac_cv_prog_cc_c99-no}" = xno; then
551 [_AC_TYPE_LONG_LONG_SNIPPET],
553 [ac_cv_type_unsigned_long_long_int=no])
555 if test $ac_cv_type_unsigned_long_long_int = yes; then
556 AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1],
557 [Define to 1 if the system has the type `unsigned long long int'.])
564 AC_DEFUN([AC_TYPE_MBSTATE_T],
565 [AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
569 # include <wchar.h>],
570 [mbstate_t x; return sizeof x;])],
571 [ac_cv_type_mbstate_t=yes],
572 [ac_cv_type_mbstate_t=no])])
573 if test $ac_cv_type_mbstate_t = yes; then
574 AC_DEFINE([HAVE_MBSTATE_T], 1,
575 [Define to 1 if <wchar.h> declares mbstate_t.])
577 AC_DEFINE([mbstate_t], int,
578 [Define to a type if <wchar.h> does not define.])
584 # FIXME: Rewrite using AC_CHECK_TYPE.
585 AN_IDENTIFIER([gid_t], [AC_TYPE_UID_T])
586 AN_IDENTIFIER([uid_t], [AC_TYPE_UID_T])
587 AC_DEFUN([AC_TYPE_UID_T],
588 [AC_CACHE_CHECK(for uid_t in sys/types.h, ac_cv_type_uid_t,
589 [AC_EGREP_HEADER(uid_t, sys/types.h,
590 ac_cv_type_uid_t=yes, ac_cv_type_uid_t=no)])
591 if test $ac_cv_type_uid_t = no; then
592 AC_DEFINE(uid_t, int, [Define to `int' if <sys/types.h> doesn't define.])
593 AC_DEFINE(gid_t, int, [Define to `int' if <sys/types.h> doesn't define.])
598 AN_IDENTIFIER([size_t], [AC_TYPE_SIZE_T])
599 AC_DEFUN([AC_TYPE_SIZE_T], [AC_CHECK_TYPE(size_t, unsigned int)])
601 AN_IDENTIFIER([ssize_t], [AC_TYPE_SSIZE_T])
602 AC_DEFUN([AC_TYPE_SSIZE_T], [AC_CHECK_TYPE(ssize_t, int)])
604 AN_IDENTIFIER([pid_t], [AC_TYPE_PID_T])
605 AC_DEFUN([AC_TYPE_PID_T], [AC_CHECK_TYPE(pid_t, int)])
607 AN_IDENTIFIER([off_t], [AC_TYPE_OFF_T])
608 AC_DEFUN([AC_TYPE_OFF_T], [AC_CHECK_TYPE(off_t, long int)])
610 AN_IDENTIFIER([mode_t], [AC_TYPE_MODE_T])
611 AC_DEFUN([AC_TYPE_MODE_T], [AC_CHECK_TYPE(mode_t, int)])
613 AN_IDENTIFIER([int8_t], [AC_TYPE_INT8_T])
614 AN_IDENTIFIER([int16_t], [AC_TYPE_INT16_T])
615 AN_IDENTIFIER([int32_t], [AC_TYPE_INT32_T])
616 AN_IDENTIFIER([int64_t], [AC_TYPE_INT64_T])
617 AN_IDENTIFIER([uint8_t], [AC_TYPE_UINT8_T])
618 AN_IDENTIFIER([uint16_t], [AC_TYPE_UINT16_T])
619 AN_IDENTIFIER([uint32_t], [AC_TYPE_UINT32_T])
620 AN_IDENTIFIER([uint64_t], [AC_TYPE_UINT64_T])
621 AC_DEFUN([AC_TYPE_INT8_T], [_AC_TYPE_INT(8)])
622 AC_DEFUN([AC_TYPE_INT16_T], [_AC_TYPE_INT(16)])
623 AC_DEFUN([AC_TYPE_INT32_T], [_AC_TYPE_INT(32)])
624 AC_DEFUN([AC_TYPE_INT64_T], [_AC_TYPE_INT(64)])
625 AC_DEFUN([AC_TYPE_UINT8_T], [_AC_TYPE_UNSIGNED_INT(8)])
626 AC_DEFUN([AC_TYPE_UINT16_T], [_AC_TYPE_UNSIGNED_INT(16)])
627 AC_DEFUN([AC_TYPE_UINT32_T], [_AC_TYPE_UNSIGNED_INT(32)])
628 AC_DEFUN([AC_TYPE_UINT64_T], [_AC_TYPE_UNSIGNED_INT(64)])
632 # Shell function body for _AC_TYPE_INT.
633 m4_define([_AC_TYPE_INT_BODY],
634 [ AS_LINENO_PUSH([$[]1])
635 AC_CACHE_CHECK([for int$[]2_t], [$[]3],
636 [AS_VAR_SET([$[]3], [no])
637 # Order is important - never check a type that is potentially smaller
638 # than half of the expected target width.
639 for ac_type in int$[]2_t 'int' 'long int' \
640 'long long int' 'short int' 'signed char'; do
642 [AC_LANG_BOOL_COMPILE_TRY(
644 enum { N = $[]2 / 2 - 1 };],
645 [0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)])],
647 [AC_LANG_BOOL_COMPILE_TRY(
649 enum { N = $[]2 / 2 - 1 };],
650 [($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)
651 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 2)])],
653 [AS_CASE([$ac_type], [int$[]2_t],
654 [AS_VAR_SET([$[]3], [yes])],
655 [AS_VAR_SET([$[]3], [$ac_type])])])])
656 AS_VAR_IF([$[]3], [no], [], [break])
659 ])# _AC_TYPE_INT_BODY
661 # _AC_TYPE_INT(NBITS)
662 # -------------------
663 # Set a variable ac_cv_c_intNBITS_t to `yes' if intNBITS_t is available,
664 # `no' if it is not and no replacement types could be found, and a C type
665 # if it is not available but a replacement signed integer type of width
666 # exactly NBITS bits was found. In the third case, intNBITS_t is AC_DEFINEd
668 AC_DEFUN([_AC_TYPE_INT],
669 [AC_REQUIRE_SHELL_FN([ac_fn_c_find_intX_t],
670 [AS_FUNCTION_DESCRIBE([ac_fn_c_find_intX_t], [LINENO BITS VAR],
671 [Finds a signed integer type with width BITS, setting cache variable VAR
674 [ac_fn_c_find_intX_t "$LINENO" "$1" "ac_cv_c_int$1_t"
675 case $ac_cv_c_int$1_t in #(
678 AC_DEFINE_UNQUOTED([int$1_t], [$ac_cv_c_int$1_t],
679 [Define to the type of a signed integer type of width exactly $1 bits
680 if such a type exists and the standard includes do not define it.]);;
684 # _AC_TYPE_UNSIGNED_INT_BODY
685 # --------------------------
686 # Shell function body for _AC_TYPE_UNSIGNED_INT.
687 m4_define([_AC_TYPE_UNSIGNED_INT_BODY],
688 [ AS_LINENO_PUSH([$[]1])
689 AC_CACHE_CHECK([for uint$[]2_t], $[]3,
690 [AS_VAR_SET([$[]3], [no])
691 # Order is important - never check a type that is potentially smaller
692 # than half of the expected target width.
693 for ac_type in uint$[]2_t 'unsigned int' 'unsigned long int' \
694 'unsigned long long int' 'unsigned short int' 'unsigned char'; do
696 [AC_LANG_BOOL_COMPILE_TRY(
697 [AC_INCLUDES_DEFAULT],
698 [(($ac_type) -1 >> ($[]2 / 2 - 1)) >> ($[]2 / 2 - 1) == 3])],
699 [AS_CASE([$ac_type], [uint$[]2_t],
700 [AS_VAR_SET([$[]3], [yes])],
701 [AS_VAR_SET([$[]3], [$ac_type])])])
702 AS_VAR_IF([$[]3], [no], [], [break])
705 ])# _AC_TYPE_UNSIGNED_INT_BODY
708 # _AC_TYPE_UNSIGNED_INT(NBITS)
709 # ----------------------------
710 # Set a variable ac_cv_c_uintNBITS_t to `yes' if uintNBITS_t is available,
711 # `no' if it is not and no replacement types could be found, and a C type
712 # if it is not available but a replacement unsigned integer type of width
713 # exactly NBITS bits was found. In the third case, uintNBITS_t is AC_DEFINEd
715 AC_DEFUN([_AC_TYPE_UNSIGNED_INT],
716 [AC_REQUIRE_SHELL_FN([ac_fn_c_find_uintX_t],
717 [AS_FUNCTION_DESCRIBE([ac_fn_c_find_uintX_t], [LINENO BITS VAR],
718 [Finds an unsigned integer type with width BITS, setting cache variable VAR
721 [ac_fn_c_find_uintX_t "$LINENO" "$1" "ac_cv_c_uint$1_t"
722 case $ac_cv_c_uint$1_t in #(
725 m4_bmatch([$1], [^\(8\|32\|64\)$],
726 [AC_DEFINE([_UINT$1_T], 1,
727 [Define for Solaris 2.5.1 so the uint$1_t typedef from
728 <sys/synch.h>, <pthread.h>, or <semaphore.h> is not used.
729 If the typedef were allowed, the #define below would cause a
731 AC_DEFINE_UNQUOTED([uint$1_t], [$ac_cv_c_uint$1_t],
732 [Define to the type of an unsigned integer type of width exactly $1 bits
733 if such a type exists and the standard includes do not define it.]);;
735 ])# _AC_TYPE_UNSIGNED_INT
739 # Note that identifiers starting with SIG are reserved by ANSI C.
740 # C89 requires signal handlers to return void; only K&R returned int;
741 # modern code does not need to worry about using this macro (not to
742 # mention that sigaction is better than signal).
743 AU_DEFUN([AC_TYPE_SIGNAL],
744 [AC_CACHE_CHECK([return type of signal handlers], ac_cv_type_signal,
746 [AC_LANG_PROGRAM([#include <sys/types.h>
749 [return *(signal (0, 0)) (0) == 1;])],
750 [ac_cv_type_signal=int],
751 [ac_cv_type_signal=void])])
752 AC_DEFINE_UNQUOTED(RETSIGTYPE, $ac_cv_type_signal,
753 [Define as the return type of signal handlers
755 ], [your code may safely assume C89 semantics that RETSIGTYPE is void.
756 Remove this warning and the `AC_CACHE_CHECK' when you adjust the code.])
759 ## ------------------------ ##
760 ## Checking size of types. ##
761 ## ------------------------ ##
768 # AC_CHECK_SIZEOF(TYPE, [IGNORED], [INCLUDES = DEFAULT-INCLUDES])
769 # ---------------------------------------------------------------
770 AC_DEFUN([AC_CHECK_SIZEOF],
771 [AS_LITERAL_IF(m4_translit([[$1]], [*], [p]), [],
772 [m4_fatal([$0: requires literal arguments])])]dnl
773 [# The cast to long int works around a bug in the HP C Compiler
774 # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
775 # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
776 # This bug is HP SR number 8606223364.
777 _AC_CACHE_CHECK_INT([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])],
778 [(long int) (sizeof ($1))],
779 [AC_INCLUDES_DEFAULT([$3])],
780 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
781 AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)
783 AS_TR_SH([ac_cv_sizeof_$1])=0
786 AC_DEFINE_UNQUOTED(AS_TR_CPP(sizeof_$1), $AS_TR_SH([ac_cv_sizeof_$1]),
787 [The size of `$1', as computed by sizeof.])
791 # AC_CHECK_ALIGNOF(TYPE, [INCLUDES = DEFAULT-INCLUDES])
792 # -----------------------------------------------------
793 # TYPE can include braces and semicolon, which AS_TR_CPP and AS_TR_SH
794 # (correctly) recognize as potential shell metacharacters. So we
795 # have to flatten problematic characters ourselves to guarantee that
796 # AC_DEFINE_UNQUOTED will see a literal.
797 AC_DEFUN([AC_CHECK_ALIGNOF],
798 [m4_if(m4_index(m4_translit([[$1]], [`\"], [$]), [$]), [-1], [],
799 [m4_fatal([$0: requires literal arguments])])]dnl
800 [_$0([$1], [$2], m4_translit([[$1]], [{;}], [___]))])
802 m4_define([_AC_CHECK_ALIGNOF],
803 [# The cast to long int works around a bug in the HP C Compiler,
804 # see AC_CHECK_SIZEOF for more information.
805 _AC_CACHE_CHECK_INT([alignment of $1], [AS_TR_SH([ac_cv_alignof_$3])],
806 [(long int) offsetof (ac__type_alignof_, y)],
807 [AC_INCLUDES_DEFAULT([$2])
809 # define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
811 typedef struct { char x; $1 y; } ac__type_alignof_;],
812 [if test "$AS_TR_SH([ac_cv_type_$3])" = yes; then
813 AC_MSG_FAILURE([cannot compute alignment of $1], 77)
815 AS_TR_SH([ac_cv_alignof_$3])=0
818 AC_DEFINE_UNQUOTED(AS_TR_CPP(alignof_$3), $AS_TR_SH([ac_cv_alignof_$3]),
819 [The normal alignment of `$1', in bytes.])
825 # What a great name :)
826 AU_DEFUN([AC_INT_16_BITS],
827 [AC_CHECK_SIZEOF([int])
828 test $ac_cv_sizeof_int = 2 &&
829 AC_DEFINE(INT_16_BITS, 1,
830 [Define to 1 if `sizeof (int)' = 2. Obsolete, use `SIZEOF_INT'.])
831 ], [your code should no longer depend upon `INT_16_BITS', but upon
832 `SIZEOF_INT == 2'. Remove this warning and the `AC_DEFINE' when you
836 # AU::AC_LONG_64_BITS
837 # -------------------
838 AU_DEFUN([AC_LONG_64_BITS],
839 [AC_CHECK_SIZEOF([long int])
840 test $ac_cv_sizeof_long_int = 8 &&
841 AC_DEFINE(LONG_64_BITS, 1,
842 [Define to 1 if `sizeof (long int)' = 8. Obsolete, use
844 ], [your code should no longer depend upon `LONG_64_BITS', but upon
845 `SIZEOF_LONG_INT == 8'. Remove this warning and the `AC_DEFINE' when
846 you adjust the code.])
850 ## -------------------------- ##
851 ## Generic structure checks. ##
852 ## -------------------------- ##
859 # _AC_CHECK_MEMBER_BODY
860 # ---------------------
861 # Shell function body for AC_CHECK_MEMBER.
862 m4_define([_AC_CHECK_MEMBER_BODY],
863 [ AS_LINENO_PUSH([$[]1])
864 AC_CACHE_CHECK([for $[]2.$[]3], [$[]4],
865 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$[]5],
866 [static $[]2 ac_aggr;
869 [AS_VAR_SET([$[]4], [yes])],
870 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$[]5],
871 [static $[]2 ac_aggr;
872 if (sizeof ac_aggr.$[]3)
874 [AS_VAR_SET([$[]4], [yes])],
875 [AS_VAR_SET([$[]4], [no])])])])
879 # AC_CHECK_MEMBER(AGGREGATE.MEMBER,
880 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
881 # [INCLUDES = DEFAULT-INCLUDES])
882 # ---------------------------------------------------------
883 # AGGREGATE.MEMBER is for instance `struct passwd.pw_gecos', shell
884 # variables are not a valid argument.
885 AC_DEFUN([AC_CHECK_MEMBER],
886 [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_member],
887 [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_member],
888 [LINENO AGGR MEMBER VAR INCLUDES],
889 [Tries to find if the field MEMBER exists in type AGGR, after including
890 INCLUDES, setting cache variable VAR accordingly.])],
892 [AS_LITERAL_IF([$1], [], [m4_fatal([$0: requires literal arguments])])]dnl
893 [m4_if(m4_index([$1], [.]), [-1],
894 [m4_fatal([$0: Did not see any dot in `$1'])])]dnl
895 [AS_VAR_PUSHDEF([ac_Member], [ac_cv_member_$1])]dnl
896 [ac_fn_[]_AC_LANG_ABBREV[]_check_member "$LINENO" ]dnl
897 [m4_bpatsubst([$1], [^\([^.]*\)\.\(.*\)], ["\1" "\2"]) "ac_Member" ]dnl
898 ["AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
899 AS_VAR_IF([ac_Member], [yes], [$2], [$3])
900 AS_VAR_POPDEF([ac_Member])dnl
904 # _AC_CHECK_MEMBERS(AGGREGATE.MEMBER)
905 # -----------------------------------
906 # Helper to AC_CHECK_MEMBERS, which generates two of the four
907 # arguments to AC_CHECK_MEMBER that are based on AGGREGATE and MEMBER.
908 m4_define([_AC_CHECK_MEMBERS],
909 [[$1], [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1]), [1],
910 [Define to 1 if `]m4_bpatsubst([$1],
911 [^\([^.]*\)\.\(.*\)], [[\2' is a member of `\1]])['.])]])
913 # AC_CHECK_MEMBERS([AGGREGATE.MEMBER, ...],
914 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
915 # [INCLUDES = DEFAULT-INCLUDES])
916 # ----------------------------------------------------------
917 # The first argument is an m4 list.
918 AC_DEFUN([AC_CHECK_MEMBERS],
919 [m4_map_args_sep([AC_CHECK_MEMBER(_$0(], [)[
920 $2], [$3], [$4])], [], $1)])
924 # ------------------------------------------------------- #
925 # Members that ought to be tested with AC_CHECK_MEMBERS. #
926 # ------------------------------------------------------- #
928 AN_IDENTIFIER([st_blksize], [AC_CHECK_MEMBERS([struct stat.st_blksize])])
929 AN_IDENTIFIER([st_rdev], [AC_CHECK_MEMBERS([struct stat.st_rdev])])
932 # Alphabetic order, please.
934 # _AC_STRUCT_DIRENT(MEMBER)
935 # -------------------------
936 AC_DEFUN([_AC_STRUCT_DIRENT],
938 AC_REQUIRE([AC_HEADER_DIRENT])
939 AC_CHECK_MEMBERS([struct dirent.$1], [], [],
941 #include <sys/types.h>
945 # define dirent direct
946 # ifdef HAVE_SYS_NDIR_H
947 # include <sys/ndir.h>
949 # ifdef HAVE_SYS_DIR_H
950 # include <sys/dir.h>
959 # AC_STRUCT_DIRENT_D_INO
960 # ----------------------
961 AC_DEFUN([AC_STRUCT_DIRENT_D_INO], [_AC_STRUCT_DIRENT([d_ino])])
963 # AC_STRUCT_DIRENT_D_TYPE
964 # -----------------------
965 AC_DEFUN([AC_STRUCT_DIRENT_D_TYPE], [_AC_STRUCT_DIRENT([d_type])])
968 # AC_STRUCT_ST_BLKSIZE
969 # --------------------
970 AU_DEFUN([AC_STRUCT_ST_BLKSIZE],
971 [AC_CHECK_MEMBERS([struct stat.st_blksize],
972 [AC_DEFINE(HAVE_ST_BLKSIZE, 1,
973 [Define to 1 if your `struct stat' has
974 `st_blksize'. Deprecated, use
975 `HAVE_STRUCT_STAT_ST_BLKSIZE' instead.])])
976 ], [your code should no longer depend upon `HAVE_ST_BLKSIZE', but
977 `HAVE_STRUCT_STAT_ST_BLKSIZE'. Remove this warning and
978 the `AC_DEFINE' when you adjust the code.])# AC_STRUCT_ST_BLKSIZE
981 # AC_STRUCT_ST_BLOCKS
982 # -------------------
983 # If `struct stat' contains an `st_blocks' member, define
984 # HAVE_STRUCT_STAT_ST_BLOCKS. Otherwise, add `fileblocks.o' to the
985 # output variable LIBOBJS. We still define HAVE_ST_BLOCKS for backward
986 # compatibility. In the future, we will activate specializations for
987 # this macro, so don't obsolete it right now.
989 # AC_OBSOLETE([$0], [; replace it with
990 # AC_CHECK_MEMBERS([struct stat.st_blocks],
991 # [AC_LIBOBJ([fileblocks])])
992 # Please note that it will define `HAVE_STRUCT_STAT_ST_BLOCKS',
993 # and not `HAVE_ST_BLOCKS'.])dnl
995 AN_IDENTIFIER([st_blocks], [AC_STRUCT_ST_BLOCKS])
996 AC_DEFUN([AC_STRUCT_ST_BLOCKS],
997 [AC_CHECK_MEMBERS([struct stat.st_blocks],
998 [AC_DEFINE(HAVE_ST_BLOCKS, 1,
999 [Define to 1 if your `struct stat' has
1000 `st_blocks'. Deprecated, use
1001 `HAVE_STRUCT_STAT_ST_BLOCKS' instead.])],
1002 [AC_LIBOBJ([fileblocks])])
1003 ])# AC_STRUCT_ST_BLOCKS
1008 AU_DEFUN([AC_STRUCT_ST_RDEV],
1009 [AC_CHECK_MEMBERS([struct stat.st_rdev],
1010 [AC_DEFINE(HAVE_ST_RDEV, 1,
1011 [Define to 1 if your `struct stat' has `st_rdev'.
1012 Deprecated, use `HAVE_STRUCT_STAT_ST_RDEV'
1014 ], [your code should no longer depend upon `HAVE_ST_RDEV', but
1015 `HAVE_STRUCT_STAT_ST_RDEV'. Remove this warning and
1016 the `AC_DEFINE' when you adjust the code.])# AC_STRUCT_ST_RDEV
1021 # FIXME: This macro is badly named, it should be AC_CHECK_TYPE_STRUCT_TM.
1022 # Or something else, but what? AC_CHECK_TYPE_STRUCT_TM_IN_SYS_TIME?
1023 AC_DEFUN([AC_STRUCT_TM],
1024 [AC_CACHE_CHECK([whether struct tm is in sys/time.h or time.h],
1026 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
1030 int *p = &tm.tm_sec;
1032 [ac_cv_struct_tm=time.h],
1033 [ac_cv_struct_tm=sys/time.h])])
1034 if test $ac_cv_struct_tm = sys/time.h; then
1035 AC_DEFINE(TM_IN_SYS_TIME, 1,
1036 [Define to 1 if your <sys/time.h> declares `struct tm'.])
1041 # AC_STRUCT_TIMEZONE
1042 # ------------------
1043 # Figure out how to get the current timezone. If `struct tm' has a
1044 # `tm_zone' member, define `HAVE_TM_ZONE'. Otherwise, if the
1045 # external array `tzname' is found, define `HAVE_TZNAME'.
1046 AN_IDENTIFIER([tm_zone], [AC_STRUCT_TIMEZONE])
1047 AC_DEFUN([AC_STRUCT_TIMEZONE],
1048 [AC_REQUIRE([AC_STRUCT_TM])dnl
1049 AC_CHECK_MEMBERS([struct tm.tm_zone],,,[#include <sys/types.h>
1050 #include <$ac_cv_struct_tm>
1052 if test "$ac_cv_member_struct_tm_tm_zone" = yes; then
1053 AC_DEFINE(HAVE_TM_ZONE, 1,
1054 [Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
1055 `HAVE_STRUCT_TM_TM_ZONE' instead.])
1057 AC_CHECK_DECLS([tzname], , , [#include <time.h>])
1058 AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
1059 [AC_LINK_IFELSE([AC_LANG_PROGRAM(
1061 #if !HAVE_DECL_TZNAME
1062 extern char *tzname[];
1065 [[return tzname[0][0];]])],
1066 [ac_cv_var_tzname=yes],
1067 [ac_cv_var_tzname=no])])
1068 if test $ac_cv_var_tzname = yes; then
1069 AC_DEFINE(HAVE_TZNAME, 1,
1070 [Define to 1 if you don't have `tm_zone' but do have the external
1074 ])# AC_STRUCT_TIMEZONE