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