* lib/autoconf/c.m4 (AC_PROG_GCC_TRADITIONAL, AC_C_CONST):
[autoconf.git] / lib / autoconf / headers.m4
blob9fe6eea1bd07ff25016d64ee87eab3b33ab1581a
1 # This file is part of Autoconf.                        -*- Autoconf -*-
2 # Checking for headers.
4 # Copyright (C) 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2006 Free Software
5 # Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
22 # As a special exception, the Free Software Foundation gives unlimited
23 # permission to copy, distribute and modify the configure scripts that
24 # are the output of Autoconf.  You need not follow the terms of the GNU
25 # General Public License when using or distributing such scripts, even
26 # though portions of the text of Autoconf appear in them.  The GNU
27 # General Public License (GPL) does govern all other use of the material
28 # that constitutes the Autoconf program.
30 # Certain portions of the Autoconf source text are designed to be copied
31 # (in certain cases, depending on the input) into the output of
32 # Autoconf.  We call these the "data" portions.  The rest of the Autoconf
33 # source text consists of comments plus executable code that decides which
34 # of the data portions to output in any given case.  We call these
35 # comments and executable code the "non-data" portions.  Autoconf never
36 # copies any of the non-data portions into its output.
38 # This special exception to the GPL applies to versions of Autoconf
39 # released by the Free Software Foundation.  When you make and
40 # distribute a modified version of Autoconf, you may extend this special
41 # exception to the GPL to apply to your modified version as well, *unless*
42 # your modified version has the potential to copy into its output some
43 # of the text that was the non-data portion of the version that you started
44 # with.  (In other words, unless your change moves or copies text from
45 # the non-data portions to the data portions.)  If your modification has
46 # such potential, you must delete any notice of this special exception
47 # to the GPL from your modified version.
49 # Written by David MacKenzie, with help from
50 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
51 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
54 # Table of contents
56 # 1. Generic tests for headers
57 # 2. Default includes
58 # 3. Headers to tests with AC_CHECK_HEADERS
59 # 4. Tests for specific headers
62 ## ------------------------------ ##
63 ## 1. Generic tests for headers.  ##
64 ## ------------------------------ ##
67 # AC_CHECK_HEADER(HEADER-FILE,
68 #                 [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
69 #                 [INCLUDES])
70 # ---------------------------------------------------------
71 # We are slowly moving to checking headers with the compiler instead
72 # of the preproc, so that we actually learn about the usability of a
73 # header instead of its mere presence.  But since users are used to
74 # the old semantics, they check for headers in random order and
75 # without providing prerequisite headers.  This macro implements the
76 # transition phase, and should be cleaned up latter to use compilation
77 # only.
79 # If INCLUDES is empty, then check both via the compiler and preproc.
80 # If the results are different, issue a warning, but keep the preproc
81 # result.
83 # If INCLUDES is `-', keep only the old semantics.
85 # If INCLUDES is specified and different from `-', then use the new
86 # semantics only.
87 AC_DEFUN([AC_CHECK_HEADER],
88 [m4_case([$4],
89          [],  [_AC_CHECK_HEADER_MONGREL($@)],
90          [-], [_AC_CHECK_HEADER_OLD($@)],
91               [_AC_CHECK_HEADER_NEW($@)])
92 ])# AC_CHECK_HEADER
95 # _AC_CHECK_HEADER_MONGREL(HEADER-FILE,
96 #                          [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
97 #                          [INCLUDES = DEFAULT-INCLUDES])
98 # ------------------------------------------------------------------
99 # Check using both the compiler and the preprocessor.  If they disagree,
100 # warn, and the preproc wins.
102 # This is not based on _AC_CHECK_HEADER_NEW and _AC_CHECK_HEADER_OLD
103 # because it obfuscate the code to try to factor everything, in particular
104 # because of the cache variables, and the `checking...' messages.
105 m4_define([_AC_CHECK_HEADER_MONGREL],
106 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
107 AS_VAR_SET_IF([ac_Header],
108               [AC_CACHE_CHECK([for $1], [ac_Header], [])],
109               [# Is the header compilable?
110 AC_MSG_CHECKING([$1 usability])
111 AC_COMPILE_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT([$4])
112 @%:@include <$1>])],
113                   [ac_header_compiler=yes],
114                   [ac_header_compiler=no])
115 AC_MSG_RESULT([$ac_header_compiler])
117 # Is the header present?
118 AC_MSG_CHECKING([$1 presence])
119 AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$1>])],
120                   [ac_header_preproc=yes],
121                   [ac_header_preproc=no])
122 AC_MSG_RESULT([$ac_header_preproc])
124 # So?  What about this header?
125 case $ac_header_compiler:$ac_header_preproc:$ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in
126   yes:no: )
127     AC_MSG_WARN([$1: accepted by the compiler, rejected by the preprocessor!])
128     AC_MSG_WARN([$1: proceeding with the compiler's result])
129     ac_header_preproc=yes
130     ;;
131   no:yes:* )
132     AC_MSG_WARN([$1: present but cannot be compiled])
133     AC_MSG_WARN([$1:     check for missing prerequisite headers?])
134     AC_MSG_WARN([$1: see the Autoconf documentation])
135     AC_MSG_WARN([$1:     section "Present But Cannot Be Compiled"])
136     AC_MSG_WARN([$1: proceeding with the preprocessor's result])
137     AC_MSG_WARN([$1: in the future, the compiler will take precedence])
138     m4_ifset([AC_PACKAGE_BUGREPORT],
139     [( AS_BOX([Report this to ]AC_PACKAGE_BUGREPORT)
140      ) | sed "s/^/$as_me: WARNING:     /" >&2])
141     ;;
142 esac
143 AC_CACHE_CHECK([for $1], [ac_Header],
144                [AS_VAR_SET([ac_Header], [$ac_header_preproc])])
145 ])dnl ! set ac_HEADER
146 AS_IF([test AS_VAR_GET([ac_Header]) = yes], [$2], [$3])[]dnl
147 AS_VAR_POPDEF([ac_Header])dnl
148 ])# _AC_CHECK_HEADER_MONGREL
151 # _AC_CHECK_HEADER_NEW(HEADER-FILE,
152 #                      [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
153 #                      [INCLUDES = DEFAULT-INCLUDES])
154 # --------------------------------------------------------------
155 # Check the compiler accepts HEADER-FILE.  The INCLUDES are defaulted.
156 m4_define([_AC_CHECK_HEADER_NEW],
157 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
158 AC_CACHE_CHECK([for $1], [ac_Header],
159                [AC_COMPILE_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT([$4])
160 @%:@include <$1>])],
161                                   [AS_VAR_SET([ac_Header], [yes])],
162                                   [AS_VAR_SET([ac_Header], [no])])])
163 AS_IF([test AS_VAR_GET([ac_Header]) = yes], [$2], [$3])[]dnl
164 AS_VAR_POPDEF([ac_Header])dnl
165 ])# _AC_CHECK_HEADER_NEW
168 # _AC_CHECK_HEADER_OLD(HEADER-FILE,
169 #                      [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
170 # --------------------------------------------------------------
171 # Check the preprocessor accepts HEADER-FILE.
172 m4_define([_AC_CHECK_HEADER_OLD],
173 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
174 AC_CACHE_CHECK([for $1], [ac_Header],
175                [AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$1>])],
176                                          [AS_VAR_SET([ac_Header], [yes])],
177                                          [AS_VAR_SET([ac_Header], [no])])])
178 AS_IF([test AS_VAR_GET([ac_Header]) = yes], [$2], [$3])[]dnl
179 AS_VAR_POPDEF([ac_Header])dnl
180 ])# _AC_CHECK_HEADER_OLD
183 # AH_CHECK_HEADERS(HEADER-FILE...)
184 # --------------------------------
185 m4_define([AH_CHECK_HEADERS],
186 [m4_foreach_w([AC_Header], [$1],
187   [AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([AC_Header])),
188      [Define to 1 if you have the <]m4_defn([AC_Header])[> header file.])])])
191 # AC_CHECK_HEADERS(HEADER-FILE...,
192 #                  [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
193 #                  [INCLUDES])
194 # ----------------------------------------------------------
195 AC_DEFUN([AC_CHECK_HEADERS],
196 [AH_CHECK_HEADERS([$1])dnl
197 for ac_header in $1
199 AC_CHECK_HEADER($ac_header,
200                 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$ac_header)) $2],
201                 [$3],
202                 [$4])dnl
203 done
204 ])# AC_CHECK_HEADERS
207 # AC_CHECK_HEADERS_ONCE(HEADER-FILE...)
208 # -------------------------------------
209 AC_DEFUN([AC_CHECK_HEADERS_ONCE],
211   AH_CHECK_HEADERS([$1])
212   m4_foreach_w([AC_Header], [$1],
213     [AC_DEFUN([_AC_Header_]m4_quote(m4_translit(AC_Header, [./-], [___])),
214        [m4_divert_text([INIT_PREPARE],
215           [ac_header_list="$ac_header_list AC_Header"])
216         _AC_HEADERS_EXPANSION])
217      AC_REQUIRE([_AC_Header_]m4_quote(m4_translit(AC_Header, [./-], [___])))])
219 m4_define([_AC_HEADERS_EXPANSION],
221   m4_divert_text([DEFAULTS], [ac_header_list=])
222   AC_CHECK_HEADERS([$ac_header_list])
223   m4_define([_AC_HEADERS_EXPANSION], [])
229 ## --------------------- ##
230 ## 2. Default includes.  ##
231 ## --------------------- ##
233 # Always use the same set of default headers for all the generic
234 # macros.  It is easier to document, to extend, and to understand than
235 # having specific defaults for each macro.
237 # _AC_INCLUDES_DEFAULT_REQUIREMENTS
238 # ---------------------------------
239 # Required when AC_INCLUDES_DEFAULT uses its default branch.
240 AC_DEFUN([_AC_INCLUDES_DEFAULT_REQUIREMENTS],
241 [m4_divert_text([DEFAULTS],
242 [# Factoring default headers for most tests.
243 dnl If ever you change this variable, please keep autoconf.texi in sync.
244 ac_includes_default="\
245 #include <stdio.h>
246 #ifdef HAVE_SYS_TYPES_H
247 # include <sys/types.h>
248 #endif
249 #ifdef HAVE_SYS_STAT_H
250 # include <sys/stat.h>
251 #endif
252 #ifdef STDC_HEADERS
253 # include <stdlib.h>
254 # include <stddef.h>
255 #else
256 # ifdef HAVE_STDLIB_H
257 #  include <stdlib.h>
258 # endif
259 #endif
260 #ifdef HAVE_STRING_H
261 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
262 #  include <memory.h>
263 # endif
264 # include <string.h>
265 #endif
266 #ifdef HAVE_STRINGS_H
267 # include <strings.h>
268 #endif
269 #ifdef HAVE_INTTYPES_H
270 # include <inttypes.h>
271 #endif
272 #ifdef HAVE_STDINT_H
273 # include <stdint.h>
274 #endif
275 #ifdef HAVE_UNISTD_H
276 # include <unistd.h>
277 #endif"
278 ])dnl
279 AC_REQUIRE([AC_HEADER_STDC])dnl
280 # On IRIX 5.3, sys/types and inttypes.h are conflicting.
281 AC_CHECK_HEADERS([sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
282                   inttypes.h stdint.h unistd.h],
283                  [], [], $ac_includes_default)
284 ])# _AC_INCLUDES_DEFAULT_REQUIREMENTS
287 # AC_INCLUDES_DEFAULT([INCLUDES])
288 # -------------------------------
289 # If INCLUDES is empty, expand in default includes, otherwise in
290 # INCLUDES.
291 # In most cases INCLUDES is not double quoted as it should, and if
292 # for instance INCLUDES = `#include <stdio.h>' then unless we force
293 # a newline, the hash will swallow the closing paren etc. etc.
294 # The usual failure.
295 # Take no risk: for the newline.
296 AC_DEFUN([AC_INCLUDES_DEFAULT],
297 [m4_ifval([$1], [$1
299           [AC_REQUIRE([_AC_INCLUDES_DEFAULT_REQUIREMENTS])dnl
300 $ac_includes_default])])
306 ## ------------------------------------------- ##
307 ## 3. Headers to check with AC_CHECK_HEADERS.  ##
308 ## ------------------------------------------- ##
310 # errno.h is portable.
312 AN_HEADER([OS.h],               [AC_CHECK_HEADERS])
313 AN_HEADER([argz.h],             [AC_CHECK_HEADERS])
314 AN_HEADER([arpa/inet.h],        [AC_CHECK_HEADERS])
315 AN_HEADER([fcntl.h],            [AC_CHECK_HEADERS])
316 AN_HEADER([fenv.h],             [AC_CHECK_HEADERS])
317 AN_HEADER([float.h],            [AC_CHECK_HEADERS])
318 AN_HEADER([fs_info.h],          [AC_CHECK_HEADERS])
319 AN_HEADER([inttypes.h],         [AC_CHECK_HEADERS])
320 AN_HEADER([langinfo.h],         [AC_CHECK_HEADERS])
321 AN_HEADER([libintl.h],          [AC_CHECK_HEADERS])
322 AN_HEADER([limits.h],           [AC_CHECK_HEADERS])
323 AN_HEADER([locale.h],           [AC_CHECK_HEADERS])
324 AN_HEADER([mach/mach.h],        [AC_CHECK_HEADERS])
325 AN_HEADER([malloc.h],           [AC_CHECK_HEADERS])
326 AN_HEADER([memory.h],           [AC_CHECK_HEADERS])
327 AN_HEADER([mntent.h],           [AC_CHECK_HEADERS])
328 AN_HEADER([mnttab.h],           [AC_CHECK_HEADERS])
329 AN_HEADER([netdb.h],            [AC_CHECK_HEADERS])
330 AN_HEADER([netinet/in.h],       [AC_CHECK_HEADERS])
331 AN_HEADER([nl_types.h],         [AC_CHECK_HEADERS])
332 AN_HEADER([nlist.h],            [AC_CHECK_HEADERS])
333 AN_HEADER([paths.h],            [AC_CHECK_HEADERS])
334 AN_HEADER([sgtty.h],            [AC_CHECK_HEADERS])
335 AN_HEADER([shadow.h],           [AC_CHECK_HEADERS])
336 AN_HEADER([stddef.h],           [AC_CHECK_HEADERS])
337 AN_HEADER([stdint.h],           [AC_CHECK_HEADERS])
338 AN_HEADER([stdio_ext.h],        [AC_CHECK_HEADERS])
339 AN_HEADER([stdlib.h],           [AC_CHECK_HEADERS])
340 AN_HEADER([string.h],           [AC_CHECK_HEADERS])
341 AN_HEADER([strings.h],          [AC_CHECK_HEADERS])
342 AN_HEADER([sys/acl.h],          [AC_CHECK_HEADERS])
343 AN_HEADER([sys/file.h],         [AC_CHECK_HEADERS])
344 AN_HEADER([sys/filsys.h],       [AC_CHECK_HEADERS])
345 AN_HEADER([sys/fs/s5param.h],   [AC_CHECK_HEADERS])
346 AN_HEADER([sys/fs_types.h],     [AC_CHECK_HEADERS])
347 AN_HEADER([sys/fstyp.h],        [AC_CHECK_HEADERS])
348 AN_HEADER([sys/ioctl.h],        [AC_CHECK_HEADERS])
349 AN_HEADER([sys/mntent.h],       [AC_CHECK_HEADERS])
350 AN_HEADER([sys/mount.h],        [AC_CHECK_HEADERS])
351 AN_HEADER([sys/param.h],        [AC_CHECK_HEADERS])
352 AN_HEADER([sys/socket.h],       [AC_CHECK_HEADERS])
353 AN_HEADER([sys/statfs.h],       [AC_CHECK_HEADERS])
354 AN_HEADER([sys/statvfs.h],      [AC_CHECK_HEADERS])
355 AN_HEADER([sys/systeminfo.h],   [AC_CHECK_HEADERS])
356 AN_HEADER([sys/time.h],         [AC_CHECK_HEADERS])
357 AN_HEADER([sys/timeb.h],        [AC_CHECK_HEADERS])
358 AN_HEADER([sys/vfs.h],          [AC_CHECK_HEADERS])
359 AN_HEADER([sys/window.h],       [AC_CHECK_HEADERS])
360 AN_HEADER([syslog.h],           [AC_CHECK_HEADERS])
361 AN_HEADER([termio.h],           [AC_CHECK_HEADERS])
362 AN_HEADER([termios.h],          [AC_CHECK_HEADERS])
363 AN_HEADER([unistd.h],           [AC_CHECK_HEADERS])
364 AN_HEADER([utime.h],            [AC_CHECK_HEADERS])
365 AN_HEADER([utmp.h],             [AC_CHECK_HEADERS])
366 AN_HEADER([utmpx.h],            [AC_CHECK_HEADERS])
367 AN_HEADER([values.h],           [AC_CHECK_HEADERS])
368 AN_HEADER([wchar.h],            [AC_CHECK_HEADERS])
369 AN_HEADER([wctype.h],           [AC_CHECK_HEADERS])
373 ## ------------------------------- ##
374 ## 4. Tests for specific headers.  ##
375 ## ------------------------------- ##
377 # AC_HEADER_ASSERT
378 # ----------------
379 # Check whether to enable assertions.
380 AC_DEFUN([AC_HEADER_ASSERT],
382   AC_MSG_CHECKING([whether to enable assertions])
383   AC_ARG_ENABLE([assert],
384     [  --disable-assert        turn off assertions],
385     [AC_MSG_RESULT([no])
386      AC_DEFINE(NDEBUG, 1, [Define to 1 if assertions should be disabled.])],
387     [AC_MSG_RESULT(yes)])
391 # _AC_CHECK_HEADER_DIRENT(HEADER-FILE,
392 #                         [ACTION-IF-FOUND], [ACTION-IF-NOT_FOUND])
393 # -----------------------------------------------------------------
394 # Like AC_CHECK_HEADER, except also make sure that HEADER-FILE
395 # defines the type `DIR'.  dirent.h on NextStep 3.2 doesn't.
396 m4_define([_AC_CHECK_HEADER_DIRENT],
397 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_dirent_$1])dnl
398 AC_CACHE_CHECK([for $1 that defines DIR], [ac_Header],
399 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
400 #include <$1>
402                                     [if ((DIR *) 0)
403 return 0;])],
404                    [AS_VAR_SET([ac_Header], [yes])],
405                    [AS_VAR_SET([ac_Header], [no])])])
406 AS_IF([test AS_VAR_GET([ac_Header]) = yes], [$2], [$3])[]dnl
407 AS_VAR_POPDEF([ac_Header])dnl
408 ])# _AC_CHECK_HEADER_DIRENT
411 # AH_CHECK_HEADERS_DIRENT(HEADERS...)
412 # -----------------------------------
413 m4_define([AH_CHECK_HEADERS_DIRENT],
414 [m4_foreach_w([AC_Header], [$1],
415   [AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([AC_Header])),
416                [Define to 1 if you have the <]m4_defn([AC_Header])[> header file, and
417                 it defines `DIR'.])])])
420 # AC_HEADER_DIRENT
421 # ----------------
422 AC_DEFUN([AC_HEADER_DIRENT],
423 [AH_CHECK_HEADERS_DIRENT(dirent.h sys/ndir.h sys/dir.h ndir.h)
424 ac_header_dirent=no
425 for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
426   _AC_CHECK_HEADER_DIRENT($ac_hdr,
427                           [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$ac_hdr), 1)
428 ac_header_dirent=$ac_hdr; break])
429 done
430 # Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
431 if test $ac_header_dirent = dirent.h; then
432   AC_SEARCH_LIBS(opendir, dir)
433 else
434   AC_SEARCH_LIBS(opendir, x)
436 ])# AC_HEADER_DIRENT
439 # AC_HEADER_MAJOR
440 # ---------------
441 AN_FUNCTION([major],     [AC_HEADER_MAJOR])
442 AN_FUNCTION([makedev],   [AC_HEADER_MAJOR])
443 AN_FUNCTION([minor],     [AC_HEADER_MAJOR])
444 AN_HEADER([sys/mkdev.h], [AC_HEADER_MAJOR])
445 AC_DEFUN([AC_HEADER_MAJOR],
446 [AC_CACHE_CHECK(whether sys/types.h defines makedev,
447                 ac_cv_header_sys_types_h_makedev,
448 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <sys/types.h>]],
449                                  [[return makedev(0, 0);]])],
450                 [ac_cv_header_sys_types_h_makedev=yes],
451                 [ac_cv_header_sys_types_h_makedev=no])
454 if test $ac_cv_header_sys_types_h_makedev = no; then
455 AC_CHECK_HEADER(sys/mkdev.h,
456                 [AC_DEFINE(MAJOR_IN_MKDEV, 1,
457                            [Define to 1 if `major', `minor', and `makedev' are
458                             declared in <mkdev.h>.])])
460   if test $ac_cv_header_sys_mkdev_h = no; then
461     AC_CHECK_HEADER(sys/sysmacros.h,
462                     [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
463                                [Define to 1 if `major', `minor', and `makedev'
464                                 are declared in <sysmacros.h>.])])
465   fi
467 ])# AC_HEADER_MAJOR
470 # AC_HEADER_RESOLV
471 # ----------------
472 # According to http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?resolver+3
473 # (or http://www.chemie.fu-berlin.de/cgi-bin/man/sgi_irix?resolver+3),
474 # sys/types.h, netinet/in.h and arpa/nameser.h are required on IRIX.
475 # netinet/in.h is needed on Cygwin, too.
476 # With Solaris 9, netdb.h is required, to get symbols like HOST_NOT_FOUND.
478 AN_HEADER(resolv.h,     [AC_HEADER_RESOLV])
479 AC_DEFUN([AC_HEADER_RESOLV],
480 [AC_CHECK_HEADERS(sys/types.h netinet/in.h arpa/nameser.h netdb.h resolv.h,
481                   [], [],
482 [[#ifdef HAVE_SYS_TYPES_H
483 #  include <sys/types.h>
484 #endif
485 #ifdef HAVE_NETINET_IN_H
486 #  include <netinet/in.h>   /* inet_ functions / structs */
487 #endif
488 #ifdef HAVE_ARPA_NAMESER_H
489 #  include <arpa/nameser.h> /* DNS HEADER struct */
490 #endif
491 #ifdef HAVE_NETDB_H
492 #  include <netdb.h>
493 #endif]])
494 ])# AC_HEADER_RESOLV
497 # AC_HEADER_STAT
498 # --------------
499 # FIXME: Shouldn't this be named AC_HEADER_SYS_STAT?
500 AC_DEFUN([AC_HEADER_STAT],
501 [AC_CACHE_CHECK(whether stat file-mode macros are broken,
502   ac_cv_header_stat_broken,
503 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <sys/types.h>
504 #include <sys/stat.h>
506 #if defined S_ISBLK && defined S_IFDIR
507 extern char c1[S_ISBLK (S_IFDIR) ? -1 : 1];
508 #endif
510 #if defined S_ISBLK && defined S_IFCHR
511 extern char c2[S_ISBLK (S_IFCHR) ? -1 : 1];
512 #endif
514 #if defined S_ISLNK && defined S_IFREG
515 extern char c3[S_ISLNK (S_IFREG) ? -1 : 1];
516 #endif
518 #if defined S_ISSOCK && defined S_IFREG
519 extern char c4[S_ISSOCK (S_IFREG) ? -1 : 1];
520 #endif
521 ]])], ac_cv_header_stat_broken=no, ac_cv_header_stat_broken=yes)])
522 if test $ac_cv_header_stat_broken = yes; then
523   AC_DEFINE(STAT_MACROS_BROKEN, 1,
524             [Define to 1 if the `S_IS*' macros in <sys/stat.h> do not
525              work properly.])
527 ])# AC_HEADER_STAT
530 # AC_HEADER_STDBOOL
531 # -----------------
532 # Check for stdbool.h that conforms to C99.
533 AN_IDENTIFIER([bool], [AC_HEADER_STDBOOL])
534 AN_IDENTIFIER([true], [AC_HEADER_STDBOOL])
535 AN_IDENTIFIER([false],[AC_HEADER_STDBOOL])
536 AC_DEFUN([AC_HEADER_STDBOOL],
537 [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
538    [ac_cv_header_stdbool_h],
539    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
540       [[
541 #include <stdbool.h>
542 #ifndef bool
543  "error: bool is not defined"
544 #endif
545 #ifndef false
546  "error: false is not defined"
547 #endif
548 #if false
549  "error: false is not 0"
550 #endif
551 #ifndef true
552  "error: true is not defined"
553 #endif
554 #if true != 1
555  "error: true is not 1"
556 #endif
557 #ifndef __bool_true_false_are_defined
558  "error: __bool_true_false_are_defined is not defined"
559 #endif
561         struct s { _Bool s: 1; _Bool t; } s;
563         char a[true == 1 ? 1 : -1];
564         char b[false == 0 ? 1 : -1];
565         char c[__bool_true_false_are_defined == 1 ? 1 : -1];
566         char d[(bool) 0.5 == true ? 1 : -1];
567         bool e = &s;
568         char f[(_Bool) 0.0 == false ? 1 : -1];
569         char g[true];
570         char h[sizeof (_Bool)];
571         char i[sizeof s.t];
572         enum { j = false, k = true, l = false * true, m = true * 256 };
573         _Bool n[m];
574         char o[sizeof n == m * sizeof n[0] ? 1 : -1];
575         char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
576 #       if defined __xlc__ || defined __GNUC__
577          /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
578             reported by James Lemley on 2005-10-05; see
579             http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
580             This test is not quite right, since xlc is allowed to
581             reject this program, as the initializer for xlcbug is
582             not one of the forms that C requires support for.
583             However, doing the test right would require a runtime
584             test, and that would make cross-compilation harder.
585             Let us hope that IBM fixes the xlc bug, and also adds
586             support for this kind of constant expression.  In the
587             meantime, this test will reject xlc, which is OK, since
588             our stdbool.h substitute should suffice.  We also test
589             this with GCC, where it should work, to detect more
590             quickly whether someone messes up the test in the
591             future.  */
592          char digs[] = "0123456789";
593          int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
594 #       endif
595         /* Catch a bug in an HP-UX C compiler.  See
596            http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
597            http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
598          */
599         _Bool q = true;
600         _Bool *pq = &q;
601       ]],
602       [[
603         *pq |= q;
604         *pq |= ! q;
605         /* Refer to every declared value, to avoid compiler optimizations.  */
606         return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
607                 + !m + !n + !o + !p + !q + !pq);
608       ]])],
609       [ac_cv_header_stdbool_h=yes],
610       [ac_cv_header_stdbool_h=no])])
611 AC_CHECK_TYPES([_Bool])
612 if test $ac_cv_header_stdbool_h = yes; then
613   AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
615 ])# AC_HEADER_STDBOOL
618 # AC_HEADER_STDC
619 # --------------
620 AC_DEFUN([AC_HEADER_STDC],
621 [AC_CACHE_CHECK(for ANSI C header files, ac_cv_header_stdc,
622 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
623 #include <stdarg.h>
624 #include <string.h>
625 #include <float.h>
626 ]])],
627                     [ac_cv_header_stdc=yes],
628                     [ac_cv_header_stdc=no])
630 if test $ac_cv_header_stdc = yes; then
631   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
632   AC_EGREP_HEADER(memchr, string.h, , ac_cv_header_stdc=no)
635 if test $ac_cv_header_stdc = yes; then
636   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
637   AC_EGREP_HEADER(free, stdlib.h, , ac_cv_header_stdc=no)
640 if test $ac_cv_header_stdc = yes; then
641   # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
642   AC_RUN_IFELSE([AC_LANG_SOURCE(
643 [[#include <ctype.h>
644 #include <stdlib.h>
645 #if ((' ' & 0x0FF) == 0x020)
646 # define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
647 # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
648 #else
649 # define ISLOWER(c) \
650                    (('a' <= (c) && (c) <= 'i') \
651                      || ('j' <= (c) && (c) <= 'r') \
652                      || ('s' <= (c) && (c) <= 'z'))
653 # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
654 #endif
656 #define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
658 main ()
660   int i;
661   for (i = 0; i < 256; i++)
662     if (XOR (islower (i), ISLOWER (i))
663         || toupper (i) != TOUPPER (i))
664       return 2;
665   return 0;
666 }]])], , ac_cv_header_stdc=no, :)
667 fi])
668 if test $ac_cv_header_stdc = yes; then
669   AC_DEFINE(STDC_HEADERS, 1,
670             [Define to 1 if you have the ANSI C header files.])
672 ])# AC_HEADER_STDC
675 # AC_HEADER_SYS_WAIT
676 # ------------------
677 AC_DEFUN([AC_HEADER_SYS_WAIT],
678 [AC_CACHE_CHECK([for sys/wait.h that is POSIX.1 compatible],
679   ac_cv_header_sys_wait_h,
680 [AC_COMPILE_IFELSE(
681 [AC_LANG_PROGRAM([#include <sys/types.h>
682 #include <sys/wait.h>
683 #ifndef WEXITSTATUS
684 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
685 #endif
686 #ifndef WIFEXITED
687 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
688 #endif
690 [  int s;
691   wait (&s);
692   s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;])],
693                  [ac_cv_header_sys_wait_h=yes],
694                  [ac_cv_header_sys_wait_h=no])])
695 if test $ac_cv_header_sys_wait_h = yes; then
696   AC_DEFINE(HAVE_SYS_WAIT_H, 1,
697             [Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible.])
699 ])# AC_HEADER_SYS_WAIT
702 # AC_HEADER_TIME
703 # --------------
704 AC_DEFUN([AC_HEADER_TIME],
705 [AC_CACHE_CHECK([whether time.h and sys/time.h may both be included],
706   ac_cv_header_time,
707 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
708 #include <sys/time.h>
709 #include <time.h>
711 [if ((struct tm *) 0)
712 return 0;])],
713                    [ac_cv_header_time=yes],
714                    [ac_cv_header_time=no])])
715 if test $ac_cv_header_time = yes; then
716   AC_DEFINE(TIME_WITH_SYS_TIME, 1,
717             [Define to 1 if you can safely include both <sys/time.h>
718              and <time.h>.])
720 ])# AC_HEADER_TIME
723 # _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
724 # ----------------------------------
725 m4_define([_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H],
726 [AC_CACHE_CHECK([whether termios.h defines TIOCGWINSZ],
727                 ac_cv_sys_tiocgwinsz_in_termios_h,
728 [AC_EGREP_CPP([yes],
729               [#include <sys/types.h>
730 #include <termios.h>
731 #ifdef TIOCGWINSZ
732   yes
733 #endif
735                 ac_cv_sys_tiocgwinsz_in_termios_h=yes,
736                 ac_cv_sys_tiocgwinsz_in_termios_h=no)])
737 ])# _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
740 # _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
741 # ----------------------------------
742 m4_define([_AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL],
743 [AC_CACHE_CHECK([whether sys/ioctl.h defines TIOCGWINSZ],
744                 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h,
745 [AC_EGREP_CPP([yes],
746               [#include <sys/types.h>
747 #include <sys/ioctl.h>
748 #ifdef TIOCGWINSZ
749   yes
750 #endif
752                 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes,
753                 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no)])
754 ])# _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
757 # AC_HEADER_TIOCGWINSZ
758 # --------------------
759 # Look for a header that defines TIOCGWINSZ.
760 # FIXME: Is this the proper name?  Is this the proper implementation?
761 # I need more help.
762 AC_DEFUN([AC_HEADER_TIOCGWINSZ],
763 [_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
764 if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then
765   _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
766   if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then
767     AC_DEFINE(GWINSZ_IN_SYS_IOCTL,1,
768               [Define to 1 if `TIOCGWINSZ' requires <sys/ioctl.h>.])
769   fi
771 ])# AC_HEADER_TIOCGWINSZ
774 # AU::AC_UNISTD_H
775 # ---------------
776 AU_DEFUN([AC_UNISTD_H],
777 [AC_CHECK_HEADERS(unistd.h)])
780 # AU::AC_USG
781 # ----------
782 # Define `USG' if string functions are in strings.h.
783 AU_DEFUN([AC_USG],
784 [AC_MSG_CHECKING([for BSD string and memory functions])
785 AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <strings.h>]],
786                                 [[rindex(0, 0); bzero(0, 0);]])],
787                [AC_MSG_RESULT(yes)],
788                [AC_MSG_RESULT(no)
789                 AC_DEFINE(USG, 1,
790                           [Define to 1 if you do not have <strings.h>, index,
791                            bzero, etc... This symbol is obsolete, you should
792                            not depend upon it.])])
793 AC_CHECK_HEADERS(string.h)],
794 [Remove `AC_MSG_CHECKING', `AC_LINK_IFELSE' and this warning
795 when you adjust your code to use HAVE_STRING_H.])
798 # AU::AC_MEMORY_H
799 # ---------------
800 # To be precise this macro used to be:
802 #   | AC_MSG_CHECKING(whether string.h declares mem functions)
803 #   | AC_EGREP_HEADER(memchr, string.h, ac_found=yes, ac_found=no)
804 #   | AC_MSG_RESULT($ac_found)
805 #   | if test $ac_found = no; then
806 #   |   AC_CHECK_HEADER(memory.h, [AC_DEFINE(NEED_MEMORY_H)])
807 #   | fi
809 # But it is better to check for both headers, and alias NEED_MEMORY_H to
810 # HAVE_MEMORY_H.
811 AU_DEFUN([AC_MEMORY_H],
812 [AC_CHECK_HEADER(memory.h,
813                 [AC_DEFINE([NEED_MEMORY_H], 1,
814                            [Same as `HAVE_MEMORY_H', don't depend on me.])])
815 AC_CHECK_HEADERS(string.h memory.h)],
816 [Remove this warning and
817 `AC_CHECK_HEADER(memory.h, AC_DEFINE(...))' when you adjust your code to
818 use HAVE_STRING_H and HAVE_MEMORY_H, not NEED_MEMORY_H.])
821 # AU::AC_DIR_HEADER
822 # -----------------
823 # Like calling `AC_HEADER_DIRENT' and `AC_FUNC_CLOSEDIR_VOID', but
824 # defines a different set of C preprocessor macros to indicate which
825 # header file is found.
826 AU_DEFUN([AC_DIR_HEADER],
827 [AC_HEADER_DIRENT
828 AC_FUNC_CLOSEDIR_VOID
829 test ac_cv_header_dirent_dirent_h &&
830   AC_DEFINE([DIRENT], 1, [Same as `HAVE_DIRENT_H', don't depend on me.])
831 test ac_cv_header_dirent_sys_ndir_h &&
832   AC_DEFINE([SYSNDIR], 1, [Same as `HAVE_SYS_NDIR_H', don't depend on me.])
833 test ac_cv_header_dirent_sys_dir_h &&
834   AC_DEFINE([SYSDIR], 1, [Same as `HAVE_SYS_DIR_H', don't depend on me.])
835 test ac_cv_header_dirent_ndir_h &&
836   AC_DEFINE([NDIR], 1, [Same as `HAVE_NDIR_H', don't depend on me.])],
837 [Remove this warning and the four `AC_DEFINE' when you
838 adjust your code to use `AC_HEADER_DIRENT'.])