These macros test for particular system features that packages might need or want to use. If you need to test for a kind of feature that none of these macros check for, you can probably do it by calling primitive test macros with appropriate arguments (Chapter 7).
These tests print messages telling the user which feature they're checking for, and what they find. They cache their results for future configure runs (the section called “Caching Results”).
Some of these macros set output variables. the section called “Substitutions in Makefiles ”, for how to get their values. The phrase "define name" is used below as a shorthand to mean "define C preprocessor symbol name to the value 1". the section called “Defining C Preprocessor Symbols”, for how to get those symbol definitions into your program.
Much effort has been expended to make Autoconf easy to learn. The most obvious way to reach this goal is simply to enforce standard interfaces and behaviors, avoiding exceptions as much as possible. Because of history and inertia, unfortunately, there are still too many exceptions in Autoconf; nevertheless, this section describes some of the common rules.
All the generic macros that AC_DEFINE a symbol as a result of their test transform their arguments to a standard alphabet. First, argument is converted to upper case and any asterisks (*) are each converted to P. Any remaining characters that are not alphanumeric are converted to underscores.
For instance,
AC_CHECK_TYPES(struct $Expensive*)
will define the symbol HAVE_STRUCT__EXPENSIVEP if the check succeeds.
Several tests depend upon a set of header files. Since these headers are not universally available, tests actually have to provide a set of protected includes, such as:
#if TIME_WITH_SYS_TIME # include sys/time.h # include time.h #else # if HAVE_SYS_TIME_H # include sys/time.h # else # include time.h # endif #endif
Unless you know exactly what you are doing, you should avoid using unconditional includes, and check the existence of the headers you include beforehand (the section called “Header Files”).
Most generic macros provide the following default set of includes:
#include stdio.h #if HAVE_SYS_TYPES_H # include sys/types.h #endif #if HAVE_SYS_STAT_H # include sys/stat.h #endif #if STDC_HEADERS # include stdlib.h # include stddef.h #else # if HAVE_STDLIB_H # include stdlib.h # endif #endif #if HAVE_STRING_H # if !STDC_HEADERS HAVE_MEMORY_H # include memory.h # endif # include string.h #endif #if HAVE_STRINGS_H # include strings.h #endif #if HAVE_INTTYPES_H # include inttypes.h #else # if HAVE_STDINT_H # include stdint.h # endif #endif #if HAVE_UNISTD_H # include unistd.h #endif
If the default includes are used, then Autoconf will automatically check for the presence of these headers and their compatibility, i.e., you don't need to run AC_HEADERS_STDC, nor check for stdlib.h etc.
These headers are checked for in the same order as they are included. For instance, on some systems string.h and strings.h both exist, but conflict. Then HAVE_STRING_H will be defined, but HAVE_STRINGS_H won't.