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 ## ------------------------------ ##
63 # AC_CHECK_HEADER(HEADER-FILE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
64 # ----------------------------------------------------------------------
65 AC_DEFUN([AC_CHECK_HEADER],
66 [AC_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
67 AC_CACHE_CHECK([for $1], ac_Header,
68 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$1>])],
69 [AC_VAR_SET(ac_Header, yes)],
70 [AC_VAR_SET(ac_Header, no)])])
71 AS_IF([test AC_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
72 AC_VAR_POPDEF([ac_Header])dnl
76 # AH_CHECK_HEADERS(HEADER-FILE...)
77 # --------------------------------
78 m4_define([AH_CHECK_HEADERS],
79 [AC_FOREACH([AC_Header], [$1],
80 [AH_TEMPLATE(AC_TR_CPP(HAVE_[]AC_Header),
81 [Define if you have the <]AC_Header[> header file.])])])
84 # AC_CHECK_HEADERS(HEADER-FILE...
85 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
86 # ----------------------------------------------------------
87 AC_DEFUN([AC_CHECK_HEADERS],
88 [AH_CHECK_HEADERS([$1])dnl
91 AC_CHECK_HEADER($ac_header,
92 [AC_DEFINE_UNQUOTED(AC_TR_CPP(HAVE_$ac_header)) $2],
101 ## ------------------------------- ##
102 ## 2. Tests for specific headers. ##
103 ## ------------------------------- ##
106 # _AC_CHECK_HEADER_DIRENT(HEADER-FILE,
107 # [ACTION-IF-FOUND], [ACTION-IF-NOT_FOUND])
108 # -----------------------------------------------------------------
109 # Like AC_CHECK_HEADER, except also make sure that HEADER-FILE
110 # defines the type `DIR'. dirent.h on NextStep 3.2 doesn't.
111 m4_define([_AC_CHECK_HEADER_DIRENT],
112 [AC_VAR_PUSHDEF([ac_Header], [ac_cv_header_dirent_$1])dnl
113 AC_CACHE_CHECK([for $1 that defines DIR], ac_Header,
114 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
118 [AC_VAR_SET(ac_Header, yes)],
119 [AC_VAR_SET(ac_Header, no)])])
120 AS_IF([test AC_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
121 AC_VAR_POPDEF([ac_Header])dnl
122 ])# _AC_CHECK_HEADER_DIRENT
125 # AH_CHECK_HEADERS_DIRENT(HEADERS...)
126 # -----------------------------------
127 m4_define([AH_CHECK_HEADERS_DIRENT],
128 [AC_FOREACH([AC_Header], [$1],
129 [AH_TEMPLATE(AC_TR_CPP(HAVE_[]AC_Header),
130 [Define if you have the <]AC_Header[> header file, and
131 it defines `DIR'.])])])
136 AC_DEFUN([AC_HEADER_DIRENT],
137 [AH_CHECK_HEADERS_DIRENT(dirent.h sys/ndir.h sys/dir.h ndir.h)
139 for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
140 _AC_CHECK_HEADER_DIRENT($ac_hdr,
141 [AC_DEFINE_UNQUOTED(AC_TR_CPP(HAVE_$ac_hdr), 1)
142 ac_header_dirent=$ac_hdr; break])
144 # Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
145 if test $ac_header_dirent = dirent.h; then
146 AC_CHECK_LIB(dir, opendir, LIBS="$LIBS -ldir")
148 AC_CHECK_LIB(x, opendir, LIBS="$LIBS -lx")
155 AC_DEFUN([AC_HEADER_MAJOR],
156 [AC_CACHE_CHECK(whether sys/types.h defines makedev,
157 ac_cv_header_sys_types_h_makedev,
158 [AC_TRY_LINK([#include <sys/types.h>
159 ], [return makedev(0, 0);],
160 ac_cv_header_sys_types_h_makedev=yes, ac_cv_header_sys_types_h_makedev=no)
163 if test $ac_cv_header_sys_types_h_makedev = no; then
164 AC_CHECK_HEADER(sys/mkdev.h,
165 [AC_DEFINE(MAJOR_IN_MKDEV, 1,
166 [Define if `major', `minor', and `makedev' are
167 declared in <mkdev.h>.])])
169 if test $ac_cv_header_sys_mkdev_h = no; then
170 AC_CHECK_HEADER(sys/sysmacros.h,
171 [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
172 [Define if `major', `minor', and `makedev' are
173 declared in <sysmacros.h>.])])
181 # FIXME: Shouldn't this be named AC_HEADER_SYS_STAT?
182 AC_DEFUN([AC_HEADER_STAT],
183 [AC_CACHE_CHECK(whether stat file-mode macros are broken,
184 ac_cv_header_stat_broken,
185 [AC_EGREP_CPP([You lose], [#include <sys/types.h>
186 #include <sys/stat.h>
188 #if defined(S_ISBLK) && defined(S_IFDIR)
189 # if S_ISBLK (S_IFDIR)
194 #if defined(S_ISBLK) && defined(S_IFCHR)
195 # if S_ISBLK (S_IFCHR)
200 #if defined(S_ISLNK) && defined(S_IFREG)
201 # if S_ISLNK (S_IFREG)
206 #if defined(S_ISSOCK) && defined(S_IFREG)
207 # if S_ISSOCK (S_IFREG)
211 ], ac_cv_header_stat_broken=yes, ac_cv_header_stat_broken=no)])
212 if test $ac_cv_header_stat_broken = yes; then
213 AC_DEFINE(STAT_MACROS_BROKEN, 1,
214 [Define if the `S_IS*' macros in <sys/stat.h> do not
222 AC_DEFUN([AC_HEADER_STDC],
223 [AC_CACHE_CHECK(for ANSI C header files, ac_cv_header_stdc,
224 [AC_TRY_CPP([#include <stdlib.h>
228 ], ac_cv_header_stdc=yes, ac_cv_header_stdc=no)
230 if test $ac_cv_header_stdc = yes; then
231 # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
232 AC_EGREP_HEADER(memchr, string.h, , ac_cv_header_stdc=no)
235 if test $ac_cv_header_stdc = yes; then
236 # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
237 AC_EGREP_HEADER(free, stdlib.h, , ac_cv_header_stdc=no)
240 if test $ac_cv_header_stdc = yes; then
241 # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
244 #if ((' ' & 0x0FF) == 0x020)
245 # define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
246 # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
248 # define ISLOWER(c) (('a' <= (c) && (c) <= 'i') \
249 || ('j' <= (c) && (c) <= 'r') \
250 || ('s' <= (c) && (c) <= 'z'))
251 # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
254 #define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
259 for (i = 0; i < 256; i++)
260 if (XOR (islower (i), ISLOWER (i))
261 || toupper (i) != TOUPPER (i))
264 }], , ac_cv_header_stdc=no, :)
266 if test $ac_cv_header_stdc = yes; then
267 AC_DEFINE(STDC_HEADERS, 1, [Define if you have the ANSI C header files.])
274 AC_DEFUN([AC_HEADER_SYS_WAIT],
275 [AC_CACHE_CHECK([for sys/wait.h that is POSIX.1 compatible],
276 ac_cv_header_sys_wait_h,
278 [AC_LANG_PROGRAM([#include <sys/types.h>
279 #include <sys/wait.h>
281 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
284 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
289 s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;])],
290 [ac_cv_header_sys_wait_h=yes],
291 [ac_cv_header_sys_wait_h=no])])
292 if test $ac_cv_header_sys_wait_h = yes; then
293 AC_DEFINE(HAVE_SYS_WAIT_H, 1,
294 [Define if you have <sys/wait.h> that is POSIX.1 compatible.])
296 ])# AC_HEADER_SYS_WAIT
301 AC_DEFUN([AC_HEADER_TIME],
302 [AC_CACHE_CHECK([whether time.h and sys/time.h may both be included],
304 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
305 #include <sys/time.h>
309 [ac_cv_header_time=yes],
310 [ac_cv_header_time=no])])
311 if test $ac_cv_header_time = yes; then
312 AC_DEFINE(TIME_WITH_SYS_TIME, 1,
313 [Define if you can safely include both <sys/time.h> and <time.h>.])
318 # _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
319 # ----------------------------------
320 m4_define([_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H],
321 [AC_CACHE_CHECK([whether termios.h defines TIOCGWINSZ],
322 ac_cv_sys_tiocgwinsz_in_termios_h,
324 [#include <sys/types.h>
330 ac_cv_sys_tiocgwinsz_in_termios_h=yes,
331 ac_cv_sys_tiocgwinsz_in_termios_h=no)])
332 ])# _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
335 # _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
336 # ----------------------------------
337 m4_define([_AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL],
338 [AC_CACHE_CHECK([whether sys/ioctl.h defines TIOCGWINSZ],
339 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h,
341 [#include <sys/types.h>
342 #include <sys/ioctl.h>
347 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes,
348 ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no)])
349 ])# _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
352 # AC_HEADER_TIOCGWINSZ
353 # --------------------
354 # Look for a header that defines TIOCGWINSZ.
355 # FIXME: Is this the proper name? Is this the proper implementation?
357 AC_DEFUN([AC_HEADER_TIOCGWINSZ],
358 [AC_REQUIRE([AC_SYS_POSIX_TERMIOS])dnl
359 if test $ac_cv_sys_posix_termios = yes; then
360 _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
362 if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then
363 _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
364 if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then
365 AC_DEFINE(GWINSZ_IN_SYS_IOCTL,1,
366 [Define if `TIOCGWINSZ' requires <sys/ioctl.h>])
369 ])# AC_HEADER_TIOCGWINSZ
374 AU_DEFUN([AC_UNISTD_H],
375 [AC_CHECK_HEADERS(unistd.h)])
380 # Define `USG' if string functions are in strings.h.
382 [AC_DIAGNOSE([obsolete],
383 [$0: Remove `AC_MSG_CHECKING', `AC_TRY_LINK' and this `AC_WARNING'
384 when you ajust your code to use HAVE_STRING_H.])dnl
385 AC_MSG_CHECKING([for BSD string and memory functions])
386 AC_TRY_LINK([@%:@include <strings.h>], [rindex(0, 0); bzero(0, 0);],
387 [AC_MSG_RESULT(yes)],
390 [Define if you do not have <strings.h>, index, bzero, etc...
391 This symbol is obsolete, you should not depend upon it.])])
392 AC_CHECK_HEADERS(string.h)])
397 # To be precise this macro used to be:
399 # | AC_MSG_CHECKING(whether string.h declares mem functions)
400 # | AC_EGREP_HEADER(memchr, string.h, ac_found=yes, ac_found=no)
401 # | AC_MSG_RESULT($ac_found)
402 # | if test $ac_found = no; then
403 # | AC_CHECK_HEADER(memory.h, [AC_DEFINE(NEED_MEMORY_H)])
406 # But it is better to check for both headers, and alias NEED_MEMORY_H to
408 AU_DEFUN([AC_MEMORY_H],
409 [AC_DIAGNOSE([obsolete], [$0: Remove this warning and
410 `AC_CHECK_HEADER(memory.h, AC_DEFINE(...))' when you ajust your code to
411 use and HAVE_STRING_H and HAVE_MEMORY_H, not NEED_MEMORY_H.])dnl
412 AC_CHECK_HEADER(memory.h,
413 [AC_DEFINE([NEED_MEMORY_H], 1,
414 [Same as `HAVE_MEMORY_H', don't depend on me.])])
415 AC_CHECK_HEADERS(string.h memory.h)
421 # Like calling `AC_HEADER_DIRENT' and `AC_FUNC_CLOSEDIR_VOID', but
422 # defines a different set of C preprocessor macros to indicate which
423 # header file is found.
424 AU_DEFUN([AC_DIR_HEADER],
426 AC_FUNC_CLOSEDIR_VOID
427 AC_DIAGNOSE([obsolete],
428 [$0: Remove this warning and the four `AC_DEFINE' when you
429 ajust your code to use `AC_HEADER_DIRENT'.])
430 test ac_cv_header_dirent_dirent_h &&
431 AC_DEFINE([DIRENT], 1, [Same as `HAVE_DIRENT_H', don't depend on me.])
432 test ac_cv_header_dirent_sys_ndir_h &&
433 AC_DEFINE([SYSNDIR], 1, [Same as `HAVE_SYS_NDIR_H', don't depend on me.])
434 test ac_cv_header_dirent_sys_dir_h &&
435 AC_DEFINE([SYSDIR], 1, [Same as `HAVE_SYS_DIR_H', don't depend on me.])
436 test ac_cv_header_dirent_ndir_h &&
437 AC_DEFINE([NDIR], 1, [Same as `HAVE_NDIR_H', don't depend on me.])