1# This file is part of Autoconf. -*- Autoconf -*- 2# Type related macros: existence, sizeof, and structure members. 3# 4# Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006 Free Software 5# Foundation, Inc. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2, or (at your option) 10# any later version. 11# 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. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program; if not, write to the Free Software 19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20# 02110-1301, USA. 21# 22# As a special exception, the Free Software Foundation gives unlimited 23# permission to copy, distribute and modify the configure scripts that 24# are the output of Autoconf. You need not follow the terms of the GNU 25# General Public License when using or distributing such scripts, even 26# though portions of the text of Autoconf appear in them. The GNU 27# General Public License (GPL) does govern all other use of the material 28# that constitutes the Autoconf program. 29# 30# Certain portions of the Autoconf source text are designed to be copied 31# (in certain cases, depending on the input) into the output of 32# Autoconf. We call these the "data" portions. The rest of the Autoconf 33# source text consists of comments plus executable code that decides which 34# of the data portions to output in any given case. We call these 35# comments and executable code the "non-data" portions. Autoconf never 36# copies any of the non-data portions into its output. 37# 38# This special exception to the GPL applies to versions of Autoconf 39# released by the Free Software Foundation. When you make and 40# distribute a modified version of Autoconf, you may extend this special 41# exception to the GPL to apply to your modified version as well, *unless* 42# your modified version has the potential to copy into its output some 43# of the text that was the non-data portion of the version that you started 44# with. (In other words, unless your change moves or copies text from 45# the non-data portions to the data portions.) If your modification has 46# such potential, you must delete any notice of this special exception 47# to the GPL from your modified version. 48# 49# Written by David MacKenzie, with help from 50# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor, 51# Roland McGrath, Noah Friedman, david d zuhn, and many others. 52 53 54## ---------------- ## 55## Type existence. ## 56## ---------------- ## 57 58# ---------------- # 59# General checks. # 60# ---------------- # 61 62# Up to 2.13 included, Autoconf used to provide the macro 63# 64# AC_CHECK_TYPE(TYPE, DEFAULT) 65# 66# Since, it provides another version which fits better with the other 67# AC_CHECK_ families: 68# 69# AC_CHECK_TYPE(TYPE, 70# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], 71# [INCLUDES = DEFAULT-INCLUDES]) 72# 73# In order to provide backward compatibility, the new scheme is 74# implemented as _AC_CHECK_TYPE_NEW, the old scheme as _AC_CHECK_TYPE_OLD, 75# and AC_CHECK_TYPE branches to one or the other, depending upon its 76# arguments. 77 78 79 80# _AC_CHECK_TYPE_NEW(TYPE, 81# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], 82# [INCLUDES = DEFAULT-INCLUDES]) 83# ------------------------------------------------------------ 84# Check whether the type TYPE is supported by the system, maybe via the 85# the provided includes. This macro implements the former task of 86# AC_CHECK_TYPE, with one big difference though: AC_CHECK_TYPE was 87# grepping in the headers, which, BTW, led to many problems until the 88# extended regular expression was correct and did not given false positives. 89# It turned out there are even portability issues with egrep... 90# 91# The most obvious way to check for a TYPE is just to compile a variable 92# definition: 93# 94# TYPE my_var; 95# 96# Unfortunately this does not work for const qualified types in C++, 97# where you need an initializer. So you think of 98# 99# TYPE my_var = (TYPE) 0; 100# 101# Unfortunately, again, this is not valid for some C++ classes. 102# 103# Then you look for another scheme. For instance you think of declaring 104# a function which uses a parameter of type TYPE: 105# 106# int foo (TYPE param); 107# 108# but of course you soon realize this does not make it with K&R 109# compilers. And by no ways you want to 110# 111# int foo (param) 112# TYPE param 113# { ; } 114# 115# since this time it's C++ who is not happy. 116# 117# Don't even think of the return type of a function, since K&R cries 118# there too. So you start thinking of declaring a *pointer* to this TYPE: 119# 120# TYPE *p; 121# 122# but you know fairly well that this is legal in C for aggregates which 123# are unknown (TYPE = struct does-not-exist). 124# 125# Then you think of using sizeof to make sure the TYPE is really 126# defined: 127# 128# sizeof (TYPE); 129# 130# But this succeeds if TYPE is a variable: you get the size of the 131# variable's type!!! 132# 133# This time you tell yourself the last two options *together* will make 134# it. And indeed this is the solution invented by Alexandre Oliva. 135# 136# Also note that we use 137# 138# if (sizeof (TYPE)) 139# 140# to `read' sizeof (to avoid warnings), while not depending on its type 141# (not necessarily size_t etc.). Equally, instead of defining an unused 142# variable, we just use a cast to avoid warnings from the compiler. 143# Suggested by Paul Eggert. 144# 145# Now, the next issue is that C++ disallows defining types inside casts 146# and inside `sizeof()', but we would like to allow unnamed structs, for 147# use inside AC_CHECK_SIZEOF, for example. So we create a typedef of the 148# new type. Note that this does not obviate the need for the other 149# constructs in general. 150m4_define([_AC_CHECK_TYPE_NEW], 151[AS_VAR_PUSHDEF([ac_Type], [ac_cv_type_$1])dnl 152AC_CACHE_CHECK([for $1], [ac_Type], 153[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4]) 154typedef $1 ac__type_new_;], 155[if ((ac__type_new_ *) 0) 156 return 0; 157if (sizeof (ac__type_new_)) 158 return 0;])], 159 [AS_VAR_SET([ac_Type], [yes])], 160 [AS_VAR_SET([ac_Type], [no])])]) 161AS_IF([test AS_VAR_GET([ac_Type]) = yes], [$2], [$3])[]dnl 162AS_VAR_POPDEF([ac_Type])dnl 163])# _AC_CHECK_TYPE_NEW 164 165 166# AC_CHECK_TYPES(TYPES, 167# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], 168# [INCLUDES = DEFAULT-INCLUDES]) 169# -------------------------------------------------------- 170# TYPES is an m4 list. There are no ambiguities here, we mean the newer 171# AC_CHECK_TYPE. 172AC_DEFUN([AC_CHECK_TYPES], 173[m4_foreach([AC_Type], [$1], 174 [_AC_CHECK_TYPE_NEW(AC_Type, 175 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Type), 1, 176 [Define to 1 if the system has the 177 type `]AC_Type['.]) 178$2], 179 [$3], 180 [$4])])]) 181 182 183# _AC_CHECK_TYPE_OLD(TYPE, DEFAULT) 184# --------------------------------- 185# FIXME: This is an extremely badly chosen name, since this 186# macro actually performs an AC_REPLACE_TYPE. Some day we 187# have to clean this up. 188m4_define([_AC_CHECK_TYPE_OLD], 189[_AC_CHECK_TYPE_NEW([$1],, 190 [AC_DEFINE_UNQUOTED([$1], [$2], 191 [Define to `$2' if <sys/types.h> does not define.])])dnl 192])# _AC_CHECK_TYPE_OLD 193 194 195# _AC_CHECK_TYPE_REPLACEMENT_TYPE_P(STRING) 196# ----------------------------------------- 197# Return `1' if STRING seems to be a builtin C/C++ type, i.e., if it 198# starts with `_Bool', `bool', `char', `double', `float', `int', 199# `long', `short', `signed', or `unsigned' followed by characters 200# that are defining types. 201# Because many people have used `off_t' and `size_t' too, they are added 202# for better common-useward backward compatibility. 203m4_define([_AC_CHECK_TYPE_REPLACEMENT_TYPE_P], 204[m4_bmatch([$1], 205 [^\(_Bool\|bool\|char\|double\|float\|int\|long\|short\|\(un\)?signed\|[_a-zA-Z][_a-zA-Z0-9]*_t\)[][_a-zA-Z0-9() *]*$], 206 1, 0)dnl 207])# _AC_CHECK_TYPE_REPLACEMENT_TYPE_P 208 209 210# _AC_CHECK_TYPE_MAYBE_TYPE_P(STRING) 211# ----------------------------------- 212# Return `1' if STRING looks like a C/C++ type. 213m4_define([_AC_CHECK_TYPE_MAYBE_TYPE_P], 214[m4_bmatch([$1], [^[_a-zA-Z0-9 ]+\([_a-zA-Z0-9() *]\|\[\|\]\)*$], 215 1, 0)dnl 216])# _AC_CHECK_TYPE_MAYBE_TYPE_P 217 218 219# AC_CHECK_TYPE(TYPE, DEFAULT) 220# or 221# AC_CHECK_TYPE(TYPE, 222# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], 223# [INCLUDES = DEFAULT-INCLUDES]) 224# ------------------------------------------------------- 225# 226# Dispatch respectively to _AC_CHECK_TYPE_OLD or _AC_CHECK_TYPE_NEW. 227# 1. More than two arguments => NEW 228# 2. $2 seems to be replacement type => OLD 229# See _AC_CHECK_TYPE_REPLACEMENT_TYPE_P for `replacement type'. 230# 3. $2 seems to be a type => NEW plus a warning 231# 4. default => NEW 232AC_DEFUN([AC_CHECK_TYPE], 233[m4_if($#, 3, 234 [_AC_CHECK_TYPE_NEW($@)], 235 $#, 4, 236 [_AC_CHECK_TYPE_NEW($@)], 237 _AC_CHECK_TYPE_REPLACEMENT_TYPE_P([$2]), 1, 238 [_AC_CHECK_TYPE_OLD($@)], 239 _AC_CHECK_TYPE_MAYBE_TYPE_P([$2]), 1, 240 [AC_DIAGNOSE([syntax], 241 [$0: assuming `$2' is not a type])_AC_CHECK_TYPE_NEW($@)], 242 [_AC_CHECK_TYPE_NEW($@)])[]dnl 243])# AC_CHECK_TYPE 244 245 246 247# ---------------------------- # 248# Types that must be checked. # 249# ---------------------------- # 250 251AN_IDENTIFIER([ptrdiff_t], [AC_CHECK_TYPES]) 252 253 254# ----------------- # 255# Specific checks. # 256# ----------------- # 257 258# AC_TYPE_GETGROUPS 259# ----------------- 260AC_DEFUN([AC_TYPE_GETGROUPS], 261[AC_REQUIRE([AC_TYPE_UID_T])dnl 262AC_CACHE_CHECK(type of array argument to getgroups, ac_cv_type_getgroups, 263[AC_RUN_IFELSE([AC_LANG_SOURCE( 264[[/* Thanks to Mike Rendell for this test. */ 265]AC_INCLUDES_DEFAULT[ 266#define NGID 256 267#undef MAX 268#define MAX(x, y) ((x) > (y) ? (x) : (y)) 269 270int 271main () 272{ 273 gid_t gidset[NGID]; 274 int i, n; 275 union { gid_t gval; long int lval; } val; 276 277 val.lval = -1; 278 for (i = 0; i < NGID; i++) 279 gidset[i] = val.gval; 280 n = getgroups (sizeof (gidset) / MAX (sizeof (int), sizeof (gid_t)) - 1, 281 gidset); 282 /* Exit non-zero if getgroups seems to require an array of ints. This 283 happens when gid_t is short int but getgroups modifies an array 284 of ints. */ 285 return n > 0 && gidset[n] != val.gval; 286}]])], 287 [ac_cv_type_getgroups=gid_t], 288 [ac_cv_type_getgroups=int], 289 [ac_cv_type_getgroups=cross]) 290if test $ac_cv_type_getgroups = cross; then 291 dnl When we can't run the test program (we are cross compiling), presume 292 dnl that <unistd.h> has either an accurate prototype for getgroups or none. 293 dnl Old systems without prototypes probably use int. 294 AC_EGREP_HEADER([getgroups.*int.*gid_t], unistd.h, 295 ac_cv_type_getgroups=gid_t, ac_cv_type_getgroups=int) 296fi]) 297AC_DEFINE_UNQUOTED(GETGROUPS_T, $ac_cv_type_getgroups, 298 [Define to the type of elements in the array set by 299 `getgroups'. Usually this is either `int' or `gid_t'.]) 300])# AC_TYPE_GETGROUPS 301 302 303# AU::AM_TYPE_PTRDIFF_T 304# --------------------- 305AU_DEFUN([AM_TYPE_PTRDIFF_T], 306[AC_CHECK_TYPES(ptrdiff_t)]) 307 308 309# AC_TYPE_INTMAX_T 310# ----------------- 311AC_DEFUN([AC_TYPE_INTMAX_T], 312[ 313 AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) 314 AC_CHECK_TYPE([intmax_t], 315 [AC_DEFINE([HAVE_INTMAX_T], 1, 316 [Define to 1 if the system has the type `intmax_t'.])], 317 [test $ac_cv_type_long_long_int = yes \ 318 && ac_type='long long int' \ 319 || ac_type='long int' 320 AC_DEFINE_UNQUOTED([intmax_t], [$ac_type], 321 [Define to the widest signed integer type 322 if <stdint.h> and <inttypes.h> do not define.])]) 323]) 324 325 326# AC_TYPE_UINTMAX_T 327# ----------------- 328AC_DEFUN([AC_TYPE_UINTMAX_T], 329[ 330 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) 331 AC_CHECK_TYPE([uintmax_t], 332 [AC_DEFINE([HAVE_UINTMAX_T], 1, 333 [Define to 1 if the system has the type `uintmax_t'.])], 334 [test $ac_cv_type_unsigned_long_long_int = yes \ 335 && ac_type='unsigned long long int' \ 336 || ac_type='unsigned long int' 337 AC_DEFINE_UNQUOTED([uintmax_t], [$ac_type], 338 [Define to the widest unsigned integer type 339 if <stdint.h> and <inttypes.h> do not define.])]) 340]) 341 342 343# AC_TYPE_INTPTR_T 344# ----------------- 345AC_DEFUN([AC_TYPE_INTPTR_T], 346[ 347 AC_CHECK_TYPE([intptr_t], 348 [AC_DEFINE([HAVE_INTPTR_T], 1, 349 [Define to 1 if the system has the type `intptr_t'.])], 350 [for ac_type in 'int' 'long int' 'long long int'; do 351 AC_COMPILE_IFELSE( 352 [AC_LANG_BOOL_COMPILE_TRY( 353 [AC_INCLUDES_DEFAULT], 354 [[sizeof (void *) <= sizeof ($ac_type)]])], 355 [AC_DEFINE_UNQUOTED([intptr_t], [$ac_type], 356 [Define to the type of a signed integer type wide enough to 357 hold a pointer, if such a type exists, and if the system 358 does not define it.]) 359 ac_type=]) 360 test -z "$ac_type" && break 361 done]) 362]) 363 364 365# AC_TYPE_UINTPTR_T 366# ----------------- 367AC_DEFUN([AC_TYPE_UINTPTR_T], 368[ 369 AC_CHECK_TYPE([uintptr_t], 370 [AC_DEFINE([HAVE_UINTPTR_T], 1, 371 [Define to 1 if the system has the type `uintptr_t'.])], 372 [for ac_type in 'unsigned int' 'unsigned long int' \ 373 'unsigned long long int'; do 374 AC_COMPILE_IFELSE( 375 [AC_LANG_BOOL_COMPILE_TRY( 376 [AC_INCLUDES_DEFAULT], 377 [[sizeof (void *) <= sizeof ($ac_type)]])], 378 [AC_DEFINE_UNQUOTED([uintptr_t], [$ac_type], 379 [Define to the type of an unsigned integer type wide enough to 380 hold a pointer, if such a type exists, and if the system 381 does not define it.]) 382 ac_type=]) 383 test -z "$ac_type" && break 384 done]) 385]) 386 387 388# AC_TYPE_LONG_DOUBLE 389# ------------------- 390AC_DEFUN([AC_TYPE_LONG_DOUBLE], 391[ 392 AC_CACHE_CHECK([for long double], [ac_cv_type_long_double], 393 [if test "$GCC" = yes; then 394 ac_cv_type_long_double=yes 395 else 396 AC_COMPILE_IFELSE( 397 [AC_LANG_BOOL_COMPILE_TRY( 398 [[/* The Stardent Vistra knows sizeof (long double), but does 399 not support it. */ 400 long double foo = 0.0L;]], 401 [[/* On Ultrix 4.3 cc, long double is 4 and double is 8. */ 402 sizeof (double) <= sizeof (long double)]])], 403 [ac_cv_type_long_double=yes], 404 [ac_cv_type_long_double=no]) 405 fi]) 406 if test $ac_cv_type_long_double = yes; then 407 AC_DEFINE([HAVE_LONG_DOUBLE], 1, 408 [Define to 1 if the system has the type `long double'.]) 409 fi 410]) 411 412 413# AC_TYPE_LONG_DOUBLE_WIDER 414# ------------------------- 415AC_DEFUN([AC_TYPE_LONG_DOUBLE_WIDER], 416[ 417 AC_CACHE_CHECK( 418 [for long double with more range or precision than double], 419 [ac_cv_type_long_double_wider], 420 [AC_COMPILE_IFELSE( 421 [AC_LANG_BOOL_COMPILE_TRY( 422 [[#include <float.h> 423 long double const a[] = 424 { 425 0.0L, DBL_MIN, DBL_MAX, DBL_EPSILON, 426 LDBL_MIN, LDBL_MAX, LDBL_EPSILON 427 }; 428 long double 429 f (long double x) 430 { 431 return ((x + (unsigned long int) 10) * (-1 / x) + a[0] 432 + (x ? f (x) : 'c')); 433 } 434 ]], 435 [[(0 < ((DBL_MAX_EXP < LDBL_MAX_EXP) 436 + (DBL_MANT_DIG < LDBL_MANT_DIG) 437 - (LDBL_MAX_EXP < DBL_MAX_EXP) 438 - (LDBL_MANT_DIG < DBL_MANT_DIG))) 439 && (int) LDBL_EPSILON == 0 440 ]])], 441 ac_cv_type_long_double_wider=yes, 442 ac_cv_type_long_double_wider=no)]) 443 if test $ac_cv_type_long_double_wider = yes; then 444 AC_DEFINE([HAVE_LONG_DOUBLE_WIDER], 1, 445 [Define to 1 if the type `long double' works and has more range or 446 precision than `double'.]) 447 fi 448])# AC_TYPE_LONG_DOUBLE_WIDER 449 450 451# AC_C_LONG_DOUBLE 452# ---------------- 453AU_DEFUN([AC_C_LONG_DOUBLE], 454 [ 455 AC_TYPE_LONG_DOUBLE_WIDER 456 ac_cv_c_long_double=$ac_cv_type_long_double_wider 457 if test $ac_cv_c_long_double = yes; then 458 AC_DEFINE([HAVE_LONG_DOUBLE], 1, 459 [Define to 1 if the type `long double' works and has more range or 460 precision than `double'.]) 461 fi 462 ], 463 [The macro `AC_C_LONG_DOUBLE' is obsolete. 464You should use `AC_TYPE_LONG_DOUBLE' or `AC_TYPE_LONG_DOUBLE_WIDER' instead.] 465) 466 467 468# AC_TYPE_LONG_LONG_INT 469# --------------------- 470AC_DEFUN([AC_TYPE_LONG_LONG_INT], 471[ 472 AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], 473 [AC_LINK_IFELSE( 474 [AC_LANG_PROGRAM( 475 [[long long int ll = 9223372036854775807ll; 476 long long int nll = -9223372036854775807LL; 477 typedef int a[((-9223372036854775807LL < 0 478 && 0 < 9223372036854775807ll) 479 ? 1 : -1)]; 480 int i = 63;]], 481 [[long long int llmax = 9223372036854775807ll; 482 return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) 483 | (llmax / ll) | (llmax % ll));]])], 484 [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. 485 dnl If cross compiling, assume the bug isn't important, since 486 dnl nobody cross compiles for this platform as far as we know. 487 AC_RUN_IFELSE( 488 [AC_LANG_PROGRAM( 489 [[@%:@include <limits.h> 490 @%:@ifndef LLONG_MAX 491 @%:@ define HALF \ 492 (1LL << (sizeof (long long int) * CHAR_BIT - 2)) 493 @%:@ define LLONG_MAX (HALF - 1 + HALF) 494 @%:@endif]], 495 [[long long int n = 1; 496 int i; 497 for (i = 0; ; i++) 498 { 499 long long int m = n << i; 500 if (m >> i != n) 501 return 1; 502 if (LLONG_MAX / 2 < m) 503 break; 504 } 505 return 0;]])], 506 [ac_cv_type_long_long_int=yes], 507 [ac_cv_type_long_long_int=no], 508 [ac_cv_type_long_long_int=yes])], 509 [ac_cv_type_long_long_int=no])]) 510 if test $ac_cv_type_long_long_int = yes; then 511 AC_DEFINE([HAVE_LONG_LONG_INT], 1, 512 [Define to 1 if the system has the type `long long int'.]) 513 fi 514]) 515 516 517# AC_TYPE_UNSIGNED_LONG_LONG_INT 518# ------------------------------ 519AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT], 520[ 521 AC_CACHE_CHECK([for unsigned long long int], 522 [ac_cv_type_unsigned_long_long_int], 523 [AC_LINK_IFELSE( 524 [AC_LANG_PROGRAM( 525 [[unsigned long long int ull = 18446744073709551615ULL; 526 typedef int a[(18446744073709551615ULL <= (unsigned long long int) -1 527 ? 1 : -1)]; 528 int i = 63;]], 529 [[unsigned long long int ullmax = 18446744073709551615ull; 530 return (ull << 63 | ull >> 63 | ull << i | ull >> i 531 | ullmax / ull | ullmax % ull);]])], 532 [ac_cv_type_unsigned_long_long_int=yes], 533 [ac_cv_type_unsigned_long_long_int=no])]) 534 if test $ac_cv_type_unsigned_long_long_int = yes; then 535 AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1, 536 [Define to 1 if the system has the type `unsigned long long int'.]) 537 fi 538]) 539 540 541# AC_TYPE_MBSTATE_T 542# ----------------- 543AC_DEFUN([AC_TYPE_MBSTATE_T], 544 [AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t, 545 [AC_COMPILE_IFELSE( 546 [AC_LANG_PROGRAM( 547 [AC_INCLUDES_DEFAULT 548# include <wchar.h>], 549 [mbstate_t x; return sizeof x;])], 550 [ac_cv_type_mbstate_t=yes], 551 [ac_cv_type_mbstate_t=no])]) 552 if test $ac_cv_type_mbstate_t = yes; then 553 AC_DEFINE([HAVE_MBSTATE_T], 1, 554 [Define to 1 if <wchar.h> declares mbstate_t.]) 555 else 556 AC_DEFINE([mbstate_t], int, 557 [Define to a type if <wchar.h> does not define.]) 558 fi]) 559 560 561# AC_TYPE_UID_T 562# ------------- 563# FIXME: Rewrite using AC_CHECK_TYPE. 564AN_IDENTIFIER([gid_t], [AC_TYPE_UID_T]) 565AN_IDENTIFIER([uid_t], [AC_TYPE_UID_T]) 566AC_DEFUN([AC_TYPE_UID_T], 567[AC_CACHE_CHECK(for uid_t in sys/types.h, ac_cv_type_uid_t, 568[AC_EGREP_HEADER(uid_t, sys/types.h, 569 ac_cv_type_uid_t=yes, ac_cv_type_uid_t=no)]) 570if test $ac_cv_type_uid_t = no; then 571 AC_DEFINE(uid_t, int, [Define to `int' if <sys/types.h> doesn't define.]) 572 AC_DEFINE(gid_t, int, [Define to `int' if <sys/types.h> doesn't define.]) 573fi 574]) 575 576 577AN_IDENTIFIER([size_t], [AC_TYPE_SIZE_T]) 578AC_DEFUN([AC_TYPE_SIZE_T], [AC_CHECK_TYPE(size_t, unsigned int)]) 579 580AN_IDENTIFIER([ssize_t], [AC_TYPE_SSIZE_T]) 581AC_DEFUN([AC_TYPE_SSIZE_T], [AC_CHECK_TYPE(ssize_t, int)]) 582 583AN_IDENTIFIER([pid_t], [AC_TYPE_PID_T]) 584AC_DEFUN([AC_TYPE_PID_T], [AC_CHECK_TYPE(pid_t, int)]) 585 586AN_IDENTIFIER([off_t], [AC_TYPE_OFF_T]) 587AC_DEFUN([AC_TYPE_OFF_T], [AC_CHECK_TYPE(off_t, long int)]) 588 589AN_IDENTIFIER([mode_t], [AC_TYPE_MODE_T]) 590AC_DEFUN([AC_TYPE_MODE_T], [AC_CHECK_TYPE(mode_t, int)]) 591 592AN_IDENTIFIER([int8_t], [AC_TYPE_INT8_T]) 593AN_IDENTIFIER([int16_t], [AC_TYPE_INT16_T]) 594AN_IDENTIFIER([int32_t], [AC_TYPE_INT32_T]) 595AN_IDENTIFIER([int64_t], [AC_TYPE_INT64_T]) 596AN_IDENTIFIER([uint8_t], [AC_TYPE_UINT8_T]) 597AN_IDENTIFIER([uint16_t], [AC_TYPE_UINT16_T]) 598AN_IDENTIFIER([uint32_t], [AC_TYPE_UINT32_T]) 599AN_IDENTIFIER([uint64_t], [AC_TYPE_UINT64_T]) 600AC_DEFUN([AC_TYPE_INT8_T], [_AC_TYPE_INT(8)]) 601AC_DEFUN([AC_TYPE_INT16_T], [_AC_TYPE_INT(16)]) 602AC_DEFUN([AC_TYPE_INT32_T], [_AC_TYPE_INT(32)]) 603AC_DEFUN([AC_TYPE_INT64_T], [_AC_TYPE_INT(64)]) 604AC_DEFUN([AC_TYPE_UINT8_T], [_AC_TYPE_UNSIGNED_INT(8)]) 605AC_DEFUN([AC_TYPE_UINT16_T], [_AC_TYPE_UNSIGNED_INT(16)]) 606AC_DEFUN([AC_TYPE_UINT32_T], [_AC_TYPE_UNSIGNED_INT(32)]) 607AC_DEFUN([AC_TYPE_UINT64_T], [_AC_TYPE_UNSIGNED_INT(64)]) 608 609# _AC_TYPE_INT(NBITS) 610# ------------------- 611AC_DEFUN([_AC_TYPE_INT], 612[ 613 AC_CACHE_CHECK([for int$1_t], [ac_cv_c_int$1_t], 614 [ac_cv_c_int$1_t=no 615 for ac_type in 'int$1_t' 'int' 'long int' \ 616 'long long int' 'short int' 'signed char'; do 617 AC_COMPILE_IFELSE( 618 [AC_LANG_BOOL_COMPILE_TRY( 619 [AC_INCLUDES_DEFAULT], 620 [[0 < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1)]])], 621 [AC_COMPILE_IFELSE( 622 [AC_LANG_BOOL_COMPILE_TRY( 623 [AC_INCLUDES_DEFAULT], 624 [[($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 1) 625 < ($ac_type) (((($ac_type) 1 << ($1 - 2)) - 1) * 2 + 2)]])], 626 [], 627 [AS_CASE([$ac_type], [int$1_t], 628 [ac_cv_c_int$1_t=yes], 629 [ac_cv_c_int$1_t=$ac_type])])]) 630 test "$ac_cv_c_int$1_t" != no && break 631 done]) 632 case $ac_cv_c_int$1_t in #( 633 no|yes) ;; #( 634 *) 635 AC_DEFINE_UNQUOTED([int$1_t], [$ac_cv_c_int$1_t], 636 [Define to the type of a signed integer type of width exactly $1 bits 637 if such a type exists and the standard includes do not define it.]);; 638 esac 639])# _AC_TYPE_INT 640 641# _AC_TYPE_UNSIGNED_INT(NBITS) 642# ---------------------------- 643AC_DEFUN([_AC_TYPE_UNSIGNED_INT], 644[ 645 AC_CACHE_CHECK([for uint$1_t], [ac_cv_c_uint$1_t], 646 [ac_cv_c_uint$1_t=no 647 for ac_type in 'uint$1_t' 'unsigned int' 'unsigned long int' \ 648 'unsigned long long int' 'unsigned short int' 'unsigned char'; do 649 AC_COMPILE_IFELSE( 650 [AC_LANG_BOOL_COMPILE_TRY( 651 [AC_INCLUDES_DEFAULT], 652 [[($ac_type) -1 >> ($1 - 1) == 1]])], 653 [AS_CASE([$ac_type], [uint$1_t], 654 [ac_cv_c_uint$1_t=yes], 655 [ac_cv_c_uint$1_t=$ac_type])]) 656 test "$ac_cv_c_uint$1_t" != no && break 657 done]) 658 case $ac_cv_c_uint$1_t in #( 659 no|yes) ;; #( 660 *) 661 m4_bmatch([$1], [^\(8\|32\|64\)$], 662 [AC_DEFINE([_UINT$1_T], 1, 663 [Define for Solaris 2.5.1 so the uint$1_t typedef from 664 <sys/synch.h>, <pthread.h>, or <semaphore.h> is not used. 665 If the typedef was allowed, the #define below would cause a 666 syntax error.])]) 667 AC_DEFINE_UNQUOTED([uint$1_t], [$ac_cv_c_uint$1_t], 668 [Define to the type of an unsigned integer type of width exactly $1 bits 669 if such a type exists and the standard includes do not define it.]);; 670 esac 671])# _AC_TYPE_UNSIGNED_INT 672 673# AC_TYPE_SIGNAL 674# -------------- 675# Note that identifiers starting with SIG are reserved by ANSI C. 676AN_FUNCTION([signal], [AC_TYPE_SIGNAL]) 677AC_DEFUN([AC_TYPE_SIGNAL], 678[AC_CACHE_CHECK([return type of signal handlers], ac_cv_type_signal, 679[AC_COMPILE_IFELSE( 680[AC_LANG_PROGRAM([#include <sys/types.h> 681#include <signal.h> 682], 683 [return *(signal (0, 0)) (0) == 1;])], 684 [ac_cv_type_signal=int], 685 [ac_cv_type_signal=void])]) 686AC_DEFINE_UNQUOTED(RETSIGTYPE, $ac_cv_type_signal, 687 [Define as the return type of signal handlers 688 (`int' or `void').]) 689]) 690 691 692## ------------------------ ## 693## Checking size of types. ## 694## ------------------------ ## 695 696# ---------------- # 697# Generic checks. # 698# ---------------- # 699 700 701# AC_CHECK_SIZEOF(TYPE, [IGNORED], [INCLUDES = DEFAULT-INCLUDES]) 702# --------------------------------------------------------------- 703AC_DEFUN([AC_CHECK_SIZEOF], 704[AS_LITERAL_IF([$1], [], 705 [AC_FATAL([$0: requires literal arguments])])dnl 706AC_CHECK_TYPE([$1], [], [], [$3]) 707# The cast to long int works around a bug in the HP C Compiler 708# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects 709# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. 710# This bug is HP SR number 8606223364. 711_AC_CACHE_CHECK_INT([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])], 712 [(long int) (sizeof (ac__type_sizeof_))], 713 [AC_INCLUDES_DEFAULT([$3]) 714 typedef $1 ac__type_sizeof_;], 715 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then 716 AC_MSG_FAILURE([cannot compute sizeof ($1)], 77) 717 else 718 AS_TR_SH([ac_cv_sizeof_$1])=0 719 fi]) 720 721AC_DEFINE_UNQUOTED(AS_TR_CPP(sizeof_$1), $AS_TR_SH([ac_cv_sizeof_$1]), 722 [The size of `$1', as computed by sizeof.]) 723])# AC_CHECK_SIZEOF 724 725 726# AC_CHECK_ALIGNOF(TYPE, [INCLUDES = DEFAULT-INCLUDES]) 727# ----------------------------------------------------- 728AC_DEFUN([AC_CHECK_ALIGNOF], 729[AS_LITERAL_IF([$1], [], 730 [AC_FATAL([$0: requires literal arguments])])dnl 731AC_CHECK_TYPE([$1], [], [], [$2]) 732# The cast to long int works around a bug in the HP C Compiler, 733# see AC_CHECK_SIZEOF for more information. 734_AC_CACHE_CHECK_INT([alignment of $1], [AS_TR_SH([ac_cv_alignof_$1])], 735 [(long int) offsetof (ac__type_alignof_, y)], 736 [AC_INCLUDES_DEFAULT([$2]) 737#ifndef offsetof 738# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0) 739#endif 740typedef struct { char x; $1 y; } ac__type_alignof_;], 741 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then 742 AC_MSG_FAILURE([cannot compute alignment of $1], 77) 743 else 744 AS_TR_SH([ac_cv_alignof_$1])=0 745 fi]) 746 747AC_DEFINE_UNQUOTED(AS_TR_CPP(alignof_$1), $AS_TR_SH([ac_cv_alignof_$1]), 748 [The normal alignment of `$1', in bytes.]) 749])# AC_CHECK_ALIGNOF 750 751 752# AU::AC_INT_16_BITS 753# ------------------ 754# What a great name :) 755AU_DEFUN([AC_INT_16_BITS], 756[AC_CHECK_SIZEOF([int]) 757test $ac_cv_sizeof_int = 2 && 758 AC_DEFINE(INT_16_BITS, 1, 759 [Define to 1 if `sizeof (int)' = 2. Obsolete, use `SIZEOF_INT'.]) 760], [your code should no longer depend upon `INT_16_BITS', but upon 761`SIZEOF_INT == 2'. Remove this warning and the `AC_DEFINE' when you 762adjust the code.]) 763 764 765# AU::AC_LONG_64_BITS 766# ------------------- 767AU_DEFUN([AC_LONG_64_BITS], 768[AC_CHECK_SIZEOF([long int]) 769test $ac_cv_sizeof_long_int = 8 && 770 AC_DEFINE(LONG_64_BITS, 1, 771 [Define to 1 if `sizeof (long int)' = 8. Obsolete, use 772 `SIZEOF_LONG_INT'.]) 773], [your code should no longer depend upon `LONG_64_BITS', but upon 774`SIZEOF_LONG_INT == 8'. Remove this warning and the `AC_DEFINE' when 775you adjust the code.]) 776 777 778 779## -------------------------- ## 780## Generic structure checks. ## 781## -------------------------- ## 782 783 784# ---------------- # 785# Generic checks. # 786# ---------------- # 787 788# AC_CHECK_MEMBER(AGGREGATE.MEMBER, 789# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], 790# [INCLUDES = DEFAULT-INCLUDES]) 791# --------------------------------------------------------- 792# AGGREGATE.MEMBER is for instance `struct passwd.pw_gecos', shell 793# variables are not a valid argument. 794AC_DEFUN([AC_CHECK_MEMBER], 795[AS_LITERAL_IF([$1], [], 796 [AC_FATAL([$0: requires literal arguments])])dnl 797m4_bmatch([$1], [\.], , 798 [m4_fatal([$0: Did not see any dot in `$1'])])dnl 799AS_VAR_PUSHDEF([ac_Member], [ac_cv_member_$1])dnl 800dnl Extract the aggregate name, and the member name 801AC_CACHE_CHECK([for $1], [ac_Member], 802[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])], 803[dnl AGGREGATE ac_aggr; 804static m4_bpatsubst([$1], [\..*]) ac_aggr; 805dnl ac_aggr.MEMBER; 806if (ac_aggr.m4_bpatsubst([$1], [^[^.]*\.])) 807return 0;])], 808 [AS_VAR_SET([ac_Member], [yes])], 809[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])], 810[dnl AGGREGATE ac_aggr; 811static m4_bpatsubst([$1], [\..*]) ac_aggr; 812dnl sizeof ac_aggr.MEMBER; 813if (sizeof ac_aggr.m4_bpatsubst([$1], [^[^.]*\.])) 814return 0;])], 815 [AS_VAR_SET([ac_Member], [yes])], 816 [AS_VAR_SET([ac_Member], [no])])])]) 817AS_IF([test AS_VAR_GET([ac_Member]) = yes], [$2], [$3])dnl 818AS_VAR_POPDEF([ac_Member])dnl 819])# AC_CHECK_MEMBER 820 821 822# AC_CHECK_MEMBERS([AGGREGATE.MEMBER, ...], 823# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND] 824# [INCLUDES = DEFAULT-INCLUDES]) 825# --------------------------------------------------------- 826# The first argument is an m4 list. 827AC_DEFUN([AC_CHECK_MEMBERS], 828[m4_foreach([AC_Member], [$1], 829 [AC_CHECK_MEMBER(AC_Member, 830 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Member), 1, 831 [Define to 1 if `]m4_bpatsubst(AC_Member, 832 [^[^.]*\.])[' is 833 member of `]m4_bpatsubst(AC_Member, [\..*])['.]) 834$2], 835 [$3], 836 [$4])])]) 837 838 839 840# ------------------------------------------------------- # 841# Members that ought to be tested with AC_CHECK_MEMBERS. # 842# ------------------------------------------------------- # 843 844AN_IDENTIFIER([st_blksize], [AC_CHECK_MEMBERS([struct stat.st_blksize])]) 845AN_IDENTIFIER([st_rdev], [AC_CHECK_MEMBERS([struct stat.st_rdev])]) 846 847 848# Alphabetic order, please. 849 850# _AC_STRUCT_DIRENT(MEMBER) 851# ------------------------- 852AC_DEFUN([_AC_STRUCT_DIRENT], 853[ 854 AC_REQUIRE([AC_HEADER_DIRENT]) 855 AC_CHECK_MEMBERS([struct dirent.$1], [], [], 856 [[ 857#include <sys/types.h> 858#ifdef HAVE_DIRENT_H 859# include <dirent.h> 860#else 861# define dirent direct 862# ifdef HAVE_SYS_NDIR_H 863# include <sys/ndir.h> 864# endif 865# ifdef HAVE_SYS_DIR_H 866# include <sys/dir.h> 867# endif 868# ifdef HAVE_NDIR_H 869# include <ndir.h> 870# endif 871#endif 872 ]]) 873]) 874 875# AC_STRUCT_DIRENT_D_INO 876# ----------------------------------- 877AC_DEFUN([AC_STRUCT_DIRENT_D_INO], [_AC_STRUCT_DIRENT([d_ino])]) 878 879# AC_STRUCT_DIRENT_D_TYPE 880# ------------------------------------ 881AC_DEFUN([AC_STRUCT_DIRENT_D_TYPE], [_AC_STRUCT_DIRENT([d_type])]) 882 883 884# AC_STRUCT_ST_BLKSIZE 885# -------------------- 886AU_DEFUN([AC_STRUCT_ST_BLKSIZE], 887[AC_CHECK_MEMBERS([struct stat.st_blksize], 888 [AC_DEFINE(HAVE_ST_BLKSIZE, 1, 889 [Define to 1 if your `struct stat' has 890 `st_blksize'. Deprecated, use 891 `HAVE_STRUCT_STAT_ST_BLKSIZE' instead.])]) 892], [your code should no longer depend upon `HAVE_ST_BLKSIZE', but 893`HAVE_STRUCT_STAT_ST_BLKSIZE'. Remove this warning and 894the `AC_DEFINE' when you adjust the code.])# AC_STRUCT_ST_BLKSIZE 895 896 897# AC_STRUCT_ST_BLOCKS 898# ------------------- 899# If `struct stat' contains an `st_blocks' member, define 900# HAVE_STRUCT_STAT_ST_BLOCKS. Otherwise, add `fileblocks.o' to the 901# output variable LIBOBJS. We still define HAVE_ST_BLOCKS for backward 902# compatibility. In the future, we will activate specializations for 903# this macro, so don't obsolete it right now. 904# 905# AC_OBSOLETE([$0], [; replace it with 906# AC_CHECK_MEMBERS([struct stat.st_blocks], 907# [AC_LIBOBJ([fileblocks])]) 908# Please note that it will define `HAVE_STRUCT_STAT_ST_BLOCKS', 909# and not `HAVE_ST_BLOCKS'.])dnl 910# 911AN_IDENTIFIER([st_blocks], [AC_STRUCT_ST_BLOCKS]) 912AC_DEFUN([AC_STRUCT_ST_BLOCKS], 913[AC_CHECK_MEMBERS([struct stat.st_blocks], 914 [AC_DEFINE(HAVE_ST_BLOCKS, 1, 915 [Define to 1 if your `struct stat' has 916 `st_blocks'. Deprecated, use 917 `HAVE_STRUCT_STAT_ST_BLOCKS' instead.])], 918 [AC_LIBOBJ([fileblocks])]) 919])# AC_STRUCT_ST_BLOCKS 920 921 922# AC_STRUCT_ST_RDEV 923# ----------------- 924AU_DEFUN([AC_STRUCT_ST_RDEV], 925[AC_CHECK_MEMBERS([struct stat.st_rdev], 926 [AC_DEFINE(HAVE_ST_RDEV, 1, 927 [Define to 1 if your `struct stat' has `st_rdev'. 928 Deprecated, use `HAVE_STRUCT_STAT_ST_RDEV' 929 instead.])]) 930], [your code should no longer depend upon `HAVE_ST_RDEV', but 931`HAVE_STRUCT_STAT_ST_RDEV'. Remove this warning and 932the `AC_DEFINE' when you adjust the code.])# AC_STRUCT_ST_RDEV 933 934 935# AC_STRUCT_TM 936# ------------ 937# FIXME: This macro is badly named, it should be AC_CHECK_TYPE_STRUCT_TM. 938# Or something else, but what? AC_CHECK_TYPE_STRUCT_TM_IN_SYS_TIME? 939AN_IDENTIFIER([tm], [AC_STRUCT_TM]) 940AC_DEFUN([AC_STRUCT_TM], 941[AC_CACHE_CHECK([whether struct tm is in sys/time.h or time.h], 942 ac_cv_struct_tm, 943[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h> 944#include <time.h> 945], 946 [struct tm tm; 947 int *p = &tm.tm_sec; 948 return !p;])], 949 [ac_cv_struct_tm=time.h], 950 [ac_cv_struct_tm=sys/time.h])]) 951if test $ac_cv_struct_tm = sys/time.h; then 952 AC_DEFINE(TM_IN_SYS_TIME, 1, 953 [Define to 1 if your <sys/time.h> declares `struct tm'.]) 954fi 955])# AC_STRUCT_TM 956 957 958# AC_STRUCT_TIMEZONE 959# ------------------ 960# Figure out how to get the current timezone. If `struct tm' has a 961# `tm_zone' member, define `HAVE_TM_ZONE'. Otherwise, if the 962# external array `tzname' is found, define `HAVE_TZNAME'. 963AN_IDENTIFIER([tm_zone], [AC_STRUCT_TIMEZONE]) 964AC_DEFUN([AC_STRUCT_TIMEZONE], 965[AC_REQUIRE([AC_STRUCT_TM])dnl 966AC_CHECK_MEMBERS([struct tm.tm_zone],,,[#include <sys/types.h> 967#include <$ac_cv_struct_tm> 968]) 969if test "$ac_cv_member_struct_tm_tm_zone" = yes; then 970 AC_DEFINE(HAVE_TM_ZONE, 1, 971 [Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use 972 `HAVE_STRUCT_TM_TM_ZONE' instead.]) 973else 974 AC_CHECK_DECLS([tzname], , , [#include <time.h>]) 975 AC_CACHE_CHECK(for tzname, ac_cv_var_tzname, 976[AC_LINK_IFELSE([AC_LANG_PROGRAM( 977[[#include <time.h> 978#if !HAVE_DECL_TZNAME 979extern char *tzname[]; 980#endif 981]], 982[[return tzname[0][0];]])], 983 [ac_cv_var_tzname=yes], 984 [ac_cv_var_tzname=no])]) 985 if test $ac_cv_var_tzname = yes; then 986 AC_DEFINE(HAVE_TZNAME, 1, 987 [Define to 1 if you don't have `tm_zone' but do have the external 988 array `tzname'.]) 989 fi 990fi 991])# AC_STRUCT_TIMEZONE 992