If the existing feature tests don't do something you need, you have to write new ones. These macros are the building blocks. They provide ways for other macros to check whether various kinds of features are available and report the results.
This chapter contains some suggestions and some of the reasons why the existing tests are written the way they are. You can also learn a lot about how to write Autoconf tests by looking at the existing ones. If something goes wrong in one or more of the Autoconf tests, this information can help you understand the assumptions behind them, which might help you figure out how to best solve the problem.
These macros check the output of the C compiler system. They do not cache the results of their tests for future use (the section called “Caching Results”), because they don't know enough about the information they are checking for to generate a cache variable name. They also do not print any messages, for the same reason. The checks for particular kinds of C features call these macros and do cache their results and print messages about what they're checking for.
When you write a feature test that could be applicable to more than one software package, the best thing to do is encapsulate it in a new macro. Chapter 10, for how to do that.
The macro AC_TRY_CPP is used to check whether particular header files exist. You can check for one at a time, or more than one if you need several header files to all exist for some purpose.
function>AC_TRY_CPP/function> (input, [action-if-true], [action-if-false]) If the preprocessor produces no error messages while processing the input (typically includes), run shell commands action-if-true. Otherwise run shell commands action-if-false. Beware that input is double quoted. Shell variable, back quote, and backslash substitutions are performed on input.
This macro uses CPPFLAGS, but not CFLAGS, because -g, -O, etc. are not valid options to many C preprocessors.
Here is how to find out whether a header file contains a particular declaration, such as a typedef, a structure, a structure member, or a function. Use AC_EGREP_HEADER instead of running grep directly on the header file; on some systems the symbol might be defined in another header file that the file you are checking #includes.
function>AC_EGREP_HEADER/function> (pattern, header-file, action-if-found, [action-if-not-found]) If the output of running the preprocessor on the system header file header-file matches the egrep regular expression pattern, execute shell commands action-if-found, otherwise execute action-if-not-found.
To check for C preprocessor symbols, either defined by header files or predefined by the C preprocessor, use AC_EGREP_CPP. Here is an example of the latter:
AC_EGREP_CPP(yes, [#ifdef _AIX yes #endif ], is_aix=yes, is_aix=no)
function>AC_EGREP_CPP/function> (pattern, program, [action-if-found], [action-if-not-found]) program is the text of a C or C++ program, on which shell variable, back quote, and backslash substitutions are performed. If the output of running the preprocessor on program matches the egrep regular expression pattern, execute shell commands action-if-found, otherwise execute action-if-not-found.
This macro calls AC_PROG_CPP or AC_PROG_CXXCPP (depending on which language is current, the section called “Language Choice”), if it hasn't been called already.