1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Checking for headers.
4 # Copyright (C) 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2008,
5 # 2009 Free Software Foundation, Inc.
7 # This file is part of Autoconf. This program is free
8 # software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the
10 # Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # Under Section 7 of GPL version 3, you are granted additional
19 # permissions described in the Autoconf Configure Script Exception,
20 # version 3.0, as published by the Free Software Foundation.
22 # You should have received a copy of the GNU General Public License
23 # and a copy of the Autoconf Configure Script Exception along with
24 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
25 # respectively. If not, see <http://www.gnu.org/licenses/>.
27 # Written by David MacKenzie, with help from
28 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
29 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
34 # 1. Generic tests for headers
36 # 3. Headers to tests with AC_CHECK_HEADERS
37 # 4. Tests for specific headers
40 ## ------------------------------ ##
41 ## 1. Generic tests for headers. ##
42 ## ------------------------------ ##
45 # AC_CHECK_HEADER(HEADER-FILE,
46 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
48 # ---------------------------------------------------------
49 # We are slowly moving to checking headers with the compiler instead
50 # of the preproc, so that we actually learn about the usability of a
51 # header instead of its mere presence. But since users are used to
52 # the old semantics, they check for headers in random order and
53 # without providing prerequisite headers. This macro implements the
54 # transition phase, and should be cleaned up latter to use compilation
57 # If INCLUDES is empty, then check both via the compiler and preproc.
58 # If the results are different, issue a warning, but keep the preproc
61 # If INCLUDES is `-', keep only the old semantics.
63 # If INCLUDES is specified and different from `-', then use the new
66 # The m4_indir allows for fewer expansions of $@.
67 AC_DEFUN([AC_CHECK_HEADER],
68 [m4_indir(m4_case([$4],
69 [], [[_AC_CHECK_HEADER_MONGREL]],
70 [-], [[_AC_CHECK_HEADER_PREPROC]],
71 [[_AC_CHECK_HEADER_COMPILE]]), $@)
75 # _AC_CHECK_HEADER_MONGREL_BODY
76 # -----------------------------
77 # Shell function body for _AC_CHECK_HEADER_MONGREL
78 m4_define([_AC_CHECK_HEADER_MONGREL_BODY],
79 [ AS_LINENO_PUSH([$[]1])
81 [AC_CACHE_CHECK([for $[]2], [$[]3], [])],
82 [# Is the header compilable?
83 AC_MSG_CHECKING([$[]2 usability])
84 AC_COMPILE_IFELSE([AC_LANG_SOURCE([$[]4
85 @%:@include <$[]2>])],
86 [ac_header_compiler=yes],
87 [ac_header_compiler=no])
88 AC_MSG_RESULT([$ac_header_compiler])
90 # Is the header present?
91 AC_MSG_CHECKING([$[]2 presence])
92 AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$[]2>])],
93 [ac_header_preproc=yes],
94 [ac_header_preproc=no])
95 AC_MSG_RESULT([$ac_header_preproc])
97 # So? What about this header?
98 case $ac_header_compiler:$ac_header_preproc:$ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in #((
100 AC_MSG_WARN([$[]2: accepted by the compiler, rejected by the preprocessor!])
101 AC_MSG_WARN([$[]2: proceeding with the compiler's result])
104 AC_MSG_WARN([$[]2: present but cannot be compiled])
105 AC_MSG_WARN([$[]2: check for missing prerequisite headers?])
106 AC_MSG_WARN([$[]2: see the Autoconf documentation])
107 AC_MSG_WARN([$[]2: section "Present But Cannot Be Compiled"])
108 AC_MSG_WARN([$[]2: proceeding with the compiler's result])
109 m4_ifset([AC_PACKAGE_BUGREPORT],
110 [m4_n([( AS_BOX([Report this to ]AC_PACKAGE_BUGREPORT)
111 ) | sed "s/^/$as_me: WARNING: /" >&2])])dnl
114 AC_CACHE_CHECK([for $[]2], [$[]3],
115 [AS_VAR_SET([$[]3], [$ac_header_compiler])])])
117 ])#_AC_CHECK_HEADER_MONGREL_BODY
119 # _AC_CHECK_HEADER_MONGREL(HEADER-FILE,
120 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
121 # [INCLUDES = DEFAULT-INCLUDES])
122 # ------------------------------------------------------------------
123 # Check using both the compiler and the preprocessor. If they disagree,
124 # warn, and the preproc wins.
126 # This is not based on _AC_CHECK_HEADER_COMPILE and _AC_CHECK_HEADER_PREPROC
127 # because it obfuscate the code to try to factor everything, in particular
128 # because of the cache variables, and the `checking...' messages.
129 AC_DEFUN([_AC_CHECK_HEADER_MONGREL],
130 [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_header_mongrel],
131 [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_header_mongrel],
132 [LINENO HEADER VAR INCLUDES],
133 [Tests whether HEADER exists, giving a warning if it cannot be compiled
134 using the include files in INCLUDES and setting the cache variable VAR
137 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])]dnl
138 [ac_fn_[]_AC_LANG_ABBREV[]_check_header_mongrel ]dnl
139 ["$LINENO" "$1" "ac_Header" "AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
140 AS_VAR_IF([ac_Header], [yes], [$2], [$3])
141 AS_VAR_POPDEF([ac_Header])])# _AC_CHECK_HEADER_MONGREL
144 # _AC_CHECK_HEADER_COMPILE_BODY
145 # -----------------------------
146 # Shell function body for _AC_CHECK_HEADER_COMPILE
147 m4_define([_AC_CHECK_HEADER_COMPILE_BODY],
148 [ AS_LINENO_PUSH([$[]1])
149 AC_CACHE_CHECK([for $[]2], [$[]3],
150 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([$[]4
151 @%:@include <$[]2>])],
152 [AS_VAR_SET([$[]3], [yes])],
153 [AS_VAR_SET([$[]3], [no])])])
155 ])# _AC_CHECK_HEADER_COMPILE_BODY
157 # _AC_CHECK_HEADER_COMPILE(HEADER-FILE,
158 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
159 # [INCLUDES = DEFAULT-INCLUDES])
160 # --------------------------------------------------------------
161 # Check the compiler accepts HEADER-FILE. The INCLUDES are defaulted.
162 AC_DEFUN([_AC_CHECK_HEADER_COMPILE],
163 [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_header_compile],
164 [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_header_compile],
165 [LINENO HEADER VAR INCLUDES],
166 [Tests whether HEADER exists and can be compiled using the include files
167 in INCLUDES, setting the cache variable VAR accordingly.])],
169 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])]dnl
170 [ac_fn_[]_AC_LANG_ABBREV[]_check_header_compile ]dnl
171 ["$LINENO" "$1" "ac_Header" "AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
172 AS_VAR_IF([ac_Header], [yes], [$2], [$3])
173 AS_VAR_POPDEF([ac_Header])])# _AC_CHECK_HEADER_COMPILE
175 # _AC_CHECK_HEADER_PREPROC_BODY
176 # -----------------------------
177 # Shell function body for _AC_CHECK_HEADER_PREPROC.
178 m4_define([_AC_CHECK_HEADER_PREPROC_BODY],
179 [ AS_LINENO_PUSH([$[]1])
180 AC_CACHE_CHECK([for $[]2], [$[]3],
181 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$[]2>])],
182 [AS_VAR_SET([$[]3], [yes])],
183 [AS_VAR_SET([$[]3], [no])])])
185 ])# _AC_CHECK_HEADER_PREPROC_BODY
189 # _AC_CHECK_HEADER_PREPROC(HEADER-FILE,
190 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
191 # --------------------------------------------------------------
192 # Check the preprocessor accepts HEADER-FILE.
193 AC_DEFUN([_AC_CHECK_HEADER_PREPROC],
194 [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_header_preproc],
195 [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_header_preproc],
197 [Tests whether HEADER is present, setting the cache variable VAR accordingly.])],
199 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])]dnl
200 [ac_fn_[]_AC_LANG_ABBREV[]_check_header_preproc "$LINENO" "$1" "ac_Header"
201 AS_VAR_IF([ac_Header], [yes], [$2], [$3])
202 AS_VAR_POPDEF([ac_Header])dnl
203 ])# _AC_CHECK_HEADER_PREPROC
205 # _AC_CHECK_HEADER_OLD(HEADER-FILE, [ACTION-IF-FOUND],
206 # [ACTION-IF-NOT-FOUND])
207 # _AC_CHECK_HEADER_NEW(HEADER-FILE, [ACTION-IF-FOUND],
208 # [ACTION-IF-NOT-FOUND])
209 # ----------------------------------------------------
210 # Some packages used these undocumented macros. Even worse, gcc
211 # redefined AC_CHECK_HEADER in terms of _AC_CHECK_HEADER_OLD, so we
212 # can't do the simpler:
213 # AU_DEFUN([_AC_CHECK_HEADER_OLD],
214 # [AC_CHECK_HEADER([$1], [$2], [$3], [-])])
215 AC_DEFUN([_AC_CHECK_HEADER_OLD],
216 [AC_DIAGNOSE([obsolete], [The macro `$0' is obsolete.
217 You should use AC_CHECK_HEADER with a fourth argument.])]dnl
218 [_AC_CHECK_HEADER_PREPROC($@)])
220 AC_DEFUN([_AC_CHECK_HEADER_NEW],
221 [AC_DIAGNOSE([obsolete], [The macro `$0' is obsolete.
222 You should use AC_CHECK_HEADER with a fourth argument.])]dnl
223 [_AC_CHECK_HEADER_COMPILE($@)])
226 # _AH_CHECK_HEADER(HEADER-FILE)
227 # -----------------------------
228 # Prepare the autoheader snippet for HEADER-FILE.
229 m4_define([_AH_CHECK_HEADER],
230 [AH_TEMPLATE(AS_TR_CPP([HAVE_$1]),
231 [Define to 1 if you have the <$1> header file.])])
234 # AH_CHECK_HEADERS(HEADER-FILE...)
235 # --------------------------------
236 m4_define([AH_CHECK_HEADERS],
237 [m4_foreach_w([AC_Header], [$1], [_AH_CHECK_HEADER(m4_defn([AC_Header]))])])
240 # AC_CHECK_HEADERS(HEADER-FILE...,
241 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
243 # ----------------------------------------------------------
244 # Check for each whitespace-separated HEADER-FILE (omitting the <> or
245 # ""), and perform ACTION-IF-FOUND or ACTION-IF-NOT-FOUND for each
246 # header. INCLUDES is as for AC_CHECK_HEADER. Additionally, make the
247 # preprocessor definition HAVE_HEADER_FILE available for each found
248 # header. Either ACTION may include `break' to stop the search.
249 AC_DEFUN([AC_CHECK_HEADERS],
250 [m4_map_args_w([$1], [_AH_CHECK_HEADER(], [)])]dnl
251 [AS_FOR([AC_header], [ac_header], [$1],
252 [AC_CHECK_HEADER(AC_header,
253 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_]AC_header)) $2],
258 # _AC_CHECK_HEADER_ONCE(HEADER-FILE)
259 # ----------------------------------
260 # Check for a single HEADER-FILE once.
261 m4_define([_AC_CHECK_HEADER_ONCE],
262 [_AH_CHECK_HEADER([$1])AC_DEFUN([_AC_Header_]m4_translit([[$1]],
264 [m4_divert_text([INIT_PREPARE], [AS_VAR_APPEND([ac_header_list], [" $1"])])
265 _AC_HEADERS_EXPANSION])AC_REQUIRE([_AC_Header_]m4_translit([[$1]],
269 # AC_CHECK_HEADERS_ONCE(HEADER-FILE...)
270 # -------------------------------------
271 # Add each whitespace-separated name in HEADER-FILE to the list of
272 # headers to check once.
273 AC_DEFUN([AC_CHECK_HEADERS_ONCE],
274 [m4_map_args_w([$1], [_AC_CHECK_HEADER_ONCE(], [)])])
276 m4_define([_AC_HEADERS_EXPANSION],
278 m4_divert_text([DEFAULTS], [ac_header_list=])
279 AC_CHECK_HEADERS([$ac_header_list], [], [], [AC_INCLUDES_DEFAULT])
280 m4_define([_AC_HEADERS_EXPANSION], [])
286 ## --------------------- ##
287 ## 2. Default includes. ##
288 ## --------------------- ##
290 # Always use the same set of default headers for all the generic
291 # macros. It is easier to document, to extend, and to understand than
292 # having specific defaults for each macro.
294 # _AC_INCLUDES_DEFAULT_REQUIREMENTS
295 # ---------------------------------
296 # Required when AC_INCLUDES_DEFAULT uses its default branch.
297 AC_DEFUN([_AC_INCLUDES_DEFAULT_REQUIREMENTS],
298 [m4_divert_text([DEFAULTS],
299 [# Factoring default headers for most tests.
300 dnl If ever you change this variable, please keep autoconf.texi in sync.
301 ac_includes_default="\
303 #ifdef HAVE_SYS_TYPES_H
304 # include <sys/types.h>
306 #ifdef HAVE_SYS_STAT_H
307 # include <sys/stat.h>
313 # ifdef HAVE_STDLIB_H
318 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
323 #ifdef HAVE_STRINGS_H
324 # include <strings.h>
326 #ifdef HAVE_INTTYPES_H
327 # include <inttypes.h>
336 AC_REQUIRE([AC_HEADER_STDC])dnl
337 # On IRIX 5.3, sys/types and inttypes.h are conflicting.
338 AC_CHECK_HEADERS([sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
339 inttypes.h stdint.h unistd.h],
340 [], [], $ac_includes_default)
341 ])# _AC_INCLUDES_DEFAULT_REQUIREMENTS
344 # AC_INCLUDES_DEFAULT([INCLUDES])
345 # -------------------------------
346 # If INCLUDES is empty, expand in default includes, otherwise in
348 # In most cases INCLUDES is not double quoted as it should, and if
349 # for instance INCLUDES = `#include <stdio.h>' then unless we force
350 # a newline, the hash will swallow the closing paren etc. etc.
352 # Take no risk: for the newline.
353 AC_DEFUN([AC_INCLUDES_DEFAULT],
356 [AC_REQUIRE([_AC_INCLUDES_DEFAULT_REQUIREMENTS])dnl
357 $ac_includes_default])])
363 ## ------------------------------------------- ##
364 ## 3. Headers to check with AC_CHECK_HEADERS. ##
365 ## ------------------------------------------- ##
367 # errno.h is portable.
369 AN_HEADER([OS.h], [AC_CHECK_HEADERS])
370 AN_HEADER([argz.h], [AC_CHECK_HEADERS])
371 AN_HEADER([arpa/inet.h], [AC_CHECK_HEADERS])
372 AN_HEADER([fcntl.h], [AC_CHECK_HEADERS])
373 AN_HEADER([fenv.h], [AC_CHECK_HEADERS])
374 AN_HEADER([float.h], [AC_CHECK_HEADERS])
375 AN_HEADER([fs_info.h], [AC_CHECK_HEADERS])
376 AN_HEADER([inttypes.h], [AC_CHECK_HEADERS])
377 AN_HEADER([langinfo.h], [AC_CHECK_HEADERS])
378 AN_HEADER([libintl.h], [AC_CHECK_HEADERS])
379 AN_HEADER([limits.h], [AC_CHECK_HEADERS])
380 AN_HEADER([locale.h], [AC_CHECK_HEADERS])
381 AN_HEADER([mach/mach.h], [AC_CHECK_HEADERS])
382 AN_HEADER([malloc.h], [AC_CHECK_HEADERS])
383 AN_HEADER([memory.h], [AC_CHECK_HEADERS])
384 AN_HEADER([mntent.h], [AC_CHECK_HEADERS])
385 AN_HEADER([mnttab.h], [AC_CHECK_HEADERS])
386 AN_HEADER([netdb.h], [AC_CHECK_HEADERS])
387 AN_HEADER([netinet/in.h], [AC_CHECK_HEADERS])
388 AN_HEADER([nl_types.h], [AC_CHECK_HEADERS])
389 AN_HEADER([nlist.h], [AC_CHECK_HEADERS])
390 AN_HEADER([paths.h], [AC_CHECK_HEADERS])
391 AN_HEADER([sgtty.h], [AC_CHECK_HEADERS])
392 AN_HEADER([shadow.h], [AC_CHECK_HEADERS])
393 AN_HEADER([stddef.h], [AC_CHECK_HEADERS])
394 AN_HEADER([stdint.h], [AC_CHECK_HEADERS])
395 AN_HEADER([stdio_ext.h], [AC_CHECK_HEADERS])
396 AN_HEADER([stdlib.h], [AC_CHECK_HEADERS])
397 AN_HEADER([string.h], [AC_CHECK_HEADERS])
398 AN_HEADER([strings.h], [AC_CHECK_HEADERS])
399 AN_HEADER([sys/acl.h], [AC_CHECK_HEADERS])
400 AN_HEADER([sys/file.h], [AC_CHECK_HEADERS])
401 AN_HEADER([sys/filsys.h], [AC_CHECK_HEADERS])
402 AN_HEADER([sys/fs/s5param.h], [AC_CHECK_HEADERS])
403 AN_HEADER([sys/fs_types.h], [AC_CHECK_HEADERS])
404 AN_HEADER([sys/fstyp.h], [AC_CHECK_HEADERS])
405 AN_HEADER([sys/ioctl.h], [AC_CHECK_HEADERS])
406 AN_HEADER([sys/mntent.h], [AC_CHECK_HEADERS])
407 AN_HEADER([sys/mount.h], [AC_CHECK_HEADERS])
408 AN_HEADER([sys/param.h], [AC_CHECK_HEADERS])
409 AN_HEADER([sys/socket.h], [AC_CHECK_HEADERS])
410 AN_HEADER([sys/statfs.h], [AC_CHECK_HEADERS])
411 AN_HEADER([sys/statvfs.h], [AC_CHECK_HEADERS])
412 AN_HEADER([sys/systeminfo.h], [AC_CHECK_HEADERS])
413 AN_HEADER([sys/time.h], [AC_CHECK_HEADERS])
414 AN_HEADER([sys/timeb.h], [AC_CHECK_HEADERS])
415 AN_HEADER([sys/vfs.h], [AC_CHECK_HEADERS])
416 AN_HEADER([sys/window.h], [AC_CHECK_HEADERS])
417 AN_HEADER([syslog.h], [AC_CHECK_HEADERS])
418 AN_HEADER([termio.h], [AC_CHECK_HEADERS])
419 AN_HEADER([termios.h], [AC_CHECK_HEADERS])
420 AN_HEADER([unistd.h], [AC_CHECK_HEADERS])
421 AN_HEADER([utime.h], [AC_CHECK_HEADERS])
422 AN_HEADER([utmp.h], [AC_CHECK_HEADERS])
423 AN_HEADER([utmpx.h], [AC_CHECK_HEADERS])
424 AN_HEADER([values.h], [AC_CHECK_HEADERS])
425 AN_HEADER([wchar.h], [AC_CHECK_HEADERS])
426 AN_HEADER([wctype.h], [AC_CHECK_HEADERS])
430 ## ------------------------------- ##
431 ## 4. Tests for specific headers. ##
432 ## ------------------------------- ##
436 # Check whether to enable assertions.
437 AC_DEFUN_ONCE([AC_HEADER_ASSERT],
439 AC_MSG_CHECKING([whether to enable assertions])
440 AC_ARG_ENABLE([assert],
441 [AS_HELP_STRING([--disable-assert], [turn off assertions])],
442 [ac_enable_assert=$enableval
444 [test "x$enableval" = xno],
445 [AC_DEFINE([NDEBUG], [1],
446 [Define to 1 if assertions should be disabled.])],
447 [test "x$enableval" != xyes],
448 [AC_MSG_WARN([invalid argument supplied to --enable-assert])
449 ac_enable_assert=yes])],
450 [ac_enable_assert=yes])
451 AC_MSG_RESULT([$ac_enable_assert])
455 # _AC_CHECK_HEADER_DIRENT(HEADER-FILE,
456 # [ACTION-IF-FOUND], [ACTION-IF-NOT_FOUND])
457 # -----------------------------------------------------------------
458 # Like AC_CHECK_HEADER, except also make sure that HEADER-FILE
459 # defines the type `DIR'. dirent.h on NextStep 3.2 doesn't.
460 m4_define([_AC_CHECK_HEADER_DIRENT],
461 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_dirent_$1])dnl
462 AC_CACHE_CHECK([for $1 that defines DIR], [ac_Header],
463 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
468 [AS_VAR_SET([ac_Header], [yes])],
469 [AS_VAR_SET([ac_Header], [no])])])
470 AS_VAR_IF([ac_Header], [yes], [$2], [$3])
471 AS_VAR_POPDEF([ac_Header])dnl
472 ])# _AC_CHECK_HEADER_DIRENT
475 # _AH_CHECK_HEADER_DIRENT(HEADERS)
476 # --------------------------------
477 # Like _AH_CHECK_HEADER, but tuned to a dirent provider.
478 m4_define([_AH_CHECK_HEADER_DIRENT],
479 [AH_TEMPLATE(AS_TR_CPP([HAVE_$1]),
480 [Define to 1 if you have the <$1> header file, and it defines `DIR'.])])
485 AC_DEFUN([AC_HEADER_DIRENT],
486 [m4_map_args([_AH_CHECK_HEADER_DIRENT], [dirent.h], [sys/ndir.h],
487 [sys/dir.h], [ndir.h])]dnl
489 for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
490 _AC_CHECK_HEADER_DIRENT($ac_hdr,
491 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$ac_hdr), 1)
492 ac_header_dirent=$ac_hdr; break])
494 # Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
495 if test $ac_header_dirent = dirent.h; then
496 AC_SEARCH_LIBS(opendir, dir)
498 AC_SEARCH_LIBS(opendir, x)
505 AN_FUNCTION([major], [AC_HEADER_MAJOR])
506 AN_FUNCTION([makedev], [AC_HEADER_MAJOR])
507 AN_FUNCTION([minor], [AC_HEADER_MAJOR])
508 AN_HEADER([sys/mkdev.h], [AC_HEADER_MAJOR])
509 AC_DEFUN([AC_HEADER_MAJOR],
510 [AC_CACHE_CHECK(whether sys/types.h defines makedev,
511 ac_cv_header_sys_types_h_makedev,
512 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <sys/types.h>]],
513 [[return makedev(0, 0);]])],
514 [ac_cv_header_sys_types_h_makedev=yes],
515 [ac_cv_header_sys_types_h_makedev=no])
518 if test $ac_cv_header_sys_types_h_makedev = no; then
519 AC_CHECK_HEADER(sys/mkdev.h,
520 [AC_DEFINE(MAJOR_IN_MKDEV, 1,
521 [Define to 1 if `major', `minor', and `makedev' are
522 declared in <mkdev.h>.])])
524 if test $ac_cv_header_sys_mkdev_h = no; then
525 AC_CHECK_HEADER(sys/sysmacros.h,
526 [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
527 [Define to 1 if `major', `minor', and `makedev'
528 are declared in <sysmacros.h>.])])
536 # According to http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?resolver+3
537 # (or http://www.chemie.fu-berlin.de/cgi-bin/man/sgi_irix?resolver+3),
538 # sys/types.h, netinet/in.h and arpa/nameser.h are required on IRIX.
539 # netinet/in.h is needed on Cygwin, too.
540 # With Solaris 9, netdb.h is required, to get symbols like HOST_NOT_FOUND.
542 AN_HEADER(resolv.h, [AC_HEADER_RESOLV])
543 AC_DEFUN([AC_HEADER_RESOLV],
544 [AC_CHECK_HEADERS(sys/types.h netinet/in.h arpa/nameser.h netdb.h resolv.h,
546 [[#ifdef HAVE_SYS_TYPES_H
547 # include <sys/types.h>
549 #ifdef HAVE_NETINET_IN_H
550 # include <netinet/in.h> /* inet_ functions / structs */
552 #ifdef HAVE_ARPA_NAMESER_H
553 # include <arpa/nameser.h> /* DNS HEADER struct */
563 # FIXME: Shouldn't this be named AC_HEADER_SYS_STAT?
564 AC_DEFUN([AC_HEADER_STAT],
565 [AC_CACHE_CHECK(whether stat file-mode macros are broken,
566 ac_cv_header_stat_broken,
567 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <sys/types.h>
568 #include <sys/stat.h>
570 #if defined S_ISBLK && defined S_IFDIR
571 extern char c1[S_ISBLK (S_IFDIR) ? -1 : 1];
574 #if defined S_ISBLK && defined S_IFCHR
575 extern char c2[S_ISBLK (S_IFCHR) ? -1 : 1];
578 #if defined S_ISLNK && defined S_IFREG
579 extern char c3[S_ISLNK (S_IFREG) ? -1 : 1];
582 #if defined S_ISSOCK && defined S_IFREG
583 extern char c4[S_ISSOCK (S_IFREG) ? -1 : 1];
585 ]])], ac_cv_header_stat_broken=no, ac_cv_header_stat_broken=yes)])
586 if test $ac_cv_header_stat_broken = yes; then
587 AC_DEFINE(STAT_MACROS_BROKEN, 1,
588 [Define to 1 if the `S_IS*' macros in <sys/stat.h> do not
596 # Check for stdbool.h that conforms to C99.
597 AN_IDENTIFIER([bool], [AC_HEADER_STDBOOL])
598 AN_IDENTIFIER([true], [AC_HEADER_STDBOOL])
599 AN_IDENTIFIER([false],[AC_HEADER_STDBOOL])
600 AC_DEFUN([AC_HEADER_STDBOOL],
601 [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
602 [ac_cv_header_stdbool_h],
603 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
607 "error: bool is not defined"
610 "error: false is not defined"
613 "error: false is not 0"
616 "error: true is not defined"
619 "error: true is not 1"
621 #ifndef __bool_true_false_are_defined
622 "error: __bool_true_false_are_defined is not defined"
625 struct s { _Bool s: 1; _Bool t; } s;
627 char a[true == 1 ? 1 : -1];
628 char b[false == 0 ? 1 : -1];
629 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
630 char d[(bool) 0.5 == true ? 1 : -1];
632 char f[(_Bool) 0.0 == false ? 1 : -1];
634 char h[sizeof (_Bool)];
636 enum { j = false, k = true, l = false * true, m = true * 256 };
637 /* The following fails for
638 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
640 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
641 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
642 # if defined __xlc__ || defined __GNUC__
643 /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
644 reported by James Lemley on 2005-10-05; see
645 http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
646 This test is not quite right, since xlc is allowed to
647 reject this program, as the initializer for xlcbug is
648 not one of the forms that C requires support for.
649 However, doing the test right would require a runtime
650 test, and that would make cross-compilation harder.
651 Let us hope that IBM fixes the xlc bug, and also adds
652 support for this kind of constant expression. In the
653 meantime, this test will reject xlc, which is OK, since
654 our stdbool.h substitute should suffice. We also test
655 this with GCC, where it should work, to detect more
656 quickly whether someone messes up the test in the
658 char digs[] = "0123456789";
659 int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
661 /* Catch a bug in an HP-UX C compiler. See
662 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
663 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
671 /* Refer to every declared value, to avoid compiler optimizations. */
672 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
673 + !m + !n + !o + !p + !q + !pq);
675 [ac_cv_header_stdbool_h=yes],
676 [ac_cv_header_stdbool_h=no])])
677 AC_CHECK_TYPES([_Bool])
678 if test $ac_cv_header_stdbool_h = yes; then
679 AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
681 ])# AC_HEADER_STDBOOL
686 AC_DEFUN([AC_HEADER_STDC],
687 [AC_CACHE_CHECK(for ANSI C header files, ac_cv_header_stdc,
688 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
693 [ac_cv_header_stdc=yes],
694 [ac_cv_header_stdc=no])
696 if test $ac_cv_header_stdc = yes; then
697 # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
698 AC_EGREP_HEADER(memchr, string.h, , ac_cv_header_stdc=no)
701 if test $ac_cv_header_stdc = yes; then
702 # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
703 AC_EGREP_HEADER(free, stdlib.h, , ac_cv_header_stdc=no)
706 if test $ac_cv_header_stdc = yes; then
707 # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
708 AC_RUN_IFELSE([AC_LANG_SOURCE(
711 #if ((' ' & 0x0FF) == 0x020)
712 # define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
713 # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
715 # define ISLOWER(c) \
716 (('a' <= (c) && (c) <= 'i') \
717 || ('j' <= (c) && (c) <= 'r') \
718 || ('s' <= (c) && (c) <= 'z'))
719 # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
722 #define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
727 for (i = 0; i < 256; i++)
728 if (XOR (islower (i), ISLOWER (i))
729 || toupper (i) != TOUPPER (i))
732 }]])], , ac_cv_header_stdc=no, :)
734 if test $ac_cv_header_stdc = yes; then
735 AC_DEFINE(STDC_HEADERS, 1,
736 [Define to 1 if you have the ANSI C header files.])
743 AC_DEFUN([AC_HEADER_SYS_WAIT],
744 [AC_CACHE_CHECK([for sys/wait.h that is POSIX.1 compatible],
745 ac_cv_header_sys_wait_h,
747 [AC_LANG_PROGRAM([#include <sys/types.h>
748 #include <sys/wait.h>
750 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
753 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
758 s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;])],
759 [ac_cv_header_sys_wait_h=yes],
760 [ac_cv_header_sys_wait_h=no])])
761 if test $ac_cv_header_sys_wait_h = yes; then
762 AC_DEFINE(HAVE_SYS_WAIT_H, 1,
763 [Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible.])
765 ])# AC_HEADER_SYS_WAIT
770 AC_DEFUN([AC_HEADER_TIME],
771 [AC_CACHE_CHECK([whether time.h and sys/time.h may both be included],
773 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
774 #include <sys/time.h>
777 [if ((struct tm *) 0)
779 [ac_cv_header_time=yes],
780 [ac_cv_header_time=no])])
781 if test $ac_cv_header_time = yes; then
782 AC_DEFINE(TIME_WITH_SYS_TIME, 1,
783 [Define to 1 if you can safely include both <sys/time.h>
789 # _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
790 # ----------------------------------
791 m4_define([_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H],
792 [AC_CACHE_CHECK([whether termios.h defines TIOCGWINSZ],
793 ac_cv_sys_tiocgwinsz_in_termios_h,
795 [#include <sys/types.h>
801 ac_cv_sys_tiocgwinsz_in_termios_h=yes,
802 ac_cv_sys_tiocgwinsz_in_termios_h=no)])
803 ])# _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
806 # _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
807 # ----------------------------------
808 m4_define([_AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL],
809 [AC_CACHE_CHECK([whether sys/ioctl.h defines TIOCGWINSZ],
810 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h,
812 [#include <sys/types.h>
813 #include <sys/ioctl.h>
818 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes,
819 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no)])
820 ])# _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
823 # AC_HEADER_TIOCGWINSZ
824 # --------------------
825 # Look for a header that defines TIOCGWINSZ.
826 # FIXME: Is this the proper name? Is this the proper implementation?
828 AC_DEFUN([AC_HEADER_TIOCGWINSZ],
829 [_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
830 if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then
831 _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
832 if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then
833 AC_DEFINE(GWINSZ_IN_SYS_IOCTL,1,
834 [Define to 1 if `TIOCGWINSZ' requires <sys/ioctl.h>.])
837 ])# AC_HEADER_TIOCGWINSZ
842 AU_DEFUN([AC_UNISTD_H],
843 [AC_CHECK_HEADERS(unistd.h)])
848 # Define `USG' if string functions are in strings.h.
850 [AC_MSG_CHECKING([for BSD string and memory functions])
851 AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <strings.h>]],
852 [[rindex(0, 0); bzero(0, 0);]])],
853 [AC_MSG_RESULT(yes)],
856 [Define to 1 if you do not have <strings.h>, index,
857 bzero, etc... This symbol is obsolete, you should
858 not depend upon it.])])
859 AC_CHECK_HEADERS(string.h)],
860 [Remove `AC_MSG_CHECKING', `AC_LINK_IFELSE' and this warning
861 when you adjust your code to use HAVE_STRING_H.])
866 # To be precise this macro used to be:
868 # | AC_MSG_CHECKING(whether string.h declares mem functions)
869 # | AC_EGREP_HEADER(memchr, string.h, ac_found=yes, ac_found=no)
870 # | AC_MSG_RESULT($ac_found)
871 # | if test $ac_found = no; then
872 # | AC_CHECK_HEADER(memory.h, [AC_DEFINE(NEED_MEMORY_H)])
875 # But it is better to check for both headers, and alias NEED_MEMORY_H to
877 AU_DEFUN([AC_MEMORY_H],
878 [AC_CHECK_HEADER(memory.h,
879 [AC_DEFINE([NEED_MEMORY_H], 1,
880 [Same as `HAVE_MEMORY_H', don't depend on me.])])
881 AC_CHECK_HEADERS(string.h memory.h)],
882 [Remove this warning and
883 `AC_CHECK_HEADER(memory.h, AC_DEFINE(...))' when you adjust your code to
884 use HAVE_STRING_H and HAVE_MEMORY_H, not NEED_MEMORY_H.])
889 # Like calling `AC_HEADER_DIRENT' and `AC_FUNC_CLOSEDIR_VOID', but
890 # defines a different set of C preprocessor macros to indicate which
891 # header file is found.
892 AU_DEFUN([AC_DIR_HEADER],
894 AC_FUNC_CLOSEDIR_VOID
895 test ac_cv_header_dirent_dirent_h &&
896 AC_DEFINE([DIRENT], 1, [Same as `HAVE_DIRENT_H', don't depend on me.])
897 test ac_cv_header_dirent_sys_ndir_h &&
898 AC_DEFINE([SYSNDIR], 1, [Same as `HAVE_SYS_NDIR_H', don't depend on me.])
899 test ac_cv_header_dirent_sys_dir_h &&
900 AC_DEFINE([SYSDIR], 1, [Same as `HAVE_SYS_DIR_H', don't depend on me.])
901 test ac_cv_header_dirent_ndir_h &&
902 AC_DEFINE([NDIR], 1, [Same as `HAVE_NDIR_H', don't depend on me.])],
903 [Remove this warning and the four `AC_DEFINE' when you
904 adjust your code to use `AC_HEADER_DIRENT'.])