1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Checking for headers.
4 # Copyright (C) 1988, 1999-2004, 2006, 2008-2017, 2020-2024 Free
5 # 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 <https://www.gnu.org/licenses/> and
26 # <https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob_plain;f=COPYING.EXCEPTION>.
28 # Written by David MacKenzie, with help from
29 # François Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
30 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
35 # 1. Generic tests for headers
37 # 3. Headers to tests with AC_CHECK_HEADERS
38 # 4. Tests for specific headers
41 ## ------------------------------ ##
42 ## 1. Generic tests for headers. ##
43 ## ------------------------------ ##
46 # AC_CHECK_HEADER(HEADER-FILE,
47 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
49 # ---------------------------------------------------------
50 # This used to check for headers using the preprocessor only, but we
51 # have now switched to running a full compilation, so that we learn
52 # about the usability of a header instead of its mere presence.
53 # The old behavior is still available by specifying '-' as the
54 # INCLUDES, but this triggers a deprecation warning.
56 # The m4_indir allows for fewer expansions of $@.
57 AC_DEFUN([AC_CHECK_HEADER],
58 [m4_indir(m4_if([$4], [-],
59 [[_AC_CHECK_HEADER_PREPROC]],
60 [[_AC_CHECK_HEADER_COMPILE]]), $@)])
63 # _AC_CHECK_HEADER_COMPILE_BODY
64 # -----------------------------
65 # Shell function body for _AC_CHECK_HEADER_COMPILE
66 m4_define([_AC_CHECK_HEADER_COMPILE_BODY],
67 [ AS_LINENO_PUSH([$[]1])
68 AC_CACHE_CHECK([for $[]2], [$[]3],
69 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([$[]4
70 @%:@include <$[]2>])],
71 [AS_VAR_SET([$[]3], [yes])],
72 [AS_VAR_SET([$[]3], [no])])])
74 ])# _AC_CHECK_HEADER_COMPILE_BODY
77 m4_define([_AC_CHECK_HEADER_COMPILE_FN],
78 [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_header_compile],
79 [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_header_compile],
80 [LINENO HEADER VAR INCLUDES],
81 [Tests whether HEADER exists and can be compiled using the include files
82 in INCLUDES, setting the cache variable VAR accordingly.])],
83 [_AC_CHECK_HEADER_COMPILE_BODY])])
85 # _AC_CHECK_HEADER_COMPILE(HEADER-FILE,
86 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
87 # [INCLUDES = DEFAULT-INCLUDES])
88 # --------------------------------------------------------------
89 # Check the compiler accepts HEADER-FILE. The INCLUDES are defaulted.
90 AC_DEFUN([_AC_CHECK_HEADER_COMPILE],
91 [_AC_CHECK_HEADER_COMPILE_FN()]dnl
92 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])]dnl
93 [ac_fn_[]_AC_LANG_ABBREV[]_check_header_compile ]dnl
94 ["$LINENO" "$1" "ac_Header" "AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
95 AS_VAR_IF([ac_Header], [yes], [$2], [$3])
96 AS_VAR_POPDEF([ac_Header])])# _AC_CHECK_HEADER_COMPILE
99 # _AC_CHECK_HEADER_PREPROC_BODY
100 # -----------------------------
101 # Shell function body for _AC_CHECK_HEADER_PREPROC.
102 m4_define([_AC_CHECK_HEADER_PREPROC_BODY],
103 [ AS_LINENO_PUSH([$[]1])
104 AC_CACHE_CHECK([for $[]2], [$[]3],
105 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$[]2>])],
106 [AS_VAR_SET([$[]3], [yes])],
107 [AS_VAR_SET([$[]3], [no])])])
109 ])# _AC_CHECK_HEADER_PREPROC_BODY
112 # _AC_CHECK_HEADER_PREPROC(HEADER-FILE,
113 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
114 # --------------------------------------------------------------
115 # Check the preprocessor accepts HEADER-FILE.
116 AC_DEFUN([_AC_CHECK_HEADER_PREPROC],
117 [m4_warn([obsolete], [Checking for headers with the preprocessor is
118 deprecated. Specify prerequisite code to AC_CHECK_HEADER
119 instead of using fourth argument '-'. (Many headers need
120 no prerequisites. If you truly need to test whether
121 something passes the preprocessor but not the compiler,
122 use AC_PREPROC_IFELSE.)])]dnl
123 [AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_header_preproc],
124 [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_header_preproc],
126 [Tests whether HEADER exists and can be preprocessed (in isolation),
127 setting the cache variable VAR accordingly.])],
129 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])]dnl
130 [ac_fn_[]_AC_LANG_ABBREV[]_check_header_preproc "$LINENO" "$1" "ac_Header"
131 AS_VAR_IF([ac_Header], [yes], [$2], [$3])
132 AS_VAR_POPDEF([ac_Header])])# _AC_CHECK_HEADER_PREPROC
135 # _AC_CHECK_HEADER_OLD(HEADER-FILE, [ACTION-IF-FOUND],
136 # [ACTION-IF-NOT-FOUND])
137 # _AC_CHECK_HEADER_NEW(HEADER-FILE, [ACTION-IF-FOUND],
138 # [ACTION-IF-NOT-FOUND])
139 # ----------------------------------------------------
140 # Some packages used these undocumented macros. Even worse, gcc
141 # redefined AC_CHECK_HEADER in terms of _AC_CHECK_HEADER_OLD, so we
142 # can't do the simpler:
143 # AU_DEFUN([_AC_CHECK_HEADER_OLD],
144 # [AC_CHECK_HEADER([$1], [$2], [$3], [-])])
145 AC_DEFUN([_AC_CHECK_HEADER_OLD],
146 [m4_warn([obsolete], [The macro '$0' is obsolete.
147 You should use AC_CHECK_HEADER with a fourth argument.])]dnl
148 [_AC_CHECK_HEADER_PREPROC($@)])
150 AC_DEFUN([_AC_CHECK_HEADER_NEW],
151 [m4_warn([obsolete], [The macro '$0' is obsolete.
152 You should use AC_CHECK_HEADER with a fourth argument.])]dnl
153 [_AC_CHECK_HEADER_COMPILE($@)])
155 # _AC_CHECK_HEADER_MONGREL(HEADER-FILE,
156 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
157 # ------------------------------------------------------------------
158 # In case anyone used this undocumented macro. Map to the _PREPROC
159 # semantics to minimize the chance of breaking anything.
160 AU_DEFUN([_AC_CHECK_HEADER_MONGREL],
161 [AC_CHECK_HEADER([$1], [$2], [$3], [-])])
164 # _AH_CHECK_HEADER(HEADER-FILE)
165 # -----------------------------
166 # Prepare the autoheader snippet for HEADER-FILE.
167 m4_define([_AH_CHECK_HEADER],
168 [AH_TEMPLATE(AS_TR_CPP([HAVE_$1]),
169 [Define to 1 if you have the <$1> header file.])])
172 # AH_CHECK_HEADERS(HEADER-FILE...)
173 # --------------------------------
174 m4_define([AH_CHECK_HEADERS],
175 [m4_foreach_w([AC_Header], [$1], [_AH_CHECK_HEADER(m4_defn([AC_Header]))])])
177 # _AC_CHECK_HEADERS_ONE_U(HEADER-FILE)
178 # -------------------------------
179 # Perform the actions that need to be performed unconditionally
180 # for every HEADER-FILE that *could* be checked for by AC_CHECK_HEADERS.
181 m4_define([_AC_CHECK_HEADERS_ONE_U],
182 [AS_LITERAL_WORD_IF([$1],
183 [_AH_CHECK_HEADER([$1])],
184 [m4_warn([syntax], [AC_CHECK_HEADERS($1): you should use literals])])])
186 # _AC_CHECK_HEADERS_ONE_S(HEADER-FILE, [INCLUDES])
187 # -------------------------------
188 # If HEADER-FILE exists, define HAVE_HEADER_FILE. HEADER-FILE must be literal.
189 # Used by AC_CHECK_HEADERS for its simplest case, when its HEADER-FILE list
190 # is fully literal and no optional actions were supplied.
191 # INCLUDES is as for AC_CHECK_HEADER.
192 m4_define([_AC_CHECK_HEADERS_ONE_S],
193 [_AH_CHECK_HEADER([$1])]dnl
194 [AC_CHECK_HEADER([$1],
195 [AC_DEFINE(AS_TR_CPP([HAVE_$1]))], [], [$2])])
197 # _AC_CHECK_HEADERS_ONE_C(HEADER-FILE, [ACTION-IF-FOUND],
198 # [ACTION-IF-NOT-FOUND], [INCLUDES])
199 # -------------------------------------------------------------------------
200 # If HEADER-FILE exists, define HAVE_HEADER-FILE and execute ACTION-IF-FOUND.
201 # Otherwise execute ACTION-IF-NOT-FOUND. HEADER-FILE can be a shell variable.
202 # Used by AC_CHECK_HEADERS for complex cases.
203 # INCLUDES is as for AC_CHECK_HEADER.
204 m4_define([_AC_CHECK_HEADERS_ONE_C],
205 [AC_CHECK_HEADER([$1],
206 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_]$1)) $2],
209 # AC_CHECK_HEADERS(HEADER-FILE...,
210 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
212 # ----------------------------------------------------------
213 # Check for each whitespace-separated HEADER-FILE (omitting the <> or
214 # ""), and perform ACTION-IF-FOUND or ACTION-IF-NOT-FOUND for each
215 # header. INCLUDES is as for AC_CHECK_HEADER. Additionally, make the
216 # preprocessor definition HAVE_HEADER_FILE available for each found
217 # header. Either ACTION may include 'break' to stop the search.
218 AC_DEFUN([AC_CHECK_HEADERS],
219 [_$0(m4_validate_w([$1]), [$2], [$3], [$4])])
221 m4_define([_AC_CHECK_HEADERS],
222 [m4_if([$2$3]AS_LITERAL_IF([$1], [[yes]], [[no]]), [yes],
223 [m4_map_args_w([$1], [_AC_CHECK_HEADERS_ONE_S(], [, [$4])])],
224 [m4_map_args_w([$1], [_AC_CHECK_HEADERS_ONE_U(], [)])]dnl
225 [AS_FOR([AC_header], [ac_header], [$1],
226 [_AC_CHECK_HEADERS_ONE_C(AC_header, [$2], [$3], [$4])])])])
229 # _AC_CHECK_HEADER_ONCE(HEADER-FILE)
230 # ----------------------------------
231 # Check for a single HEADER-FILE once.
232 m4_define([_AC_CHECK_HEADER_ONCE],
233 [_AH_CHECK_HEADER([$1])AC_DEFUN([_AC_Header_]m4_translit([[$1]],
234 [./-], [___]), [m4_divert_text([INIT_PREPARE],
235 [AS_VAR_APPEND([ac_header_]]_AC_LANG_ABBREV[[_list],
236 [" $1 ]AS_TR_SH([$1]) AS_TR_CPP([HAVE_$1])["])])]dnl
237 [_AC_HEADERS_EXPANSION(_AC_LANG_ABBREV)])AC_REQUIRE(
238 [_AC_Header_]m4_translit([[$1]], [./-], [___]))])
241 # AC_CHECK_HEADERS_ONCE(HEADER-FILE...)
242 # -------------------------------------
243 # Add each whitespace-separated name in HEADER-FILE to the list of
244 # headers to check once.
245 # Note: has intimate knowledge of how AC_INCLUDES_DEFAULT works,
247 AC_DEFUN([AC_CHECK_HEADERS_ONCE],
248 [AC_REQUIRE([AC_CHECK_INCLUDES_DEFAULT])]dnl
249 [m4_map_args_w(m4_validate_w([$1]), [_AC_CHECK_HEADER_ONCE(], [)])])
252 # _AC_HEADERS_EXPANSION(LANG)
253 # ---------------------------
254 # One-shot code per language LANG for checking all headers registered by
255 # AC_CHECK_HEADERS_ONCE while that language was active. We have to inline
256 # portions of AC_CHECK_HEADER_COMPILE, because although we operate on shell
257 # variables, we know they represent literals at that point in time,
258 # where we don't want to trigger normal AS_VAR_PUSHDEF shell code.
259 m4_define([_AC_HEADERS_EXPANSION],
260 [m4_ifndef([$0($1)], [m4_define([$0($1)])m4_divert_text([DEFAULTS],
261 [ac_header_$1_list=])ac_header= ac_cache=
262 for ac_item in $ac_header_$1_list
264 if test $ac_cache; then
265 _AC_CHECK_HEADER_COMPILE_FN()ac_fn_$1_check_header_compile "$LINENO" ]dnl
266 [$ac_header ac_cv_header_$ac_cache "$ac_includes_default"
267 if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then
268 printf '%s\n' "[#]define $ac_item 1" >> confdefs.h
271 elif test $ac_header; then
280 ## --------------------- ##
281 ## 2. Default includes. ##
282 ## --------------------- ##
284 # Always use the same set of default headers for all the generic
285 # macros. It is easier to document, to extend, and to understand than
286 # having specific defaults for each macro.
288 # AC_CHECK_INCLUDES_DEFAULT
289 # -------------------------
290 # Required when AC_INCLUDES_DEFAULT uses its default branch.
291 AC_DEFUN_ONCE([AC_CHECK_INCLUDES_DEFAULT],
292 dnl If ever you change this variable, please keep autoconf.texi in sync.
293 [m4_divert_text([DEFAULTS],
294 [# Factoring default headers for most tests.
295 ac_includes_default="\
306 #ifdef HAVE_INTTYPES_H
307 # include <inttypes.h>
312 #ifdef HAVE_STRINGS_H
313 # include <strings.h>
315 #ifdef HAVE_SYS_TYPES_H
316 # include <sys/types.h>
318 #ifdef HAVE_SYS_STAT_H
319 # include <sys/stat.h>
325 [dnl We have to check for all the headers that aren't part of the
326 dnl C-1990 *freestanding* environment, which is all of them except stddef.h.
327 m4_map_args([_AC_CHECK_HEADER_ONCE],
328 [stdio.h], [stdlib.h], [string.h], [inttypes.h], [stdint.h],
329 [strings.h], [sys/stat.h], [sys/types.h], [unistd.h])]dnl
330 [AS_IF([test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes],
331 [AC_DEFINE([STDC_HEADERS], [1],
332 [Define to 1 if all of the C89 standard headers exist
333 (not just the ones required in a freestanding environment).
334 This macro is provided for backward compatibility;
335 new code need not use it.])])])
336 # AC_CHECK_INCLUDES_DEFAULT
339 # AC_INCLUDES_DEFAULT([INCLUDES])
340 # -------------------------------
341 # If INCLUDES is empty, expand in default includes, otherwise in
343 # In most cases INCLUDES is not double quoted as it should, and if
344 # for instance INCLUDES = '#include <stdio.h>' then unless we force
345 # a newline, the hash will swallow the closing paren etc. etc.
347 # Take no risk: for the newline.
348 AC_DEFUN([AC_INCLUDES_DEFAULT],
351 [AC_REQUIRE([AC_CHECK_INCLUDES_DEFAULT])]dnl
352 [$ac_includes_default])])
355 ## ------------------------------------------- ##
356 ## 3. Headers to check with AC_CHECK_HEADERS. ##
357 ## ------------------------------------------- ##
359 # There is no longer any need to check for headers that are part of
360 # C89 (as amended): assert.h, ctype.h, errno.h, float.h, iso646.h,
361 # limits.h, locale.h, math.h, setjmp.h, signal.h, stdarg.h, stddef.h,
362 # stdio.h, stdlib.h, string.h, time.h, wchar.h, wctype.h.
364 AN_HEADER([OS.h], [AC_CHECK_HEADERS])
365 AN_HEADER([argz.h], [AC_CHECK_HEADERS])
366 AN_HEADER([arpa/inet.h], [AC_CHECK_HEADERS])
367 AN_HEADER([fcntl.h], [AC_CHECK_HEADERS])
368 AN_HEADER([fenv.h], [AC_CHECK_HEADERS])
369 AN_HEADER([fs_info.h], [AC_CHECK_HEADERS])
370 AN_HEADER([inttypes.h], [AC_CHECK_HEADERS])
371 AN_HEADER([langinfo.h], [AC_CHECK_HEADERS])
372 AN_HEADER([libintl.h], [AC_CHECK_HEADERS])
373 AN_HEADER([mach/mach.h], [AC_CHECK_HEADERS])
374 AN_HEADER([malloc.h], [AC_CHECK_HEADERS])
375 AN_HEADER([mntent.h], [AC_CHECK_HEADERS])
376 AN_HEADER([mnttab.h], [AC_CHECK_HEADERS])
377 AN_HEADER([netdb.h], [AC_CHECK_HEADERS])
378 AN_HEADER([netinet/in.h], [AC_CHECK_HEADERS])
379 AN_HEADER([nl_types.h], [AC_CHECK_HEADERS])
380 AN_HEADER([nlist.h], [AC_CHECK_HEADERS])
381 AN_HEADER([paths.h], [AC_CHECK_HEADERS])
382 AN_HEADER([sgtty.h], [AC_CHECK_HEADERS])
383 AN_HEADER([shadow.h], [AC_CHECK_HEADERS])
384 AN_HEADER([stdint.h], [AC_CHECK_HEADERS])
385 AN_HEADER([stdio_ext.h], [AC_CHECK_HEADERS])
386 AN_HEADER([strings.h], [AC_CHECK_HEADERS])
387 AN_HEADER([sys/acl.h], [AC_CHECK_HEADERS])
388 AN_HEADER([sys/file.h], [AC_CHECK_HEADERS])
389 AN_HEADER([sys/filsys.h], [AC_CHECK_HEADERS])
390 AN_HEADER([sys/fs/s5param.h], [AC_CHECK_HEADERS])
391 AN_HEADER([sys/fs_types.h], [AC_CHECK_HEADERS])
392 AN_HEADER([sys/fstyp.h], [AC_CHECK_HEADERS])
393 AN_HEADER([sys/ioctl.h], [AC_CHECK_HEADERS])
394 AN_HEADER([sys/mntent.h], [AC_CHECK_HEADERS])
395 AN_HEADER([sys/mount.h], [AC_CHECK_HEADERS])
396 AN_HEADER([sys/param.h], [AC_CHECK_HEADERS])
397 AN_HEADER([sys/socket.h], [AC_CHECK_HEADERS])
398 AN_HEADER([sys/statfs.h], [AC_CHECK_HEADERS])
399 AN_HEADER([sys/statvfs.h], [AC_CHECK_HEADERS])
400 AN_HEADER([sys/systeminfo.h], [AC_CHECK_HEADERS])
401 AN_HEADER([sys/time.h], [AC_CHECK_HEADERS])
402 AN_HEADER([sys/timeb.h], [AC_CHECK_HEADERS])
403 AN_HEADER([sys/vfs.h], [AC_CHECK_HEADERS])
404 AN_HEADER([sys/window.h], [AC_CHECK_HEADERS])
405 AN_HEADER([syslog.h], [AC_CHECK_HEADERS])
406 AN_HEADER([termio.h], [AC_CHECK_HEADERS])
407 AN_HEADER([termios.h], [AC_CHECK_HEADERS])
408 AN_HEADER([unistd.h], [AC_CHECK_HEADERS])
409 AN_HEADER([utime.h], [AC_CHECK_HEADERS])
410 AN_HEADER([utmp.h], [AC_CHECK_HEADERS])
411 AN_HEADER([utmpx.h], [AC_CHECK_HEADERS])
412 AN_HEADER([values.h], [AC_CHECK_HEADERS])
414 ## ------------------------------- ##
415 ## 4. Tests for specific headers. ##
416 ## ------------------------------- ##
420 # Check whether to enable assertions.
421 AC_DEFUN_ONCE([AC_HEADER_ASSERT],
423 AC_MSG_CHECKING([whether to enable assertions])
424 AC_ARG_ENABLE([assert],
425 [AS_HELP_STRING([--disable-assert], [turn off assertions])],
426 [ac_enable_assert=$enableval
428 [test "x$enableval" = xno],
429 [AC_DEFINE([NDEBUG], [1],
430 [Define to 1 if assertions should be disabled.])],
431 [test "x$enableval" != xyes],
432 [AC_MSG_WARN([invalid argument supplied to --enable-assert])
433 ac_enable_assert=yes])],
434 [ac_enable_assert=yes])
435 AC_MSG_RESULT([$ac_enable_assert])
439 # _AC_CHECK_HEADER_DIRENT(HEADER-FILE,
440 # [ACTION-IF-FOUND], [ACTION-IF-NOT_FOUND])
441 # -----------------------------------------------------------------
442 # Like AC_CHECK_HEADER, except also make sure that HEADER-FILE
443 # defines the type 'DIR'. dirent.h on NextStep 3.2 doesn't.
444 m4_define([_AC_CHECK_HEADER_DIRENT],
445 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_dirent_$1])dnl
446 AC_CACHE_CHECK([for $1 that defines DIR], [ac_Header],
447 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
452 [AS_VAR_SET([ac_Header], [yes])],
453 [AS_VAR_SET([ac_Header], [no])])])
454 AS_VAR_IF([ac_Header], [yes], [$2], [$3])
455 AS_VAR_POPDEF([ac_Header])dnl
456 ])# _AC_CHECK_HEADER_DIRENT
459 # _AH_CHECK_HEADER_DIRENT(HEADERS)
460 # --------------------------------
461 # Like _AH_CHECK_HEADER, but tuned to a dirent provider.
462 m4_define([_AH_CHECK_HEADER_DIRENT],
463 [AH_TEMPLATE(AS_TR_CPP([HAVE_$1]),
464 [Define to 1 if you have the <$1> header file, and it defines 'DIR'.])])
469 AC_DEFUN([AC_HEADER_DIRENT],
470 [m4_map_args([_AH_CHECK_HEADER_DIRENT], [dirent.h], [sys/ndir.h],
471 [sys/dir.h], [ndir.h])]dnl
473 for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
474 _AC_CHECK_HEADER_DIRENT($ac_hdr,
475 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$ac_hdr), 1)
476 ac_header_dirent=$ac_hdr; break])
478 # Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
479 if test $ac_header_dirent = dirent.h; then
480 AC_SEARCH_LIBS(opendir, dir)
482 AC_SEARCH_LIBS(opendir, x)
489 # Thanks to glibc 2.25 deprecating macros in sys/types.h, coupled with
490 # back-compat to autoconf 2.69, we need the following logic:
491 # Check whether <sys/types.h> compiles.
492 # If <sys/mkdev.h> compiles, assume it provides major/minor/makedev.
493 # Otherwise, if <sys/sysmacros.h> compiles, assume it provides the macros.
494 # Otherwise, either the macros were provided by <sys/types.h>, or do
495 # not exist on the platform. Code trying to use these three macros is
496 # assumed to not care about platforms that lack the macros.
497 AN_FUNCTION([major], [AC_HEADER_MAJOR])
498 AN_FUNCTION([makedev], [AC_HEADER_MAJOR])
499 AN_FUNCTION([minor], [AC_HEADER_MAJOR])
500 AN_HEADER([sys/mkdev.h], [AC_HEADER_MAJOR])
501 AC_DEFUN([AC_HEADER_MAJOR],
502 [AC_CHECK_HEADERS_ONCE([sys/types.h])
503 AC_CHECK_HEADER([sys/mkdev.h],
504 [AC_DEFINE([MAJOR_IN_MKDEV], [1],
505 [Define to 1 if 'major', 'minor', and 'makedev' are
506 declared in <mkdev.h>.])])
507 if test $ac_cv_header_sys_mkdev_h = no; then
508 AC_CHECK_HEADER([sys/sysmacros.h],
509 [AC_DEFINE([MAJOR_IN_SYSMACROS], [1],
510 [Define to 1 if 'major', 'minor', and 'makedev'
511 are declared in <sysmacros.h>.])])
518 # sys/types.h, netinet/in.h and arpa/nameser.h are required on IRIX.
519 # netinet/in.h is needed on Cygwin, too.
520 # With Solaris 9, netdb.h is required, to get symbols like HOST_NOT_FOUND.
522 AN_HEADER(resolv.h, [AC_HEADER_RESOLV])
523 AC_DEFUN([AC_HEADER_RESOLV],
524 [AC_CHECK_HEADERS(sys/types.h netinet/in.h arpa/nameser.h netdb.h resolv.h,
526 [[#ifdef HAVE_SYS_TYPES_H
527 # include <sys/types.h>
529 #ifdef HAVE_NETINET_IN_H
530 # include <netinet/in.h> /* inet_ functions / structs */
532 #ifdef HAVE_ARPA_NAMESER_H
533 # include <arpa/nameser.h> /* DNS HEADER struct */
543 # FIXME: Shouldn't this be named AC_HEADER_SYS_STAT?
544 AC_DEFUN([AC_HEADER_STAT],
545 [AC_CACHE_CHECK(whether stat file-mode macros are broken,
546 ac_cv_header_stat_broken,
547 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <sys/types.h>
548 #include <sys/stat.h>
550 #if defined S_ISBLK && defined S_IFDIR
551 extern char c1[S_ISBLK (S_IFDIR) ? -1 : 1];
554 #if defined S_ISBLK && defined S_IFCHR
555 extern char c2[S_ISBLK (S_IFCHR) ? -1 : 1];
558 #if defined S_ISLNK && defined S_IFREG
559 extern char c3[S_ISLNK (S_IFREG) ? -1 : 1];
562 #if defined S_ISSOCK && defined S_IFREG
563 extern char c4[S_ISSOCK (S_IFREG) ? -1 : 1];
565 ]])], ac_cv_header_stat_broken=no, ac_cv_header_stat_broken=yes)])
566 if test $ac_cv_header_stat_broken = yes; then
567 AC_DEFINE(STAT_MACROS_BROKEN, 1,
568 [Define to 1 if the 'S_IS*' macros in <sys/stat.h> do not
574 # AC_CHECK_HEADER_STDBOOL
576 # Check for stdbool.h that conforms to C99 or later.
577 AN_IDENTIFIER([bool], [AC_CHECK_HEADER_STDBOOL])
578 AN_IDENTIFIER([true], [AC_CHECK_HEADER_STDBOOL])
579 AN_IDENTIFIER([false],[AC_CHECK_HEADER_STDBOOL])
580 AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
581 [AC_CHECK_TYPES([_Bool])
582 AC_CACHE_CHECK([for stdbool.h that conforms to C99 or later],
583 [ac_cv_header_stdbool_h],
586 [[#include <stdbool.h>
588 /* "true" and "false" should be usable in #if expressions and
589 integer constant expressions, and "bool" should be a valid
592 Although C99 requires bool, true, and false to be macros,
593 C23 and C++11 overrule that, so do not test for that.
594 Although C99 requires __bool_true_false_are_defined and
595 _Bool, C23 says they are obsolescent, so do not require
599 #error "'true' is not true"
602 #error "'true' is not equal to 1"
604 char b[true == 1 ? 1 : -1];
608 #error "'false' is not false"
611 #error "'false' is not equal to 0"
613 char d[false == 0 ? 1 : -1];
615 enum { e = false, f = true, g = false * true, h = true * 256 };
617 char i[(bool) 0.5 == true ? 1 : -1];
618 char j[(bool) 0.0 == false ? 1 : -1];
619 char k[sizeof (bool) > 0 ? 1 : -1];
621 struct sb { bool s: 1; bool t; } s;
622 char l[sizeof s.t > 0 ? 1 : -1];
624 /* The following fails for
625 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
627 char n[sizeof m == h * sizeof m[0] ? 1 : -1];
628 char o[-1 - (bool) 0 < 0 ? 1 : -1];
629 /* Catch a bug in an HP-UX C compiler. See
630 https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
631 https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
641 /* Refer to every declared value, so they cannot be
642 discarded as unused. */
643 return (!b + !c + !d + !e + !f + !g + !h + !i + !j + !k
644 + !l + !m + !n + !o + !p + !pp + !ps);
646 [ac_cv_header_stdbool_h=yes],
647 [ac_cv_header_stdbool_h=no])])
648 ])# AC_CHECK_HEADER_STDBOOL
653 # Define HAVE_STDBOOL_H if the system provides stdbool.h that conforms to C99.
654 AC_DEFUN([AC_HEADER_STDBOOL],
655 [AC_CHECK_HEADER_STDBOOL
656 if test $ac_cv_header_stdbool_h = yes; then
657 AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
659 ])# AC_HEADER_STDBOOL
664 AU_DEFUN([AC_HEADER_STDC],
665 [# Autoupdate added the next two lines to ensure that your configure
666 # script's behavior did not change. They are probably safe to remove.
667 AC_CHECK_INCLUDES_DEFAULT
670 [The preprocessor macro 'STDC_HEADERS' is obsolete.
671 Except in unusual embedded environments, you can safely include all
672 C89 headers unconditionally.])
676 AC_DEFUN([AC_HEADER_SYS_WAIT],
677 [AC_CACHE_CHECK([for sys/wait.h that is POSIX.1 compatible],
678 ac_cv_header_sys_wait_h,
680 [AC_LANG_PROGRAM([#include <sys/types.h>
681 #include <sys/wait.h>
683 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
686 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
691 s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;])],
692 [ac_cv_header_sys_wait_h=yes],
693 [ac_cv_header_sys_wait_h=no])])
694 if test $ac_cv_header_sys_wait_h = yes; then
695 AC_DEFINE(HAVE_SYS_WAIT_H, 1,
696 [Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible.])
698 ])# AC_HEADER_SYS_WAIT
703 AU_DEFUN([AC_HEADER_TIME],
704 [AC_CHECK_HEADERS_ONCE([sys/time.h])
705 # Obsolete code to be removed.
706 if test $ac_cv_header_sys_time_h = yes; then
707 AC_DEFINE(TIME_WITH_SYS_TIME, 1,
708 [Define to 1 if you can safely include both <sys/time.h>
709 and <time.h>. This macro is obsolete.])
711 # End of obsolete code.
712 ], [Update your code to rely only on HAVE_SYS_TIME_H,
713 then remove this warning and the obsolete code below it.
714 All current systems provide time.h; it need not be checked for.
715 Not all systems provide sys/time.h, but those that do, all allow
716 you to include it and time.h simultaneously.])
720 # _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
721 # ----------------------------------
722 m4_define([_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H],
723 [AC_CACHE_CHECK([whether termios.h defines TIOCGWINSZ],
724 ac_cv_sys_tiocgwinsz_in_termios_h,
725 [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
727 [#include <termios.h>
728 const int tiocgwinsz = TIOCGWINSZ;
730 ac_cv_sys_tiocgwinsz_in_termios_h=yes,
731 ac_cv_sys_tiocgwinsz_in_termios_h=no)])
732 ])# _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
735 # _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
736 # ----------------------------------
737 m4_define([_AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL],
738 [AC_CACHE_CHECK([whether sys/ioctl.h defines TIOCGWINSZ],
739 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h,
740 [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
742 [#include <sys/ioctl.h>
743 const int tiocgwinsz = TIOCGWINSZ;
745 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes,
746 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no)])
747 ])# _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
750 # AC_HEADER_TIOCGWINSZ
751 # --------------------
752 # Look for a header that defines TIOCGWINSZ.
753 # FIXME: Is this the proper name? Is this the proper implementation?
755 AC_DEFUN([AC_HEADER_TIOCGWINSZ],
756 [_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
757 if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then
758 _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
759 if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then
760 AC_DEFINE(GWINSZ_IN_SYS_IOCTL,1,
761 [Define to 1 if 'TIOCGWINSZ' requires <sys/ioctl.h>.])
764 ])# AC_HEADER_TIOCGWINSZ
769 AU_DEFUN([AC_UNISTD_H],
770 [# Autoupdate added the following line to ensure that your configure
771 # script's behavior did not change. It is probably safe to remove.
772 AC_CHECK_INCLUDES_DEFAULT])
777 # Define 'USG' if string functions are *not* in strings.h.
779 [# Obsolete code to be removed.
780 AC_MSG_CHECKING([for BSD string and memory functions])
781 AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <strings.h>]],
782 [[rindex("", 0); bzero(0, 0);]])],
783 [AC_MSG_RESULT(yes)],
786 [Define to 1 if you do not have <strings.h>, index,
787 bzero, etc... This symbol is obsolete, you should
788 not depend upon it.])])
789 # End of obsolete code.
791 [Update your code to use string.h, then remove this
792 warning and the code below it. It is not necessary
793 to check for string.h.])
798 # To be precise this macro used to be:
800 # | AC_MSG_CHECKING(whether string.h declares mem functions)
801 # | AC_EGREP_HEADER(memchr, string.h, ac_found=yes, ac_found=no)
802 # | AC_MSG_RESULT($ac_found)
803 # | if test $ac_found = no; then
804 # | AC_CHECK_HEADER(memory.h, [AC_DEFINE(NEED_MEMORY_H)])
807 # But it is better to check for both headers, and alias NEED_MEMORY_H to
809 AU_DEFUN([AC_MEMORY_H],
810 [# Obsolete code to be removed.
811 AC_CHECK_HEADERS_ONCE([memory.h])
812 if test $ac_cv_header_memory_h = yes; then
813 AC_DEFINE([NEED_MEMORY_H], [1],
814 [Same as 'HAVE_MEMORY_H', don't depend on me.])
816 # End of obsolete code.
818 [Update your code to use string.h, then remove this
819 warning and the code below it. It is not necessary
820 to check for string.h.])
825 # Like calling 'AC_HEADER_DIRENT' and 'AC_FUNC_CLOSEDIR_VOID', but
826 # defines a different set of C preprocessor macros to indicate which
827 # header file is found.
828 AU_DEFUN([AC_DIR_HEADER],
830 AC_FUNC_CLOSEDIR_VOID
831 test ac_cv_header_dirent_dirent_h &&
832 AC_DEFINE([DIRENT], 1, [Same as 'HAVE_DIRENT_H', don't depend on me.])
833 test ac_cv_header_dirent_sys_ndir_h &&
834 AC_DEFINE([SYSNDIR], 1, [Same as 'HAVE_SYS_NDIR_H', don't depend on me.])
835 test ac_cv_header_dirent_sys_dir_h &&
836 AC_DEFINE([SYSDIR], 1, [Same as 'HAVE_SYS_DIR_H', don't depend on me.])
837 test ac_cv_header_dirent_ndir_h &&
838 AC_DEFINE([NDIR], 1, [Same as 'HAVE_NDIR_H', don't depend on me.])],
839 [Remove this warning and the four 'AC_DEFINE' when you
840 adjust your code to use 'AC_HEADER_DIRENT'.])