maint: update copyright year
[autoconf.git] / lib / autoconf / headers.m4
blob75bdfeff187790b92796fdd7a8011e175957c4dd
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Checking for headers.
4 # Copyright (C) 1988, 1999-2004, 2006, 2008-2011 Free Software
5 # 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.
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 # 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
55 # only.
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
59 # result.
61 # If INCLUDES is `-', keep only the old semantics.
63 # If INCLUDES is specified and different from `-', then use the new
64 # semantics only.
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]]), $@)
72 ])# AC_CHECK_HEADER
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])
80   AS_VAR_SET_IF([$[]3],
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 #((
99   yes:no: )
100     AC_MSG_WARN([$[]2: accepted by the compiler, rejected by the preprocessor!])
101     AC_MSG_WARN([$[]2: proceeding with the compiler's result])
102     ;;
103   no:yes:* )
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
112     ;;
113 esac
114   AC_CACHE_CHECK([for $[]2], [$[]3],
115                  [AS_VAR_SET([$[]3], [$ac_header_compiler])])])
116   AS_LINENO_POP
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
135      accordingly.])],
136   [$0_BODY])]dnl
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])])])
154   AS_LINENO_POP
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.])],
168   [$0_BODY])]dnl
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])])])
184   AS_LINENO_POP
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],
196     [LINENO HEADER VAR],
197     [Tests whether HEADER is present, setting the cache variable VAR accordingly.])],
198   [$0_BODY])]dnl
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],
242 #                  [INCLUDES])
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],
254                  [$3], [$4])dnl])
255 ])# AC_CHECK_HEADERS
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]],
263     [./-], [___]),
264   [m4_divert_text([INIT_PREPARE], [AS_VAR_APPEND([ac_header_list], [" $1"])])
265 _AC_HEADERS_EXPANSION])AC_REQUIRE([_AC_Header_]m4_translit([[$1]],
266     [./-], [___]))])
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="\
302 #include <stdio.h>
303 #ifdef HAVE_SYS_TYPES_H
304 # include <sys/types.h>
305 #endif
306 #ifdef HAVE_SYS_STAT_H
307 # include <sys/stat.h>
308 #endif
309 #ifdef STDC_HEADERS
310 # include <stdlib.h>
311 # include <stddef.h>
312 #else
313 # ifdef HAVE_STDLIB_H
314 #  include <stdlib.h>
315 # endif
316 #endif
317 #ifdef HAVE_STRING_H
318 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
319 #  include <memory.h>
320 # endif
321 # include <string.h>
322 #endif
323 #ifdef HAVE_STRINGS_H
324 # include <strings.h>
325 #endif
326 #ifdef HAVE_INTTYPES_H
327 # include <inttypes.h>
328 #endif
329 #ifdef HAVE_STDINT_H
330 # include <stdint.h>
331 #endif
332 #ifdef HAVE_UNISTD_H
333 # include <unistd.h>
334 #endif"
335 ])dnl
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
347 # INCLUDES.
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.
351 # The usual failure.
352 # Take no risk: for the newline.
353 AC_DEFUN([AC_INCLUDES_DEFAULT],
354 [m4_ifval([$1], [$1
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 ## ------------------------------- ##
434 # AC_HEADER_ASSERT
435 # ----------------
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
443      AS_IF(dnl
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>
464 #include <$1>
466                                     [if ((DIR *) 0)
467 return 0;])],
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'.])])
483 # AC_HEADER_DIRENT
484 # ----------------
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
488 [ac_header_dirent=no
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])
493 done
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)
497 else
498   AC_SEARCH_LIBS(opendir, x)
500 ])# AC_HEADER_DIRENT
503 # AC_HEADER_MAJOR
504 # ---------------
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>.])])
529   fi
531 ])# AC_HEADER_MAJOR
534 # AC_HEADER_RESOLV
535 # ----------------
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,
545                   [], [],
546 [[#ifdef HAVE_SYS_TYPES_H
547 #  include <sys/types.h>
548 #endif
549 #ifdef HAVE_NETINET_IN_H
550 #  include <netinet/in.h>   /* inet_ functions / structs */
551 #endif
552 #ifdef HAVE_ARPA_NAMESER_H
553 #  include <arpa/nameser.h> /* DNS HEADER struct */
554 #endif
555 #ifdef HAVE_NETDB_H
556 #  include <netdb.h>
557 #endif]])
558 ])# AC_HEADER_RESOLV
561 # AC_HEADER_STAT
562 # --------------
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];
572 #endif
574 #if defined S_ISBLK && defined S_IFCHR
575 extern char c2[S_ISBLK (S_IFCHR) ? -1 : 1];
576 #endif
578 #if defined S_ISLNK && defined S_IFREG
579 extern char c3[S_ISLNK (S_IFREG) ? -1 : 1];
580 #endif
582 #if defined S_ISSOCK && defined S_IFREG
583 extern char c4[S_ISSOCK (S_IFREG) ? -1 : 1];
584 #endif
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
589              work properly.])
591 ])# AC_HEADER_STAT
594 # AC_HEADER_STDBOOL
595 # -----------------
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(
604       [[
605 #include <stdbool.h>
606 #ifndef bool
607  "error: bool is not defined"
608 #endif
609 #ifndef false
610  "error: false is not defined"
611 #endif
612 #if false
613  "error: false is not 0"
614 #endif
615 #ifndef true
616  "error: true is not defined"
617 #endif
618 #if true != 1
619  "error: true is not 1"
620 #endif
621 #ifndef __bool_true_false_are_defined
622  "error: __bool_true_false_are_defined is not defined"
623 #endif
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];
631         /* See body of main program for 'e'.  */
632         char f[(_Bool) 0.0 == false ? 1 : -1];
633         char g[true];
634         char h[sizeof (_Bool)];
635         char i[sizeof s.t];
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]. */
639         _Bool n[m];
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         /* Catch a bug in an HP-UX C compiler.  See
643            http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
644            http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
645          */
646         _Bool q = true;
647         _Bool *pq = &q;
648       ]],
649       [[
650         bool e = &s;
651         *pq |= q;
652         *pq |= ! q;
653         /* Refer to every declared value, to avoid compiler optimizations.  */
654         return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
655                 + !m + !n + !o + !p + !q + !pq);
656       ]])],
657       [ac_cv_header_stdbool_h=yes],
658       [ac_cv_header_stdbool_h=no])])
659 AC_CHECK_TYPES([_Bool])
660 if test $ac_cv_header_stdbool_h = yes; then
661   AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
663 ])# AC_HEADER_STDBOOL
666 # AC_HEADER_STDC
667 # --------------
668 AC_DEFUN([AC_HEADER_STDC],
669 [AC_CACHE_CHECK(for ANSI C header files, ac_cv_header_stdc,
670 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
671 #include <stdarg.h>
672 #include <string.h>
673 #include <float.h>
674 ]])],
675                     [ac_cv_header_stdc=yes],
676                     [ac_cv_header_stdc=no])
678 if test $ac_cv_header_stdc = yes; then
679   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
680   AC_EGREP_HEADER(memchr, string.h, , ac_cv_header_stdc=no)
683 if test $ac_cv_header_stdc = yes; then
684   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
685   AC_EGREP_HEADER(free, stdlib.h, , ac_cv_header_stdc=no)
688 if test $ac_cv_header_stdc = yes; then
689   # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
690   AC_RUN_IFELSE([AC_LANG_SOURCE(
691 [[#include <ctype.h>
692 #include <stdlib.h>
693 #if ((' ' & 0x0FF) == 0x020)
694 # define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
695 # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
696 #else
697 # define ISLOWER(c) \
698                    (('a' <= (c) && (c) <= 'i') \
699                      || ('j' <= (c) && (c) <= 'r') \
700                      || ('s' <= (c) && (c) <= 'z'))
701 # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
702 #endif
704 #define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
706 main ()
708   int i;
709   for (i = 0; i < 256; i++)
710     if (XOR (islower (i), ISLOWER (i))
711         || toupper (i) != TOUPPER (i))
712       return 2;
713   return 0;
714 }]])], , ac_cv_header_stdc=no, :)
715 fi])
716 if test $ac_cv_header_stdc = yes; then
717   AC_DEFINE(STDC_HEADERS, 1,
718             [Define to 1 if you have the ANSI C header files.])
720 ])# AC_HEADER_STDC
723 # AC_HEADER_SYS_WAIT
724 # ------------------
725 AC_DEFUN([AC_HEADER_SYS_WAIT],
726 [AC_CACHE_CHECK([for sys/wait.h that is POSIX.1 compatible],
727   ac_cv_header_sys_wait_h,
728 [AC_COMPILE_IFELSE(
729 [AC_LANG_PROGRAM([#include <sys/types.h>
730 #include <sys/wait.h>
731 #ifndef WEXITSTATUS
732 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
733 #endif
734 #ifndef WIFEXITED
735 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
736 #endif
738 [  int s;
739   wait (&s);
740   s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;])],
741                  [ac_cv_header_sys_wait_h=yes],
742                  [ac_cv_header_sys_wait_h=no])])
743 if test $ac_cv_header_sys_wait_h = yes; then
744   AC_DEFINE(HAVE_SYS_WAIT_H, 1,
745             [Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible.])
747 ])# AC_HEADER_SYS_WAIT
750 # AC_HEADER_TIME
751 # --------------
752 AC_DEFUN([AC_HEADER_TIME],
753 [AC_CACHE_CHECK([whether time.h and sys/time.h may both be included],
754   ac_cv_header_time,
755 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
756 #include <sys/time.h>
757 #include <time.h>
759 [if ((struct tm *) 0)
760 return 0;])],
761                    [ac_cv_header_time=yes],
762                    [ac_cv_header_time=no])])
763 if test $ac_cv_header_time = yes; then
764   AC_DEFINE(TIME_WITH_SYS_TIME, 1,
765             [Define to 1 if you can safely include both <sys/time.h>
766              and <time.h>.])
768 ])# AC_HEADER_TIME
771 # _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
772 # ----------------------------------
773 m4_define([_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H],
774 [AC_CACHE_CHECK([whether termios.h defines TIOCGWINSZ],
775                 ac_cv_sys_tiocgwinsz_in_termios_h,
776 [AC_EGREP_CPP([yes],
777               [#include <sys/types.h>
778 #include <termios.h>
779 #ifdef TIOCGWINSZ
780   yes
781 #endif
783                 ac_cv_sys_tiocgwinsz_in_termios_h=yes,
784                 ac_cv_sys_tiocgwinsz_in_termios_h=no)])
785 ])# _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
788 # _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
789 # ----------------------------------
790 m4_define([_AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL],
791 [AC_CACHE_CHECK([whether sys/ioctl.h defines TIOCGWINSZ],
792                 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h,
793 [AC_EGREP_CPP([yes],
794               [#include <sys/types.h>
795 #include <sys/ioctl.h>
796 #ifdef TIOCGWINSZ
797   yes
798 #endif
800                 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes,
801                 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no)])
802 ])# _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
805 # AC_HEADER_TIOCGWINSZ
806 # --------------------
807 # Look for a header that defines TIOCGWINSZ.
808 # FIXME: Is this the proper name?  Is this the proper implementation?
809 # I need more help.
810 AC_DEFUN([AC_HEADER_TIOCGWINSZ],
811 [_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
812 if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then
813   _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
814   if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then
815     AC_DEFINE(GWINSZ_IN_SYS_IOCTL,1,
816               [Define to 1 if `TIOCGWINSZ' requires <sys/ioctl.h>.])
817   fi
819 ])# AC_HEADER_TIOCGWINSZ
822 # AU::AC_UNISTD_H
823 # ---------------
824 AU_DEFUN([AC_UNISTD_H],
825 [AC_CHECK_HEADERS(unistd.h)])
828 # AU::AC_USG
829 # ----------
830 # Define `USG' if string functions are in strings.h.
831 AU_DEFUN([AC_USG],
832 [AC_MSG_CHECKING([for BSD string and memory functions])
833 AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <strings.h>]],
834                                 [[rindex(0, 0); bzero(0, 0);]])],
835                [AC_MSG_RESULT(yes)],
836                [AC_MSG_RESULT(no)
837                 AC_DEFINE(USG, 1,
838                           [Define to 1 if you do not have <strings.h>, index,
839                            bzero, etc... This symbol is obsolete, you should
840                            not depend upon it.])])
841 AC_CHECK_HEADERS(string.h)],
842 [Remove `AC_MSG_CHECKING', `AC_LINK_IFELSE' and this warning
843 when you adjust your code to use HAVE_STRING_H.])
846 # AU::AC_MEMORY_H
847 # ---------------
848 # To be precise this macro used to be:
850 #   | AC_MSG_CHECKING(whether string.h declares mem functions)
851 #   | AC_EGREP_HEADER(memchr, string.h, ac_found=yes, ac_found=no)
852 #   | AC_MSG_RESULT($ac_found)
853 #   | if test $ac_found = no; then
854 #   |   AC_CHECK_HEADER(memory.h, [AC_DEFINE(NEED_MEMORY_H)])
855 #   | fi
857 # But it is better to check for both headers, and alias NEED_MEMORY_H to
858 # HAVE_MEMORY_H.
859 AU_DEFUN([AC_MEMORY_H],
860 [AC_CHECK_HEADER(memory.h,
861                 [AC_DEFINE([NEED_MEMORY_H], 1,
862                            [Same as `HAVE_MEMORY_H', don't depend on me.])])
863 AC_CHECK_HEADERS(string.h memory.h)],
864 [Remove this warning and
865 `AC_CHECK_HEADER(memory.h, AC_DEFINE(...))' when you adjust your code to
866 use HAVE_STRING_H and HAVE_MEMORY_H, not NEED_MEMORY_H.])
869 # AU::AC_DIR_HEADER
870 # -----------------
871 # Like calling `AC_HEADER_DIRENT' and `AC_FUNC_CLOSEDIR_VOID', but
872 # defines a different set of C preprocessor macros to indicate which
873 # header file is found.
874 AU_DEFUN([AC_DIR_HEADER],
875 [AC_HEADER_DIRENT
876 AC_FUNC_CLOSEDIR_VOID
877 test ac_cv_header_dirent_dirent_h &&
878   AC_DEFINE([DIRENT], 1, [Same as `HAVE_DIRENT_H', don't depend on me.])
879 test ac_cv_header_dirent_sys_ndir_h &&
880   AC_DEFINE([SYSNDIR], 1, [Same as `HAVE_SYS_NDIR_H', don't depend on me.])
881 test ac_cv_header_dirent_sys_dir_h &&
882   AC_DEFINE([SYSDIR], 1, [Same as `HAVE_SYS_DIR_H', don't depend on me.])
883 test ac_cv_header_dirent_ndir_h &&
884   AC_DEFINE([NDIR], 1, [Same as `HAVE_NDIR_H', don't depend on me.])],
885 [Remove this warning and the four `AC_DEFINE' when you
886 adjust your code to use `AC_HEADER_DIRENT'.])