autoconf: Particular Headers

1 
1 5.6.2 Particular Header Checks
1 ------------------------------
1 
1 These macros check for particular system header files--whether they
1 exist, and in some cases whether they declare certain symbols.
1 
1  -- Macro: AC_CHECK_HEADER_STDBOOL
1      Check whether `stdbool.h' exists and conforms to C99, and cache the
1      result in the `ac_cv_header_stdbool_h' variable.  If the type
1      `_Bool' is defined, define `HAVE__BOOL' to 1.
1 
1      This macro is intended for use by Gnulib (⇒Gnulib) and other
1      packages that supply a substitute `stdbool.h' on platforms lacking
1      a conforming one.  The `AC_HEADER_STDBOOL' macro is better for code
1      that explicitly checks for `stdbool.h'.
1 
1  -- Macro: AC_HEADER_ASSERT
1      Check whether to enable assertions in the style of `assert.h'.
1      Assertions are enabled by default, but the user can override this
1      by invoking `configure' with the `--disable-assert' option.
1 
1  -- Macro: AC_HEADER_DIRENT
1      Check for the following header files.  For the first one that is
1      found and defines `DIR', define the listed C preprocessor macro:
1 
1      `dirent.h'     `HAVE_DIRENT_H'
1      `sys/ndir.h'   `HAVE_SYS_NDIR_H'
1      `sys/dir.h'    `HAVE_SYS_DIR_H'
1      `ndir.h'       `HAVE_NDIR_H'
1 
1      The directory-library declarations in your source code should look
1      something like the following:
1 
1           #include <sys/types.h>
1           #ifdef HAVE_DIRENT_H
1           # include <dirent.h>
1           # define NAMLEN(dirent) strlen ((dirent)->d_name)
1           #else
1           # define dirent direct
1           # define NAMLEN(dirent) ((dirent)->d_namlen)
1           # ifdef HAVE_SYS_NDIR_H
1           #  include <sys/ndir.h>
1           # endif
1           # ifdef HAVE_SYS_DIR_H
1           #  include <sys/dir.h>
1           # endif
1           # ifdef HAVE_NDIR_H
1           #  include <ndir.h>
1           # endif
1           #endif
1 
1      Using the above declarations, the program would declare variables
1      to be of type `struct dirent', not `struct direct', and would
1      access the length of a directory entry name by passing a pointer
1      to a `struct dirent' to the `NAMLEN' macro.
1 
1      This macro also checks for the SCO Xenix `dir' and `x' libraries.
1 
1      This macro is obsolescent, as all current systems with directory
1      libraries have `<dirent.h>'.  New programs need not use this macro.
1 
1      Also see `AC_STRUCT_DIRENT_D_INO' and `AC_STRUCT_DIRENT_D_TYPE'
1      (⇒Particular Structures).
1 
1  -- Macro: AC_HEADER_MAJOR
1      If `sys/types.h' does not define `major', `minor', and `makedev',
1      but `sys/mkdev.h' does, define `MAJOR_IN_MKDEV'; otherwise, if
1      `sys/sysmacros.h' does, define `MAJOR_IN_SYSMACROS'.
1 
1  -- Macro: AC_HEADER_RESOLV
1      Checks for header `resolv.h', checking for prerequisites first.
1      To properly use `resolv.h', your code should contain something like
1      the following:
1 
1      #ifdef HAVE_SYS_TYPES_H
1      #  include <sys/types.h>
1      #endif
1      #ifdef HAVE_NETINET_IN_H
1      #  include <netinet/in.h>   /* inet_ functions / structs */
1      #endif
1      #ifdef HAVE_ARPA_NAMESER_H
1      #  include <arpa/nameser.h> /* DNS HEADER struct */
1      #endif
1      #ifdef HAVE_NETDB_H
1      #  include <netdb.h>
1      #endif
1      #include <resolv.h>
1 
1  -- Macro: AC_HEADER_STAT
1      If the macros `S_ISDIR', `S_ISREG', etc. defined in `sys/stat.h'
1      do not work properly (returning false positives), define
1      `STAT_MACROS_BROKEN'.  This is the case on Tektronix UTekV, Amdahl
1      UTS and Motorola System V/88.
1 
1      This macro is obsolescent, as no current systems have the bug.
1      New programs need not use this macro.
1 
1  -- Macro: AC_HEADER_STDBOOL
1      If `stdbool.h' exists and conforms to C99, define `HAVE_STDBOOL_H'
1      to 1; if the type `_Bool' is defined, define `HAVE__BOOL' to 1.
1      To fulfill the C99 requirements, your program could contain the
1      following code:
1 
1           #ifdef HAVE_STDBOOL_H
1           # include <stdbool.h>
1           #else
1           # ifndef HAVE__BOOL
1           #  ifdef __cplusplus
1           typedef bool _Bool;
1           #  else
1           #   define _Bool signed char
1           #  endif
1           # endif
1           # define bool _Bool
1           # define false 0
1           # define true 1
1           # define __bool_true_false_are_defined 1
1           #endif
1 
11      Alternatively you can use the `stdbool' package of Gnulib (⇒
      Gnulib).  It simplifies your code so that it can say just
1      `#include <stdbool.h>', and it adds support for less-common
1      platforms.
1 
1      This macro caches its result in the `ac_cv_header_stdbool_h'
1      variable.
1 
1      This macro differs from `AC_CHECK_HEADER_STDBOOL' only in that it
1      defines `HAVE_STDBOOL_H' whereas `AC_CHECK_HEADER_STDBOOL' does
1      not.
1 
1  -- Macro: AC_HEADER_STDC
1      Define `STDC_HEADERS' if the system has C header files conforming
1      to ANSI C89 (ISO C90).  Specifically, this macro checks for
1      `stdlib.h', `stdarg.h', `string.h', and `float.h'; if the system
1      has those, it probably has the rest of the C89 header files.  This
1      macro also checks whether `string.h' declares `memchr' (and thus
1      presumably the other `mem' functions), whether `stdlib.h' declare
1      `free' (and thus presumably `malloc' and other related functions),
1      and whether the `ctype.h' macros work on characters with the high
1      bit set, as the C standard requires.
1 
1      If you use this macro, your code can refer to `STDC_HEADERS' to
1      determine whether the system has conforming header files (and
1      probably C library functions).
1 
1      This macro caches its result in the `ac_cv_header_stdc' variable.
1 
1      This macro is obsolescent, as current systems have conforming
1      header files.  New programs need not use this macro.
1 
1      Nowadays `string.h' is part of the C standard and declares
1      functions like `strcpy', and `strings.h' is standardized by Posix
1      and declares BSD functions like `bcopy'; but historically, string
1      functions were a major sticking point in this area.  If you still
1      want to worry about portability to ancient systems without
1      standard headers, there is so much variation that it is probably
1      easier to declare the functions you use than to figure out exactly
1      what the system header files declare.  Some ancient systems
1      contained a mix of functions from the C standard and from BSD;
1      some were mostly standard but lacked `memmove'; some defined the
1      BSD functions as macros in `string.h' or `strings.h'; some had
1      only the BSD functions but `string.h'; some declared the memory
1      functions in `memory.h', some in `string.h'; etc.  It is probably
1      sufficient to check for one string function and one memory
1      function; if the library had the standard versions of those then
1      it probably had most of the others.  If you put the following in
1      `configure.ac':
1 
1           # This example is obsolescent.
1           # Nowadays you can omit these macro calls.
1           AC_HEADER_STDC
1           AC_CHECK_FUNCS([strchr memcpy])
1 
1      then, in your code, you can use declarations like this:
1 
1           /* This example is obsolescent.
1              Nowadays you can just #include <string.h>.  */
1           #ifdef STDC_HEADERS
1           # include <string.h>
1           #else
1           # ifndef HAVE_STRCHR
1           #  define strchr index
1           #  define strrchr rindex
1           # endif
1           char *strchr (), *strrchr ();
1           # ifndef HAVE_MEMCPY
1           #  define memcpy(d, s, n) bcopy ((s), (d), (n))
1           #  define memmove(d, s, n) bcopy ((s), (d), (n))
1           # endif
1           #endif
1 
1      If you use a function like `memchr', `memset', `strtok', or
1      `strspn', which have no BSD equivalent, then macros don't suffice
1      to port to ancient hosts; you must provide an implementation of
1      each function.  An easy way to incorporate your implementations
1      only when needed (since the ones in system C libraries may be hand
1      optimized) is to, taking `memchr' for example, put it in
1      `memchr.c' and use `AC_REPLACE_FUNCS([memchr])'.
1 
1  -- Macro: AC_HEADER_SYS_WAIT
1      If `sys/wait.h' exists and is compatible with Posix, define
1      `HAVE_SYS_WAIT_H'.  Incompatibility can occur if `sys/wait.h' does
1      not exist, or if it uses the old BSD `union wait' instead of `int'
1      to store a status value.  If `sys/wait.h' is not Posix compatible,
1      then instead of including it, define the Posix macros with their
1      usual interpretations.  Here is an example:
1 
1           #include <sys/types.h>
1           #ifdef HAVE_SYS_WAIT_H
1           # include <sys/wait.h>
1           #endif
1           #ifndef WEXITSTATUS
1           # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
1           #endif
1           #ifndef WIFEXITED
1           # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
1           #endif
1 
1      This macro caches its result in the `ac_cv_header_sys_wait_h'
1      variable.
1 
1      This macro is obsolescent, as current systems are compatible with
1      Posix.  New programs need not use this macro.
1 
1    `_POSIX_VERSION' is defined when `unistd.h' is included on Posix
1 systems.  If there is no `unistd.h', it is definitely not a Posix
1 system.  However, some non-Posix systems do have `unistd.h'.
1 
1    The way to check whether the system supports Posix is:
1 
1      #ifdef HAVE_UNISTD_H
1      # include <sys/types.h>
1      # include <unistd.h>
1      #endif
1 
1      #ifdef _POSIX_VERSION
1      /* Code for Posix systems.  */
1      #endif
1 
1  -- Macro: AC_HEADER_TIME
1      If a program may include both `time.h' and `sys/time.h', define
1      `TIME_WITH_SYS_TIME'.  On some ancient systems, `sys/time.h'
1      included `time.h', but `time.h' was not protected against multiple
1      inclusion, so programs could not explicitly include both files.
1      This macro is useful in programs that use, for example, `struct
1      timeval' as well as `struct tm'.  It is best used in conjunction
1      with `HAVE_SYS_TIME_H', which can be checked for using
1      `AC_CHECK_HEADERS([sys/time.h])'.
1 
1           #ifdef TIME_WITH_SYS_TIME
1           # include <sys/time.h>
1           # include <time.h>
1           #else
1           # ifdef HAVE_SYS_TIME_H
1           #  include <sys/time.h>
1           # else
1           #  include <time.h>
1           # endif
1           #endif
1 
1      This macro caches its result in the `ac_cv_header_time' variable.
1 
1      This macro is obsolescent, as current systems can include both
1      files when they exist.  New programs need not use this macro.
1 
1  -- Macro: AC_HEADER_TIOCGWINSZ
1      If the use of `TIOCGWINSZ' requires `<sys/ioctl.h>', then define
1      `GWINSZ_IN_SYS_IOCTL'.  Otherwise `TIOCGWINSZ' can be found in
1      `<termios.h>'.
1 
1      Use:
1 
1           #ifdef HAVE_TERMIOS_H
1           # include <termios.h>
1           #endif
1 
1           #ifdef GWINSZ_IN_SYS_IOCTL
1           # include <sys/ioctl.h>
1           #endif
1