1# This file is part of Autoconf.			-*- Autoconf -*-
2# Checking for headers.
3#
4# Copyright (C) 1988, 1999-2004, 2006, 2008-2012 Free Software
5# Foundation, Inc.
6
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.
12#
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.
17#
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.
21#
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/>.
26
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.
30
31
32# Table of contents
33#
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
38
39
40## ------------------------------ ##
41## 1. Generic tests for headers.  ##
42## ------------------------------ ##
43
44
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.
56#
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.
60#
61# If INCLUDES is `-', keep only the old semantics.
62#
63# If INCLUDES is specified and different from `-', then use the new
64# semantics only.
65#
66# The m4_indir allows for fewer expansions of $@.
67AC_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
73
74
75# _AC_CHECK_HEADER_MONGREL_BODY
76# -----------------------------
77# Shell function body for _AC_CHECK_HEADER_MONGREL
78m4_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?
83AC_MSG_CHECKING([$[]2 usability])
84AC_COMPILE_IFELSE([AC_LANG_SOURCE([$[]4
85@%:@include <$[]2>])],
86		  [ac_header_compiler=yes],
87		  [ac_header_compiler=no])
88AC_MSG_RESULT([$ac_header_compiler])
89
90# Is the header present?
91AC_MSG_CHECKING([$[]2 presence])
92AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <$[]2>])],
93		  [ac_header_preproc=yes],
94		  [ac_header_preproc=no])
95AC_MSG_RESULT([$ac_header_preproc])
96
97# So?  What about this header?
98case $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])
109m4_ifset([AC_PACKAGE_BUGREPORT],
110[m4_n([( AS_BOX([Report this to ]AC_PACKAGE_BUGREPORT)
111     ) | sed "s/^/$as_me: WARNING:     /" >&2])])dnl
112    ;;
113esac
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
118
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.
125#
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.
129AC_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])], [""])"
140AS_VAR_IF([ac_Header], [yes], [$2], [$3])
141AS_VAR_POPDEF([ac_Header])])# _AC_CHECK_HEADER_MONGREL
142
143
144# _AC_CHECK_HEADER_COMPILE_BODY
145# -----------------------------
146# Shell function body for _AC_CHECK_HEADER_COMPILE
147m4_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
156
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.
162AC_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])], [""])"
172AS_VAR_IF([ac_Header], [yes], [$2], [$3])
173AS_VAR_POPDEF([ac_Header])])# _AC_CHECK_HEADER_COMPILE
174
175# _AC_CHECK_HEADER_PREPROC_BODY
176# -----------------------------
177# Shell function body for _AC_CHECK_HEADER_PREPROC.
178m4_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
186
187
188
189# _AC_CHECK_HEADER_PREPROC(HEADER-FILE,
190#		       [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
191# --------------------------------------------------------------
192# Check the preprocessor accepts HEADER-FILE.
193AC_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"
201AS_VAR_IF([ac_Header], [yes], [$2], [$3])
202AS_VAR_POPDEF([ac_Header])dnl
203])# _AC_CHECK_HEADER_PREPROC
204
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], [-])])
215AC_DEFUN([_AC_CHECK_HEADER_OLD],
216[AC_DIAGNOSE([obsolete], [The macro `$0' is obsolete.
217You should use AC_CHECK_HEADER with a fourth argument.])]dnl
218[_AC_CHECK_HEADER_PREPROC($@)])
219
220AC_DEFUN([_AC_CHECK_HEADER_NEW],
221[AC_DIAGNOSE([obsolete], [The macro `$0' is obsolete.
222You should use AC_CHECK_HEADER with a fourth argument.])]dnl
223[_AC_CHECK_HEADER_COMPILE($@)])
224
225
226# _AH_CHECK_HEADER(HEADER-FILE)
227# -----------------------------
228# Prepare the autoheader snippet for HEADER-FILE.
229m4_define([_AH_CHECK_HEADER],
230[AH_TEMPLATE(AS_TR_CPP([HAVE_$1]),
231  [Define to 1 if you have the <$1> header file.])])
232
233
234# AH_CHECK_HEADERS(HEADER-FILE...)
235# --------------------------------
236m4_define([AH_CHECK_HEADERS],
237[m4_foreach_w([AC_Header], [$1], [_AH_CHECK_HEADER(m4_defn([AC_Header]))])])
238
239
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.
249AC_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
256
257
258# _AC_CHECK_HEADER_ONCE(HEADER-FILE)
259# ----------------------------------
260# Check for a single HEADER-FILE once.
261m4_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    [./-], [___]))])
267
268
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.
273AC_DEFUN([AC_CHECK_HEADERS_ONCE],
274[m4_map_args_w([$1], [_AC_CHECK_HEADER_ONCE(], [)])])
275
276m4_define([_AC_HEADERS_EXPANSION],
277[
278  m4_divert_text([DEFAULTS], [ac_header_list=])
279  AC_CHECK_HEADERS([$ac_header_list], [], [], [AC_INCLUDES_DEFAULT])
280  m4_define([_AC_HEADERS_EXPANSION], [])
281])
282
283
284
285
286## --------------------- ##
287## 2. Default includes.  ##
288## --------------------- ##
289
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.
293
294# _AC_INCLUDES_DEFAULT_REQUIREMENTS
295# ---------------------------------
296# Required when AC_INCLUDES_DEFAULT uses its default branch.
297AC_DEFUN([_AC_INCLUDES_DEFAULT_REQUIREMENTS],
298[m4_divert_text([DEFAULTS],
299[# Factoring default headers for most tests.
300dnl If ever you change this variable, please keep autoconf.texi in sync.
301ac_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
336AC_REQUIRE([AC_HEADER_STDC])dnl
337# On IRIX 5.3, sys/types and inttypes.h are conflicting.
338AC_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
342
343
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.
353AC_DEFUN([AC_INCLUDES_DEFAULT],
354[m4_ifval([$1], [$1
355],
356	  [AC_REQUIRE([_AC_INCLUDES_DEFAULT_REQUIREMENTS])dnl
357$ac_includes_default])])
358
359
360
361
362
363## ------------------------------------------- ##
364## 3. Headers to check with AC_CHECK_HEADERS.  ##
365## ------------------------------------------- ##
366
367# errno.h is portable.
368
369AN_HEADER([OS.h],               [AC_CHECK_HEADERS])
370AN_HEADER([argz.h],             [AC_CHECK_HEADERS])
371AN_HEADER([arpa/inet.h],        [AC_CHECK_HEADERS])
372AN_HEADER([fcntl.h],            [AC_CHECK_HEADERS])
373AN_HEADER([fenv.h],             [AC_CHECK_HEADERS])
374AN_HEADER([float.h],            [AC_CHECK_HEADERS])
375AN_HEADER([fs_info.h],          [AC_CHECK_HEADERS])
376AN_HEADER([inttypes.h],         [AC_CHECK_HEADERS])
377AN_HEADER([langinfo.h],         [AC_CHECK_HEADERS])
378AN_HEADER([libintl.h],          [AC_CHECK_HEADERS])
379AN_HEADER([limits.h],           [AC_CHECK_HEADERS])
380AN_HEADER([locale.h],           [AC_CHECK_HEADERS])
381AN_HEADER([mach/mach.h],        [AC_CHECK_HEADERS])
382AN_HEADER([malloc.h],           [AC_CHECK_HEADERS])
383AN_HEADER([memory.h],           [AC_CHECK_HEADERS])
384AN_HEADER([mntent.h],           [AC_CHECK_HEADERS])
385AN_HEADER([mnttab.h],           [AC_CHECK_HEADERS])
386AN_HEADER([netdb.h],            [AC_CHECK_HEADERS])
387AN_HEADER([netinet/in.h],       [AC_CHECK_HEADERS])
388AN_HEADER([nl_types.h],         [AC_CHECK_HEADERS])
389AN_HEADER([nlist.h],            [AC_CHECK_HEADERS])
390AN_HEADER([paths.h],            [AC_CHECK_HEADERS])
391AN_HEADER([sgtty.h],            [AC_CHECK_HEADERS])
392AN_HEADER([shadow.h],           [AC_CHECK_HEADERS])
393AN_HEADER([stddef.h],           [AC_CHECK_HEADERS])
394AN_HEADER([stdint.h],           [AC_CHECK_HEADERS])
395AN_HEADER([stdio_ext.h],        [AC_CHECK_HEADERS])
396AN_HEADER([stdlib.h],           [AC_CHECK_HEADERS])
397AN_HEADER([string.h],           [AC_CHECK_HEADERS])
398AN_HEADER([strings.h],          [AC_CHECK_HEADERS])
399AN_HEADER([sys/acl.h],          [AC_CHECK_HEADERS])
400AN_HEADER([sys/file.h],         [AC_CHECK_HEADERS])
401AN_HEADER([sys/filsys.h],       [AC_CHECK_HEADERS])
402AN_HEADER([sys/fs/s5param.h],   [AC_CHECK_HEADERS])
403AN_HEADER([sys/fs_types.h],     [AC_CHECK_HEADERS])
404AN_HEADER([sys/fstyp.h],        [AC_CHECK_HEADERS])
405AN_HEADER([sys/ioctl.h],        [AC_CHECK_HEADERS])
406AN_HEADER([sys/mntent.h],       [AC_CHECK_HEADERS])
407AN_HEADER([sys/mount.h],        [AC_CHECK_HEADERS])
408AN_HEADER([sys/param.h],        [AC_CHECK_HEADERS])
409AN_HEADER([sys/socket.h],       [AC_CHECK_HEADERS])
410AN_HEADER([sys/statfs.h],       [AC_CHECK_HEADERS])
411AN_HEADER([sys/statvfs.h],      [AC_CHECK_HEADERS])
412AN_HEADER([sys/systeminfo.h],   [AC_CHECK_HEADERS])
413AN_HEADER([sys/time.h],         [AC_CHECK_HEADERS])
414AN_HEADER([sys/timeb.h],        [AC_CHECK_HEADERS])
415AN_HEADER([sys/vfs.h],          [AC_CHECK_HEADERS])
416AN_HEADER([sys/window.h],       [AC_CHECK_HEADERS])
417AN_HEADER([syslog.h],           [AC_CHECK_HEADERS])
418AN_HEADER([termio.h],           [AC_CHECK_HEADERS])
419AN_HEADER([termios.h],          [AC_CHECK_HEADERS])
420AN_HEADER([unistd.h],           [AC_CHECK_HEADERS])
421AN_HEADER([utime.h],            [AC_CHECK_HEADERS])
422AN_HEADER([utmp.h],             [AC_CHECK_HEADERS])
423AN_HEADER([utmpx.h],            [AC_CHECK_HEADERS])
424AN_HEADER([values.h],           [AC_CHECK_HEADERS])
425AN_HEADER([wchar.h],            [AC_CHECK_HEADERS])
426AN_HEADER([wctype.h],           [AC_CHECK_HEADERS])
427
428
429
430## ------------------------------- ##
431## 4. Tests for specific headers.  ##
432## ------------------------------- ##
433
434# AC_HEADER_ASSERT
435# ----------------
436# Check whether to enable assertions.
437AC_DEFUN_ONCE([AC_HEADER_ASSERT],
438[
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])
452])
453
454
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.
460m4_define([_AC_CHECK_HEADER_DIRENT],
461[AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_dirent_$1])dnl
462AC_CACHE_CHECK([for $1 that defines DIR], [ac_Header],
463[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
464#include <$1>
465],
466				    [if ((DIR *) 0)
467return 0;])],
468		   [AS_VAR_SET([ac_Header], [yes])],
469		   [AS_VAR_SET([ac_Header], [no])])])
470AS_VAR_IF([ac_Header], [yes], [$2], [$3])
471AS_VAR_POPDEF([ac_Header])dnl
472])# _AC_CHECK_HEADER_DIRENT
473
474
475# _AH_CHECK_HEADER_DIRENT(HEADERS)
476# --------------------------------
477# Like _AH_CHECK_HEADER, but tuned to a dirent provider.
478m4_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'.])])
481
482
483# AC_HEADER_DIRENT
484# ----------------
485AC_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
489for 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)
492ac_header_dirent=$ac_hdr; break])
493done
494# Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
495if test $ac_header_dirent = dirent.h; then
496  AC_SEARCH_LIBS(opendir, dir)
497else
498  AC_SEARCH_LIBS(opendir, x)
499fi
500])# AC_HEADER_DIRENT
501
502
503# AC_HEADER_MAJOR
504# ---------------
505AN_FUNCTION([major],     [AC_HEADER_MAJOR])
506AN_FUNCTION([makedev],   [AC_HEADER_MAJOR])
507AN_FUNCTION([minor],     [AC_HEADER_MAJOR])
508AN_HEADER([sys/mkdev.h], [AC_HEADER_MAJOR])
509AC_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])
516])
517
518if test $ac_cv_header_sys_types_h_makedev = no; then
519AC_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>.])])
523
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
530fi
531])# AC_HEADER_MAJOR
532
533
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.
541#
542AN_HEADER(resolv.h,	[AC_HEADER_RESOLV])
543AC_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
559
560
561# AC_HEADER_STAT
562# --------------
563# FIXME: Shouldn't this be named AC_HEADER_SYS_STAT?
564AC_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>
569
570#if defined S_ISBLK && defined S_IFDIR
571extern char c1[S_ISBLK (S_IFDIR) ? -1 : 1];
572#endif
573
574#if defined S_ISBLK && defined S_IFCHR
575extern char c2[S_ISBLK (S_IFCHR) ? -1 : 1];
576#endif
577
578#if defined S_ISLNK && defined S_IFREG
579extern char c3[S_ISLNK (S_IFREG) ? -1 : 1];
580#endif
581
582#if defined S_ISSOCK && defined S_IFREG
583extern char c4[S_ISSOCK (S_IFREG) ? -1 : 1];
584#endif
585]])], ac_cv_header_stat_broken=no, ac_cv_header_stat_broken=yes)])
586if 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.])
590fi
591])# AC_HEADER_STAT
592
593
594# AC_CHECK_HEADER_STDBOOL
595# -----------------
596# Check for stdbool.h that conforms to C99.
597AN_IDENTIFIER([bool], [AC_CHECK_HEADER_STDBOOL])
598AN_IDENTIFIER([true], [AC_CHECK_HEADER_STDBOOL])
599AN_IDENTIFIER([false],[AC_CHECK_HEADER_STDBOOL])
600AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
601  [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
602     [ac_cv_header_stdbool_h],
603     [AC_COMPILE_IFELSE(
604        [AC_LANG_PROGRAM(
605           [[
606             #include <stdbool.h>
607             #ifndef bool
608              "error: bool is not defined"
609             #endif
610             #ifndef false
611              "error: false is not defined"
612             #endif
613             #if false
614              "error: false is not 0"
615             #endif
616             #ifndef true
617              "error: true is not defined"
618             #endif
619             #if true != 1
620              "error: true is not 1"
621             #endif
622             #ifndef __bool_true_false_are_defined
623              "error: __bool_true_false_are_defined is not defined"
624             #endif
625
626             struct s { _Bool s: 1; _Bool t; } s;
627
628             char a[true == 1 ? 1 : -1];
629             char b[false == 0 ? 1 : -1];
630             char c[__bool_true_false_are_defined == 1 ? 1 : -1];
631             char d[(bool) 0.5 == true ? 1 : -1];
632             /* See body of main program for 'e'.  */
633             char f[(_Bool) 0.0 == false ? 1 : -1];
634             char g[true];
635             char h[sizeof (_Bool)];
636             char i[sizeof s.t];
637             enum { j = false, k = true, l = false * true, m = true * 256 };
638             /* The following fails for
639                HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
640             _Bool n[m];
641             char o[sizeof n == m * sizeof n[0] ? 1 : -1];
642             char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
643             /* Catch a bug in an HP-UX C compiler.  See
644                http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
645                http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
646              */
647             _Bool q = true;
648             _Bool *pq = &q;
649           ]],
650           [[
651             bool e = &s;
652             *pq |= q;
653             *pq |= ! q;
654             /* Refer to every declared value, to avoid compiler optimizations.  */
655             return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
656                     + !m + !n + !o + !p + !q + !pq);
657           ]])],
658        [ac_cv_header_stdbool_h=yes],
659        [ac_cv_header_stdbool_h=no])])
660   AC_CHECK_TYPES([_Bool])
661])# AC_CHECK_HEADER_STDBOOL
662
663
664# AC_HEADER_STDBOOL
665# -----------------
666# Define HAVE_STDBOOL_H if tdbool.h that conforms to C99.
667AC_DEFUN([AC_HEADER_STDBOOL],
668[AC_CHECK_HEADER_STDBOOL
669if test $ac_cv_header_stdbool_h = yes; then
670  AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
671fi
672])# AC_HEADER_STDBOOL
673
674
675# AC_HEADER_STDC
676# --------------
677AC_DEFUN([AC_HEADER_STDC],
678[AC_CACHE_CHECK(for ANSI C header files, ac_cv_header_stdc,
679[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
680#include <stdarg.h>
681#include <string.h>
682#include <float.h>
683]])],
684		    [ac_cv_header_stdc=yes],
685		    [ac_cv_header_stdc=no])
686
687if test $ac_cv_header_stdc = yes; then
688  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
689  AC_EGREP_HEADER(memchr, string.h, , ac_cv_header_stdc=no)
690fi
691
692if test $ac_cv_header_stdc = yes; then
693  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
694  AC_EGREP_HEADER(free, stdlib.h, , ac_cv_header_stdc=no)
695fi
696
697if test $ac_cv_header_stdc = yes; then
698  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
699  AC_RUN_IFELSE([AC_LANG_SOURCE(
700[[#include <ctype.h>
701#include <stdlib.h>
702#if ((' ' & 0x0FF) == 0x020)
703# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
704# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
705#else
706# define ISLOWER(c) \
707		   (('a' <= (c) && (c) <= 'i') \
708		     || ('j' <= (c) && (c) <= 'r') \
709		     || ('s' <= (c) && (c) <= 'z'))
710# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
711#endif
712
713#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
714int
715main ()
716{
717  int i;
718  for (i = 0; i < 256; i++)
719    if (XOR (islower (i), ISLOWER (i))
720	|| toupper (i) != TOUPPER (i))
721      return 2;
722  return 0;
723}]])], , ac_cv_header_stdc=no, :)
724fi])
725if test $ac_cv_header_stdc = yes; then
726  AC_DEFINE(STDC_HEADERS, 1,
727	    [Define to 1 if you have the ANSI C header files.])
728fi
729])# AC_HEADER_STDC
730
731
732# AC_HEADER_SYS_WAIT
733# ------------------
734AC_DEFUN([AC_HEADER_SYS_WAIT],
735[AC_CACHE_CHECK([for sys/wait.h that is POSIX.1 compatible],
736  ac_cv_header_sys_wait_h,
737[AC_COMPILE_IFELSE(
738[AC_LANG_PROGRAM([#include <sys/types.h>
739#include <sys/wait.h>
740#ifndef WEXITSTATUS
741# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
742#endif
743#ifndef WIFEXITED
744# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
745#endif
746],
747[  int s;
748  wait (&s);
749  s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;])],
750		 [ac_cv_header_sys_wait_h=yes],
751		 [ac_cv_header_sys_wait_h=no])])
752if test $ac_cv_header_sys_wait_h = yes; then
753  AC_DEFINE(HAVE_SYS_WAIT_H, 1,
754	    [Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible.])
755fi
756])# AC_HEADER_SYS_WAIT
757
758
759# AC_HEADER_TIME
760# --------------
761AC_DEFUN([AC_HEADER_TIME],
762[AC_CACHE_CHECK([whether time.h and sys/time.h may both be included],
763  ac_cv_header_time,
764[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
765#include <sys/time.h>
766#include <time.h>
767],
768[if ((struct tm *) 0)
769return 0;])],
770		   [ac_cv_header_time=yes],
771		   [ac_cv_header_time=no])])
772if test $ac_cv_header_time = yes; then
773  AC_DEFINE(TIME_WITH_SYS_TIME, 1,
774	    [Define to 1 if you can safely include both <sys/time.h>
775	     and <time.h>.])
776fi
777])# AC_HEADER_TIME
778
779
780# _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
781# ----------------------------------
782m4_define([_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H],
783[AC_CACHE_CHECK([whether termios.h defines TIOCGWINSZ],
784		ac_cv_sys_tiocgwinsz_in_termios_h,
785[AC_EGREP_CPP([yes],
786	      [#include <sys/types.h>
787#include <termios.h>
788#ifdef TIOCGWINSZ
789  yes
790#endif
791],
792		ac_cv_sys_tiocgwinsz_in_termios_h=yes,
793		ac_cv_sys_tiocgwinsz_in_termios_h=no)])
794])# _AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
795
796
797# _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
798# ----------------------------------
799m4_define([_AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL],
800[AC_CACHE_CHECK([whether sys/ioctl.h defines TIOCGWINSZ],
801		ac_cv_sys_tiocgwinsz_in_sys_ioctl_h,
802[AC_EGREP_CPP([yes],
803	      [#include <sys/types.h>
804#include <sys/ioctl.h>
805#ifdef TIOCGWINSZ
806  yes
807#endif
808],
809		ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes,
810		ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no)])
811])# _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
812
813
814# AC_HEADER_TIOCGWINSZ
815# --------------------
816# Look for a header that defines TIOCGWINSZ.
817# FIXME: Is this the proper name?  Is this the proper implementation?
818# I need more help.
819AC_DEFUN([AC_HEADER_TIOCGWINSZ],
820[_AC_HEADER_TIOCGWINSZ_IN_TERMIOS_H
821if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then
822  _AC_HEADER_TIOCGWINSZ_IN_SYS_IOCTL
823  if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then
824    AC_DEFINE(GWINSZ_IN_SYS_IOCTL,1,
825	      [Define to 1 if `TIOCGWINSZ' requires <sys/ioctl.h>.])
826  fi
827fi
828])# AC_HEADER_TIOCGWINSZ
829
830
831# AU::AC_UNISTD_H
832# ---------------
833AU_DEFUN([AC_UNISTD_H],
834[AC_CHECK_HEADERS(unistd.h)])
835
836
837# AU::AC_USG
838# ----------
839# Define `USG' if string functions are in strings.h.
840AU_DEFUN([AC_USG],
841[AC_MSG_CHECKING([for BSD string and memory functions])
842AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <strings.h>]],
843				[[rindex(0, 0); bzero(0, 0);]])],
844	       [AC_MSG_RESULT(yes)],
845	       [AC_MSG_RESULT(no)
846		AC_DEFINE(USG, 1,
847			  [Define to 1 if you do not have <strings.h>, index,
848			   bzero, etc... This symbol is obsolete, you should
849			   not depend upon it.])])
850AC_CHECK_HEADERS(string.h)],
851[Remove `AC_MSG_CHECKING', `AC_LINK_IFELSE' and this warning
852when you adjust your code to use HAVE_STRING_H.])
853
854
855# AU::AC_MEMORY_H
856# ---------------
857# To be precise this macro used to be:
858#
859#   | AC_MSG_CHECKING(whether string.h declares mem functions)
860#   | AC_EGREP_HEADER(memchr, string.h, ac_found=yes, ac_found=no)
861#   | AC_MSG_RESULT($ac_found)
862#   | if test $ac_found = no; then
863#   |	AC_CHECK_HEADER(memory.h, [AC_DEFINE(NEED_MEMORY_H)])
864#   | fi
865#
866# But it is better to check for both headers, and alias NEED_MEMORY_H to
867# HAVE_MEMORY_H.
868AU_DEFUN([AC_MEMORY_H],
869[AC_CHECK_HEADER(memory.h,
870		[AC_DEFINE([NEED_MEMORY_H], 1,
871			   [Same as `HAVE_MEMORY_H', don't depend on me.])])
872AC_CHECK_HEADERS(string.h memory.h)],
873[Remove this warning and
874`AC_CHECK_HEADER(memory.h, AC_DEFINE(...))' when you adjust your code to
875use HAVE_STRING_H and HAVE_MEMORY_H, not NEED_MEMORY_H.])
876
877
878# AU::AC_DIR_HEADER
879# -----------------
880# Like calling `AC_HEADER_DIRENT' and `AC_FUNC_CLOSEDIR_VOID', but
881# defines a different set of C preprocessor macros to indicate which
882# header file is found.
883AU_DEFUN([AC_DIR_HEADER],
884[AC_HEADER_DIRENT
885AC_FUNC_CLOSEDIR_VOID
886test ac_cv_header_dirent_dirent_h &&
887  AC_DEFINE([DIRENT], 1, [Same as `HAVE_DIRENT_H', don't depend on me.])
888test ac_cv_header_dirent_sys_ndir_h &&
889  AC_DEFINE([SYSNDIR], 1, [Same as `HAVE_SYS_NDIR_H', don't depend on me.])
890test ac_cv_header_dirent_sys_dir_h &&
891  AC_DEFINE([SYSDIR], 1, [Same as `HAVE_SYS_DIR_H', don't depend on me.])
892test ac_cv_header_dirent_ndir_h &&
893  AC_DEFINE([NDIR], 1, [Same as `HAVE_NDIR_H', don't depend on me.])],
894[Remove this warning and the four `AC_DEFINE' when you
895adjust your code to use `AC_HEADER_DIRENT'.])
896