1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Checking for headers.
4 # Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # As a special exception, the Free Software Foundation gives unlimited
22 # permission to copy, distribute and modify the configure scripts that
23 # are the output of Autoconf. You need not follow the terms of the GNU
24 # General Public License when using or distributing such scripts, even
25 # though portions of the text of Autoconf appear in them. The GNU
26 # General Public License (GPL) does govern all other use of the material
27 # that constitutes the Autoconf program.
29 # Certain portions of the Autoconf source text are designed to be copied
30 # (in certain cases, depending on the input) into the output of
31 # Autoconf. We call these the "data" portions. The rest of the Autoconf
32 # source text consists of comments plus executable code that decides which
33 # of the data portions to output in any given case. We call these
34 # comments and executable code the "non-data" portions. Autoconf never
35 # copies any of the non-data portions into its output.
37 # This special exception to the GPL applies to versions of Autoconf
38 # released by the Free Software Foundation. When you make and
39 # distribute a modified version of Autoconf, you may extend this special
40 # exception to the GPL to apply to your modified version as well, *unless*
41 # your modified version has the potential to copy into its output some
42 # of the text that was the non-data portion of the version that you started
43 # with. (In other words, unless your change moves or copies text from
44 # the non-data portions to the data portions.) If your modification has
45 # such potential, you must delete any notice of this special exception
46 # to the GPL from your modified version.
48 # Written by David MacKenzie, with help from
49 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
50 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
55 # 1. Generic tests for headers
56 # 2. Tests for specific headers
59 ## ------------------------------ ##
60 ## 1. Generic tests for headers. ##
61 ## ------------------------------ ##
64 # AC_CHECK_HEADER(HEADER-FILE,
65 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
67 # ---------------------------------------------------------
68 # If INCLUDES is empty and strictly empty, use the preprocessor to
69 # check whether HEADER-FILE exists. If INCLUDES is set, then use the
70 # compiler to check whether INCLUDES followed by HEADER-FILE compiles
72 AC_DEFUN([AC_CHECK_HEADER],
73 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
74 AC_CACHE_CHECK([for $1], ac_Header,
76 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([$4
78 [AS_VAR_SET(ac_Header, yes)],
79 [AS_VAR_SET(ac_Header, no)])],
80 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$1>])],
81 [AS_VAR_SET(ac_Header, yes)],
82 [AS_VAR_SET(ac_Header, no)])])])
83 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
84 AS_VAR_POPDEF([ac_Header])dnl
88 # AH_CHECK_HEADERS(HEADER-FILE...)
89 # --------------------------------
90 m4_define([AH_CHECK_HEADERS],
91 [AC_FOREACH([AC_Header], [$1],
92 [AH_TEMPLATE(AS_TR_CPP(HAVE_[]AC_Header),
93 [Define if you have the <]AC_Header[> header file.])])])
96 # AC_CHECK_HEADERS(HEADER-FILE...
97 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
99 # ----------------------------------------------------------
100 AC_DEFUN([AC_CHECK_HEADERS],
101 [AH_CHECK_HEADERS([$1])dnl
104 AC_CHECK_HEADER($ac_header,
105 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$ac_header)) $2],
115 ## ------------------------------- ##
116 ## 2. Tests for specific headers. ##
117 ## ------------------------------- ##
120 # _AC_CHECK_HEADER_DIRENT(HEADER-FILE,
121 # [ACTION-IF-FOUND], [ACTION-IF-NOT_FOUND])
122 # -----------------------------------------------------------------
123 # Like AC_CHECK_HEADER, except also make sure that HEADER-FILE
124 # defines the type `DIR'. dirent.h on NextStep 3.2 doesn't.
125 m4_define([_AC_CHECK_HEADER_DIRENT],
126 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_dirent_$1])dnl
127 AC_CACHE_CHECK([for $1 that defines DIR], ac_Header,
128 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
133 [AS_VAR_SET(ac_Header, yes)],
134 [AS_VAR_SET(ac_Header, no)])])
135 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
136 AS_VAR_POPDEF([ac_Header])dnl
137 ])# _AC_CHECK_HEADER_DIRENT
140 # AH_CHECK_HEADERS_DIRENT(HEADERS...)
141 # -----------------------------------
142 m4_define([AH_CHECK_HEADERS_DIRENT],
143 [AC_FOREACH([AC_Header], [$1],
144 [AH_TEMPLATE(AS_TR_CPP(HAVE_[]AC_Header),
145 [Define if you have the <]AC_Header[> header file, and
146 it defines `DIR'.])])])
151 AC_DEFUN([AC_HEADER_DIRENT],
152 [AH_CHECK_HEADERS_DIRENT(dirent.h sys/ndir.h sys/dir.h ndir.h)
154 for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
155 _AC_CHECK_HEADER_DIRENT($ac_hdr,
156 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$ac_hdr), 1)
157 ac_header_dirent=$ac_hdr; break])
159 # Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
160 if test $ac_header_dirent = dirent.h; then
161 AC_CHECK_LIB(dir, opendir, LIBS="$LIBS -ldir")
163 AC_CHECK_LIB(x, opendir, LIBS="$LIBS -lx")
170 AC_DEFUN([AC_HEADER_MAJOR],
171 [AC_CACHE_CHECK(whether sys/types.h defines makedev,
172 ac_cv_header_sys_types_h_makedev,
173 [AC_TRY_LINK([#include <sys/types.h>
174 ], [return makedev(0, 0);],
175 ac_cv_header_sys_types_h_makedev=yes, ac_cv_header_sys_types_h_makedev=no)
178 if test $ac_cv_header_sys_types_h_makedev = no; then
179 AC_CHECK_HEADER(sys/mkdev.h,
180 [AC_DEFINE(MAJOR_IN_MKDEV, 1,
181 [Define if `major', `minor', and `makedev' are
182 declared in <mkdev.h>.])])
184 if test $ac_cv_header_sys_mkdev_h = no; then
185 AC_CHECK_HEADER(sys/sysmacros.h,
186 [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
187 [Define if `major', `minor', and `makedev' are
188 declared in <sysmacros.h>.])])
196 # FIXME: Shouldn't this be named AC_HEADER_SYS_STAT?
197 AC_DEFUN([AC_HEADER_STAT],
198 [AC_CACHE_CHECK(whether stat file-mode macros are broken,
199 ac_cv_header_stat_broken,
200 [AC_EGREP_CPP([You lose], [#include <sys/types.h>
201 #include <sys/stat.h>
203 #if defined(S_ISBLK) && defined(S_IFDIR)
204 # if S_ISBLK (S_IFDIR)
209 #if defined(S_ISBLK) && defined(S_IFCHR)
210 # if S_ISBLK (S_IFCHR)
215 #if defined(S_ISLNK) && defined(S_IFREG)
216 # if S_ISLNK (S_IFREG)
221 #if defined(S_ISSOCK) && defined(S_IFREG)
222 # if S_ISSOCK (S_IFREG)
226 ], ac_cv_header_stat_broken=yes, ac_cv_header_stat_broken=no)])
227 if test $ac_cv_header_stat_broken = yes; then
228 AC_DEFINE(STAT_MACROS_BROKEN, 1,
229 [Define if the `S_IS*' macros in <sys/stat.h> do not
237 AC_DEFUN([AC_HEADER_STDC],
238 [AC_CACHE_CHECK(for ANSI C header files, ac_cv_header_stdc,
239 [AC_TRY_CPP([#include <stdlib.h>
243 ], ac_cv_header_stdc=yes, ac_cv_header_stdc=no)
245 if test $ac_cv_header_stdc = yes; then
246 # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
247 AC_EGREP_HEADER(memchr, string.h, , ac_cv_header_stdc=no)
250 if test $ac_cv_header_stdc = yes; then
251 # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
252 AC_EGREP_HEADER(free, stdlib.h, , ac_cv_header_stdc=no)
255 if test $ac_cv_header_stdc = yes; then
256 # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
259 #if ((' ' & 0x0FF) == 0x020)
260 # define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
261 # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
263 # define ISLOWER(c) (('a' <= (c) && (c) <= 'i') \
264 || ('j' <= (c) && (c) <= 'r') \
265 || ('s' <= (c) && (c) <= 'z'))
266 # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
269 #define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
274 for (i = 0; i < 256; i++)
275 if (XOR (islower (i), ISLOWER (i))
276 || toupper (i) != TOUPPER (i))
279 }], , ac_cv_header_stdc=no, :)
281 if test $ac_cv_header_stdc = yes; then
282 AC_DEFINE(STDC_HEADERS, 1, [Define if you have the ANSI C header files.])
289 AC_DEFUN([AC_HEADER_SYS_WAIT],
290 [AC_CACHE_CHECK([for sys/wait.h that is POSIX.1 compatible],
291 ac_cv_header_sys_wait_h,
293 [AC_LANG_PROGRAM([#include <sys/types.h>
294 #include <sys/wait.h>
296 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
299 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
304 s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;])],
305 [ac_cv_header_sys_wait_h=yes],
306 [ac_cv_header_sys_wait_h=no])])
307 if test $ac_cv_header_sys_wait_h = yes; then
308 AC_DEFINE(HAVE_SYS_WAIT_H, 1,
309 [Define if you have <sys/wait.h> that is POSIX.1 compatible.])
311 ])# AC_HEADER_SYS_WAIT
316 AC_DEFUN([AC_HEADER_TIME],
317 [AC_CACHE_CHECK([whether time.h and sys/time.h may both be included],
319 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
320 #include <sys/time.h>
323 [if ((struct tm *) 0)
325 [ac_cv_header_time=yes],
326 [ac_cv_header_time=no])])
327 if test $ac_cv_header_time = yes; then
328 AC_DEFINE(TIME_WITH_SYS_TIME, 1,
329 [Define if you can safely include both <sys/time.h> and <time.h>.])
334 # _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
335 # ----------------------------------
336 m4_define([_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H],
337 [AC_CACHE_CHECK([whether termios.h defines TIOCGWINSZ],
338 ac_cv_sys_tiocgwinsz_in_termios_h,
340 [#include <sys/types.h>
346 ac_cv_sys_tiocgwinsz_in_termios_h=yes,
347 ac_cv_sys_tiocgwinsz_in_termios_h=no)])
348 ])# _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
351 # _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
352 # ----------------------------------
353 m4_define([_AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL],
354 [AC_CACHE_CHECK([whether sys/ioctl.h defines TIOCGWINSZ],
355 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h,
357 [#include <sys/types.h>
358 #include <sys/ioctl.h>
363 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes,
364 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no)])
365 ])# _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
368 # AC_HEADER_TIOCGWINSZ
369 # --------------------
370 # Look for a header that defines TIOCGWINSZ.
371 # FIXME: Is this the proper name? Is this the proper implementation?
373 AC_DEFUN([AC_HEADER_TIOCGWINSZ],
374 [AC_REQUIRE([AC_SYS_POSIX_TERMIOS])dnl
375 if test $ac_cv_sys_posix_termios = yes; then
376 _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
378 if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then
379 _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
380 if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then
381 AC_DEFINE(GWINSZ_IN_SYS_IOCTL,1,
382 [Define if `TIOCGWINSZ' requires <sys/ioctl.h>])
385 ])# AC_HEADER_TIOCGWINSZ
390 AU_DEFUN([AC_UNISTD_H],
391 [AC_CHECK_HEADERS(unistd.h)])
396 # Define `USG' if string functions are in strings.h.
398 [AC_DIAGNOSE([obsolete],
399 [$0: Remove `AC_MSG_CHECKING', `AC_TRY_LINK' and this `AC_WARNING'
400 when you ajust your code to use HAVE_STRING_H.])dnl
401 AC_MSG_CHECKING([for BSD string and memory functions])
402 AC_TRY_LINK([@%:@include <strings.h>], [rindex(0, 0); bzero(0, 0);],
403 [AC_MSG_RESULT(yes)],
406 [Define if you do not have <strings.h>, index, bzero, etc...
407 This symbol is obsolete, you should not depend upon it.])])
408 AC_CHECK_HEADERS(string.h)])
413 # To be precise this macro used to be:
415 # | AC_MSG_CHECKING(whether string.h declares mem functions)
416 # | AC_EGREP_HEADER(memchr, string.h, ac_found=yes, ac_found=no)
417 # | AC_MSG_RESULT($ac_found)
418 # | if test $ac_found = no; then
419 # | AC_CHECK_HEADER(memory.h, [AC_DEFINE(NEED_MEMORY_H)])
422 # But it is better to check for both headers, and alias NEED_MEMORY_H to
424 AU_DEFUN([AC_MEMORY_H],
425 [AC_DIAGNOSE([obsolete], [$0: Remove this warning and
426 `AC_CHECK_HEADER(memory.h, AC_DEFINE(...))' when you ajust your code to
427 use and HAVE_STRING_H and HAVE_MEMORY_H, not NEED_MEMORY_H.])dnl
428 AC_CHECK_HEADER(memory.h,
429 [AC_DEFINE([NEED_MEMORY_H], 1,
430 [Same as `HAVE_MEMORY_H', don't depend on me.])])
431 AC_CHECK_HEADERS(string.h memory.h)
437 # Like calling `AC_HEADER_DIRENT' and `AC_FUNC_CLOSEDIR_VOID', but
438 # defines a different set of C preprocessor macros to indicate which
439 # header file is found.
440 AU_DEFUN([AC_DIR_HEADER],
442 AC_FUNC_CLOSEDIR_VOID
443 AC_DIAGNOSE([obsolete],
444 [$0: Remove this warning and the four `AC_DEFINE' when you
445 ajust your code to use `AC_HEADER_DIRENT'.])
446 test ac_cv_header_dirent_dirent_h &&
447 AC_DEFINE([DIRENT], 1, [Same as `HAVE_DIRENT_H', don't depend on me.])
448 test ac_cv_header_dirent_sys_ndir_h &&
449 AC_DEFINE([SYSNDIR], 1, [Same as `HAVE_SYS_NDIR_H', don't depend on me.])
450 test ac_cv_header_dirent_sys_dir_h &&
451 AC_DEFINE([SYSDIR], 1, [Same as `HAVE_SYS_DIR_H', don't depend on me.])
452 test ac_cv_header_dirent_ndir_h &&
453 AC_DEFINE([NDIR], 1, [Same as `HAVE_NDIR_H', don't depend on me.])