1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Type related macros: existence, sizeof, and structure members.
4 # Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # As a special exception, the Free Software Foundation gives unlimited
22 # permission to copy, distribute and modify the configure scripts that
23 # are the output of Autoconf. You need not follow the terms of the GNU
24 # General Public License when using or distributing such scripts, even
25 # though portions of the text of Autoconf appear in them. The GNU
26 # General Public License (GPL) does govern all other use of the material
27 # that constitutes the Autoconf program.
29 # Certain portions of the Autoconf source text are designed to be copied
30 # (in certain cases, depending on the input) into the output of
31 # Autoconf. We call these the "data" portions. The rest of the Autoconf
32 # source text consists of comments plus executable code that decides which
33 # of the data portions to output in any given case. We call these
34 # comments and executable code the "non-data" portions. Autoconf never
35 # copies any of the non-data portions into its output.
37 # This special exception to the GPL applies to versions of Autoconf
38 # released by the Free Software Foundation. When you make and
39 # distribute a modified version of Autoconf, you may extend this special
40 # exception to the GPL to apply to your modified version as well, *unless*
41 # your modified version has the potential to copy into its output some
42 # of the text that was the non-data portion of the version that you started
43 # with. (In other words, unless your change moves or copies text from
44 # the non-data portions to the data portions.) If your modification has
45 # such potential, you must delete any notice of this special exception
46 # to the GPL from your modified version.
48 # Written by David MacKenzie, with help from
49 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
50 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
53 ## ---------------- ##
55 ## ---------------- ##
61 # Up to 2.13 included, Autoconf used to provide the macro
63 # AC_CHECK_TYPE(TYPE, DEFAULT)
65 # Since, it provides another version which fits better with the other
69 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
72 # In order to provide backward compatibility, the new scheme is
73 # implemented as _AC_CHECK_TYPE_NEW, the old scheme as _AC_CHECK_TYPE_OLD,
74 # and AC_CHECK_TYPE branches to one or the other, depending upon its
79 # _AC_CHECK_TYPE_NEW(TYPE,
80 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
82 # ------------------------------------------------------------
83 # Check whether the type TYPE is supported by the system, maybe via the
84 # the provided includes. This macro implements the former task of
85 # AC_CHECK_TYPE, with one big difference though: AC_CHECK_TYPE was
86 # grepping in the headers, which, BTW, led to many problems until
87 # the egrep expression was correct and did not given false positives.
88 # It turned out there are even portability issues with egrep...
90 # The most obvious way to check for a TYPE is just to compile a variable
95 # Unfortunately this does not work for const qualified types in C++,
96 # where you need an initializer. So you think of
98 # TYPE my_var = (TYPE) 0;
100 # Unfortunately, again, this is not valid for some C++ classes.
102 # Then you look for another scheme. For instance you think of declaring
103 # a function which uses a parameter of type TYPE:
105 # int foo (TYPE param);
107 # but of course you soon realize this does not make it with K&R
108 # compilers. And by no ways you want to
114 # since this time it's C++ who is not happy.
116 # Don't even think of the return type of a function, since K&R cries
117 # there too. So you start thinking of declaring a *pointer* to this TYPE:
121 # but you know fairly well that this is legal in C for aggregates which
122 # are unknown (TYPE = struct does-not-exist).
124 # Then you think of using sizeof to make sure the TYPE is really
129 # But this succeeds if TYPE is a variable: you get the size of the
132 # This time you tell yourself the last two options *together* will make
133 # it. And indeed this is the solution invented by Alexandre Oliva.
135 # Also note that we use
139 # to `read' sizeof (to avoid warnings), while not depending on its type
140 # (not necessarily size_t etc.). Equally, instead of defining an unused
141 # variable, we just use a cast to avoid warnings from the compiler.
142 # Suggested by Paul Eggert.
143 m4_define([_AC_CHECK_TYPE_NEW],
144 [AS_VAR_PUSHDEF([ac_Type], [ac_cv_type_$1])dnl
145 AC_CACHE_CHECK([for $1], ac_Type,
146 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
151 [AS_VAR_SET(ac_Type, yes)],
152 [AS_VAR_SET(ac_Type, no)])])
153 AS_IF([test AS_VAR_GET(ac_Type) = yes], [$2], [$3])[]dnl
154 AS_VAR_POPDEF([ac_Type])dnl
155 ])# _AC_CHECK_TYPE_NEW
158 # AC_CHECK_TYPES(TYPES,
159 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
161 # --------------------------------------------------------
162 # TYPES is an m4 list. There are no ambiguities here, we mean the newer
164 AC_DEFUN([AC_CHECK_TYPES],
165 [m4_foreach([AC_Type], [$1],
166 [_AC_CHECK_TYPE_NEW(AC_Type,
167 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Type), 1,
168 [Define if the system has the type
175 # _AC_CHECK_TYPE_OLD(TYPE, DEFAULT)
176 # ---------------------------------
177 # FIXME: This is an extremely badly chosen name, since this
178 # macro actually performs an AC_REPLACE_TYPE. Some day we
179 # have to clean this up.
180 m4_define([_AC_CHECK_TYPE_OLD],
181 [_AC_CHECK_TYPE_NEW([$1],,
182 [AC_DEFINE_UNQUOTED([$1], [$2],
183 [Define to `$2' if <sys/types.h> does not define.])])dnl
184 ])# _AC_CHECK_TYPE_OLD
187 # _AC_CHECK_TYPE_REPLACEMENT_TYPE_P(STRING)
188 # -----------------------------------------
189 # Return `1' if STRING seems to be a builtin C/C++ type, i.e., if it
190 # starts with `_Bool', `bool', `char', `double', `float', `int',
191 # `long', `short', `signed', or `unsigned' followed by characters
192 # that are defining types.
193 # Because many people have used `off_t' and `size_t' too, they are added
194 # for better common-useward backward compatibility.
195 m4_define([_AC_CHECK_TYPE_REPLACEMENT_TYPE_P],
196 [m4_if(m4_regexp([$1],
197 [^\(_Bool\|bool\|char\|double\|float\|int\|long\|short\|\(un\)?signed\|[_a-zA-Z][_a-zA-Z0-9]*_t\)[][_a-zA-Z0-9() *]*$]),
199 ])# _AC_CHECK_TYPE_REPLACEMENT_TYPE_P
202 # _AC_CHECK_TYPE_MAYBE_TYPE_P(STRING)
203 # -----------------------------------
204 # Return `1' if STRING looks like a C/C++ type.
205 m4_define([_AC_CHECK_TYPE_MAYBE_TYPE_P],
206 [m4_if(m4_regexp([$1], [^[_a-zA-Z0-9 ]+\([_a-zA-Z0-9() *]\|\[\|\]\)*$]),
208 ])# _AC_CHECK_TYPE_MAYBE_TYPE_P
211 # AC_CHECK_TYPE(TYPE, DEFAULT)
213 # AC_CHECK_TYPE(TYPE,
214 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
216 # -------------------------------------------------------
218 # Dispatch respectively to _AC_CHECK_TYPE_OLD or _AC_CHECK_TYPE_NEW.
219 # 1. More than two arguments => NEW
220 # 2. $2 seems to be replacement type => OLD
221 # See _AC_CHECK_TYPE_REPLACEMENT_TYPE_P for `replacement type'.
222 # 3. $2 seems to be a type => NEW plus a warning
224 AC_DEFUN([AC_CHECK_TYPE],
226 [_AC_CHECK_TYPE_NEW($@)],
228 [_AC_CHECK_TYPE_NEW($@)],
229 _AC_CHECK_TYPE_REPLACEMENT_TYPE_P([$2]), 1,
230 [_AC_CHECK_TYPE_OLD($@)],
231 _AC_CHECK_TYPE_MAYBE_TYPE_P([$2]), 1,
232 [AC_DIAGNOSE([syntax],
233 [$0: assuming `$2' is not a type])_AC_CHECK_TYPE_NEW($@)],
234 [_AC_CHECK_TYPE_NEW($@)])[]dnl
239 # ----------------- #
241 # ----------------- #
245 AC_DEFUN([AC_TYPE_GETGROUPS],
246 [AC_REQUIRE([AC_TYPE_UID_T])dnl
247 AC_CACHE_CHECK(type of array argument to getgroups, ac_cv_type_getgroups,
248 [AC_RUN_IFELSE([AC_LANG_SOURCE(
249 [[/* Thanks to Mike Rendell for this test. */
250 #include <sys/types.h>
253 #define MAX(x, y) ((x) > (y) ? (x) : (y))
260 union { gid_t gval; long lval; } val;
263 for (i = 0; i < NGID; i++)
264 gidset[i] = val.gval;
265 n = getgroups (sizeof (gidset) / MAX (sizeof (int), sizeof (gid_t)) - 1,
267 /* Exit non-zero if getgroups seems to require an array of ints. This
268 happens when gid_t is short but getgroups modifies an array of ints. */
269 exit ((n > 0 && gidset[n] != val.gval) ? 1 : 0);
271 [ac_cv_type_getgroups=gid_t],
272 [ac_cv_type_getgroups=int],
273 [ac_cv_type_getgroups=cross])
274 if test $ac_cv_type_getgroups = cross; then
275 dnl When we can't run the test program (we are cross compiling), presume
276 dnl that <unistd.h> has either an accurate prototype for getgroups or none.
277 dnl Old systems without prototypes probably use int.
278 AC_EGREP_HEADER([getgroups.*int.*gid_t], unistd.h,
279 ac_cv_type_getgroups=gid_t, ac_cv_type_getgroups=int)
281 AC_DEFINE_UNQUOTED(GETGROUPS_T, $ac_cv_type_getgroups,
282 [Define to the type of elements in the array set by
283 `getgroups'. Usually this is either `int' or `gid_t'.])
284 ])# AC_TYPE_GETGROUPS
287 # AU::AM_TYPE_PTRDIFF_T
288 AU_DEFUN([AM_TYPE_PTRDIFF_T],
289 [AC_CHECK_TYPES(ptrdiff_t)])
294 # FIXME: Rewrite using AC_CHECK_TYPE.
295 AC_DEFUN([AC_TYPE_UID_T],
296 [AC_CACHE_CHECK(for uid_t in sys/types.h, ac_cv_type_uid_t,
297 [AC_EGREP_HEADER(uid_t, sys/types.h,
298 ac_cv_type_uid_t=yes, ac_cv_type_uid_t=no)])
299 if test $ac_cv_type_uid_t = no; then
300 AC_DEFINE(uid_t, int, [Define to `int' if <sys/types.h> doesn't define.])
301 AC_DEFINE(gid_t, int, [Define to `int' if <sys/types.h> doesn't define.])
306 AC_DEFUN([AC_TYPE_SIZE_T], [AC_CHECK_TYPE(size_t, unsigned)])
307 AC_DEFUN([AC_TYPE_PID_T], [AC_CHECK_TYPE(pid_t, int)])
308 AC_DEFUN([AC_TYPE_OFF_T], [AC_CHECK_TYPE(off_t, long)])
309 AC_DEFUN([AC_TYPE_MODE_T], [AC_CHECK_TYPE(mode_t, int)])
314 # Note that identifiers starting with SIG are reserved by ANSI C.
315 AC_DEFUN([AC_TYPE_SIGNAL],
316 [AC_CACHE_CHECK([return type of signal handlers], ac_cv_type_signal,
318 [AC_LANG_PROGRAM([#include <sys/types.h>
324 extern "C" void (*signal (int, void (*)(int)))(int);
326 void (*signal ()) ();
330 [ac_cv_type_signal=void],
331 [ac_cv_type_signal=int])])
332 AC_DEFINE_UNQUOTED(RETSIGTYPE, $ac_cv_type_signal,
333 [Define as the return type of signal handlers
338 ## ------------------------ ##
339 ## Checking size of types. ##
340 ## ------------------------ ##
347 # AC_CHECK_SIZEOF(TYPE, [IGNORED], [INCLUDES])
348 # --------------------------------------------
349 AC_DEFUN([AC_CHECK_SIZEOF],
350 [AS_LITERAL_IF([$1], [],
351 [AC_FATAL([$0: requires literal arguments])])dnl
352 AC_CHECK_TYPE([$1], [], [], [$3])
353 AC_CACHE_CHECK([size of $1], AS_TR_SH([ac_cv_sizeof_$1]),
354 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
355 _AC_COMPUTE_INT([sizeof ($1)],
356 [AS_TR_SH([ac_cv_sizeof_$1])],
357 [AC_INCLUDES_DEFAULT([$3])])
359 AS_TR_SH([ac_cv_sizeof_$1])=0
361 AC_DEFINE_UNQUOTED(AS_TR_CPP(sizeof_$1), $AS_TR_SH([ac_cv_sizeof_$1]),
362 [The size of a `$1', as computed by sizeof.])
373 # What a great name :)
374 AU_DEFUN([AC_INT_16_BITS],
375 [AC_CHECK_SIZEOF([int])
376 AC_DIAGNOSE([obsolete], [$0:
377 your code should no longer depend upon `INT_16_BITS', but upon
378 `SIZEOF_INT'. Remove this warning and the `AC_DEFINE' when you
379 adjust the code.])dnl
380 test $ac_cv_sizeof_int = 2 &&
381 AC_DEFINE(INT_16_BITS, 1,
382 [Define if `sizeof (int)' = 2. Obsolete, use `SIZEOF_INT'.])
386 # AU::AC_LONG_64_BITS
387 # -------------------
388 AU_DEFUN([AC_LONG_64_BITS],
389 [AC_CHECK_SIZEOF([long int])
390 AC_DIAGNOSE([obsolete], [$0:
391 your code should no longer depend upon `LONG_64_BITS', but upon
392 `SIZEOF_LONG_INT'. Remove this warning and the `AC_DEFINE' when
393 you adjust the code.])dnl
394 test $ac_cv_sizeof_long_int = 8 &&
395 AC_DEFINE(LONG_64_BITS, 1,
396 [Define if `sizeof (long int)' = 8. Obsolete, use
402 ## -------------------------- ##
403 ## Generic structure checks. ##
404 ## -------------------------- ##
411 # AC_CHECK_MEMBER(AGGREGATE.MEMBER,
412 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
414 # ---------------------------------------------------------
415 # AGGREGATE.MEMBER is for instance `struct passwd.pw_gecos', shell
416 # variables are not a valid argument.
417 AC_DEFUN([AC_CHECK_MEMBER],
418 [AS_LITERAL_IF([$1], [],
419 [AC_FATAL([$0: requires literal arguments])])dnl
420 m4_if(m4_regexp([$1], [\.]), -1,
421 [AC_FATAL([$0: Did not see any dot in `$1'])])dnl
422 AS_VAR_PUSHDEF([ac_Member], [ac_cv_member_$1])dnl
423 dnl Extract the aggregate name, and the member name
424 AC_CACHE_CHECK([for $1], ac_Member,
425 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
426 [dnl AGGREGATE ac_aggr;
427 static m4_patsubst([$1], [\..*]) ac_aggr;
429 if (ac_aggr.m4_patsubst([$1], [^[^.]*\.]))
431 [AS_VAR_SET(ac_Member, yes)],
432 [AS_VAR_SET(ac_Member, no)])])
433 AS_IF([test AS_VAR_GET(ac_Member) = yes], [$2], [$3])dnl
434 AS_VAR_POPDEF([ac_Member])dnl
438 # AC_CHECK_MEMBERS([AGGREGATE.MEMBER, ...],
439 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]
441 # ---------------------------------------------------------
442 # The first argument is an m4 list.
443 AC_DEFUN([AC_CHECK_MEMBERS],
444 [m4_foreach([AC_Member], [$1],
445 [AC_CHECK_MEMBER(AC_Member,
446 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Member), 1,
447 [Define if `]m4_patsubst(AC_Member,
449 member of `]m4_patsubst(AC_Member, [\..*])['.])
455 # ----------------- #
457 # ----------------- #
459 # Alphabetic order, please.
461 # AC_STRUCT_ST_BLKSIZE
462 # --------------------
463 AU_DEFUN([AC_STRUCT_ST_BLKSIZE],
464 [AC_DIAGNOSE([obsolete], [$0:
465 your code should no longer depend upon `HAVE_ST_BLKSIZE', but
466 `HAVE_STRUCT_STAT_ST_BLKSIZE'. Remove this warning and
467 the `AC_DEFINE' when you adjust the code.])
468 AC_CHECK_MEMBERS([struct stat.st_blksize],
469 [AC_DEFINE(HAVE_ST_BLKSIZE, 1,
470 [Define if your `struct stat' has
471 `st_blksize'. Deprecated, use
472 `HAVE_STRUCT_STAT_ST_BLKSIZE' instead.])])
473 ])# AC_STRUCT_ST_BLKSIZE
476 # AC_STRUCT_ST_BLOCKS
477 # -------------------
478 # If `struct stat' contains an `st_blocks' member, define
479 # HAVE_STRUCT_STAT_ST_BLOCKS. Otherwise, add `fileblocks.o' to the
480 # output variable LIBOBJS. We still define HAVE_ST_BLOCKS for backward
481 # compatibility. In the future, we will activate specializations for
482 # this macro, so don't obsolete it right now.
484 # AC_OBSOLETE([$0], [; replace it with
485 # AC_CHECK_MEMBERS([struct stat.st_blocks],
486 # [AC_LIBOBJ([fileblocks])])
487 # Please note that it will define `HAVE_STRUCT_STAT_ST_BLOCKS',
488 # and not `HAVE_ST_BLOCKS'.])dnl
490 AC_DEFUN([AC_STRUCT_ST_BLOCKS],
491 [AC_CHECK_MEMBERS([struct stat.st_blocks],
492 [AC_DEFINE(HAVE_ST_BLOCKS, 1,
493 [Define if your `struct stat' has
494 `st_blocks'. Deprecated, use
495 `HAVE_STRUCT_STAT_ST_BLOCKS' instead.])],
496 [AC_LIBOBJ([fileblocks])])
497 ])# AC_STRUCT_ST_BLOCKS
502 AU_DEFUN([AC_STRUCT_ST_RDEV],
503 [AC_DIAGNOSE([obsolete], [$0:
504 your code should no longer depend upon `HAVE_ST_RDEV', but
505 `HAVE_STRUCT_STAT_ST_RDEV'. Remove this warning and
506 the `AC_DEFINE' when you adjust the code.])
507 AC_CHECK_MEMBERS([struct stat.st_rdev],
508 [AC_DEFINE(HAVE_ST_RDEV, 1,
509 [Define if your `struct stat' has `st_rdev'.
510 Deprecated, use `HAVE_STRUCT_STAT_ST_RDEV'
512 ])# AC_STRUCT_ST_RDEV
517 # FIXME: This macro is badly named, it should be AC_CHECK_TYPE_STRUCT_TM.
518 # Or something else, but what? AC_CHECK_TYPE_STRUCT_TM_IN_SYS_TIME?
519 AC_DEFUN([AC_STRUCT_TM],
520 [AC_CACHE_CHECK([whether struct tm is in sys/time.h or time.h],
522 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
525 [struct tm *tp; tp->tm_sec;])],
526 [ac_cv_struct_tm=time.h],
527 [ac_cv_struct_tm=sys/time.h])])
528 if test $ac_cv_struct_tm = sys/time.h; then
529 AC_DEFINE(TM_IN_SYS_TIME, 1,
530 [Define if your <sys/time.h> declares `struct tm'.])
537 # Figure out how to get the current timezone. If `struct tm' has a
538 # `tm_zone' member, define `HAVE_TM_ZONE'. Otherwise, if the
539 # external array `tzname' is found, define `HAVE_TZNAME'.
540 AC_DEFUN([AC_STRUCT_TIMEZONE],
541 [AC_REQUIRE([AC_STRUCT_TM])dnl
542 AC_CHECK_MEMBERS([struct tm.tm_zone],,,[#include <sys/types.h>
543 #include <$ac_cv_struct_tm>
545 if test "$ac_cv_member_struct_tm_tm_zone" = yes; then
546 AC_DEFINE(HAVE_TM_ZONE, 1,
547 [Define if your `struct tm' has `tm_zone'. Deprecated, use
548 `HAVE_STRUCT_TM_TM_ZONE' instead.])
550 AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
553 #ifndef tzname /* For SGI. */
554 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
557 [atoi(*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)])
558 if test $ac_cv_var_tzname = yes; then
559 AC_DEFINE(HAVE_TZNAME, 1,
560 [Define if you don't have `tm_zone' but do have the external
564 ])# AC_STRUCT_TIMEZONE