autoconf: Running the Preprocessor

1 
1 6.3 Running the Preprocessor
1 ============================
1 
1 Sometimes one might need to run the preprocessor on some source file.
1 _Usually it is a bad idea_, as you typically need to _compile_ your
1 project, not merely run the preprocessor on it; therefore you certainly
1 want to run the compiler, not the preprocessor.  Resist the temptation
1 of following the easiest path.
1 
1    Nevertheless, if you need to run the preprocessor, then use
1 `AC_PREPROC_IFELSE'.
1 
1    The macros described in this section cannot be used for tests in
1 Erlang, Fortran, or Go, since those languages require no preprocessor.
1 
1  -- Macro: AC_PREPROC_IFELSE (INPUT, [ACTION-IF-TRUE],
1           [ACTION-IF-FALSE])
11      Run the preprocessor of the current language (⇒Language
      Choice) on the INPUT, run the shell commands ACTION-IF-TRUE on
1      success, ACTION-IF-FALSE otherwise.  The INPUT can be made by
1      `AC_LANG_PROGRAM' and friends.
1 
1      This macro uses `CPPFLAGS', but not `CFLAGS', because `-g', `-O',
1      etc. are not valid options to many C preprocessors.
1 
1      It is customary to report unexpected failures with
1      `AC_MSG_FAILURE'.  If needed, ACTION-IF-TRUE can further access
1      the preprocessed output in the file `conftest.i'.
1 
1    For instance:
1 
1      AC_INIT([Hello], [1.0], [bug-hello@example.org])
1      AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
1        [Greetings string.])
1      AC_PREPROC_IFELSE(
1         [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
1                          [[fputs (hw, stdout);]])],
1         [AC_MSG_RESULT([OK])],
1         [AC_MSG_FAILURE([unexpected preprocessor failure])])
1 
1 results in:
1 
1      checking for gcc... gcc
1      checking for C compiler default output file name... a.out
1      checking whether the C compiler works... yes
1      checking whether we are cross compiling... no
1      checking for suffix of executables...
1      checking for suffix of object files... o
1      checking whether we are using the GNU C compiler... yes
1      checking whether gcc accepts -g... yes
1      checking for gcc option to accept ISO C89... none needed
1      checking how to run the C preprocessor... gcc -E
1      OK
1 
1 
1    The macro `AC_TRY_CPP' (⇒Obsolete Macros) used to play the
1 role of `AC_PREPROC_IFELSE', but double quotes its argument, making it
1 impossible to use it to elaborate sources.  You are encouraged to get
1 rid of your old use of the macro `AC_TRY_CPP' in favor of
1 `AC_PREPROC_IFELSE', but, in the first place, are you sure you need to
1 run the _preprocessor_ and not the compiler?
1 
1  -- Macro: AC_EGREP_HEADER (PATTERN, HEADER-FILE, ACTION-IF-FOUND,
1           [ACTION-IF-NOT-FOUND])
1      If the output of running the preprocessor on the system header file
1      HEADER-FILE matches the extended regular expression PATTERN,
1      execute shell commands ACTION-IF-FOUND, otherwise execute
1      ACTION-IF-NOT-FOUND.
1 
1  -- Macro: AC_EGREP_CPP (PATTERN, PROGRAM, [ACTION-IF-FOUND],
1           [ACTION-IF-NOT-FOUND])
1      PROGRAM is the text of a C or C++ program, on which shell
1      variable, back quote, and backslash substitutions are performed.
1      If the output of running the preprocessor on PROGRAM matches the
1      extended regular expression PATTERN, execute shell commands
1      ACTION-IF-FOUND, otherwise execute ACTION-IF-NOT-FOUND.
1