autoconf: Defining Symbols

1 
1 7.1 Defining C Preprocessor Symbols
1 ===================================
1 
1 A common action to take in response to a feature test is to define a C
1 preprocessor symbol indicating the results of the test.  That is done by
1 calling `AC_DEFINE' or `AC_DEFINE_UNQUOTED'.
1 
1    By default, `AC_OUTPUT' places the symbols defined by these macros
1 into the output variable `DEFS', which contains an option
1 `-DSYMBOL=VALUE' for each symbol defined.  Unlike in Autoconf version
1 1, there is no variable `DEFS' defined while `configure' is running.
1 To check whether Autoconf macros have already defined a certain C
1 preprocessor symbol, test the value of the appropriate cache variable,
1 as in this example:
1 
1      AC_CHECK_FUNC([vprintf], [AC_DEFINE([HAVE_VPRINTF], [1],
1                                [Define if vprintf exists.])])
1      if test "x$ac_cv_func_vprintf" != xyes; then
1        AC_CHECK_FUNC([_doprnt], [AC_DEFINE([HAVE_DOPRNT], [1],
1                                  [Define if _doprnt exists.])])
1      fi
1 
1    If `AC_CONFIG_HEADERS' has been called, then instead of creating
1 `DEFS', `AC_OUTPUT' creates a header file by substituting the correct
11 values into `#define' statements in a template file.  ⇒
 Configuration Headers, for more information about this kind of output.
1 
1  -- Macro: AC_DEFINE (VARIABLE, VALUE, [DESCRIPTION])
1  -- Macro: AC_DEFINE (VARIABLE)
1      Define VARIABLE to VALUE (verbatim), by defining a C preprocessor
1      macro for VARIABLE.  VARIABLE should be a C identifier, optionally
1      suffixed by a parenthesized argument list to define a C
1      preprocessor macro with arguments.  The macro argument list, if
1      present, should be a comma-separated list of C identifiers,
1      possibly terminated by an ellipsis `...' if C99 syntax is employed.
1      VARIABLE should not contain comments, white space, trigraphs,
1      backslash-newlines, universal character names, or non-ASCII
1      characters.
1 
1      VALUE may contain backslash-escaped newlines, which will be
1      preserved if you use `AC_CONFIG_HEADERS' but flattened if passed
1      via `@DEFS@' (with no effect on the compilation, since the
1      preprocessor sees only one line in the first place).  VALUE should
1      not contain raw newlines.  If you are not using
1      `AC_CONFIG_HEADERS', VALUE should not contain any `#' characters,
1      as `make' tends to eat them.  To use a shell variable, use
1      `AC_DEFINE_UNQUOTED' instead.
1 
1      DESCRIPTION is only useful if you are using `AC_CONFIG_HEADERS'.
1      In this case, DESCRIPTION is put into the generated `config.h.in'
1      as the comment before the macro define.  The following example
1      defines the C preprocessor variable `EQUATION' to be the string
1      constant `"$a > $b"':
1 
1           AC_DEFINE([EQUATION], ["$a > $b"],
1             [Equation string.])
1 
1      If neither VALUE nor DESCRIPTION are given, then VALUE defaults to
1      1 instead of to the empty string.  This is for backwards
1      compatibility with older versions of Autoconf, but this usage is
1      obsolescent and may be withdrawn in future versions of Autoconf.
1 
1      If the VARIABLE is a literal string, it is passed to
1      `m4_pattern_allow' (⇒Forbidden Patterns).
1 
1      If multiple `AC_DEFINE' statements are executed for the same
1      VARIABLE name (not counting any parenthesized argument list), the
1      last one wins.
1 
1  -- Macro: AC_DEFINE_UNQUOTED (VARIABLE, VALUE, [DESCRIPTION])
1  -- Macro: AC_DEFINE_UNQUOTED (VARIABLE)
1      Like `AC_DEFINE', but three shell expansions are
1      performed--once--on VARIABLE and VALUE: variable expansion (`$'),
1      command substitution (``'), and backslash escaping (`\'), as if in
1      an unquoted here-document.  Single and double quote characters in
1      the value have no special meaning.  Use this macro instead of
1      `AC_DEFINE' when VARIABLE or VALUE is a shell variable.  Examples:
1 
1           AC_DEFINE_UNQUOTED([config_machfile], ["$machfile"],
1             [Configuration machine file.])
1           AC_DEFINE_UNQUOTED([GETGROUPS_T], [$ac_cv_type_getgroups],
1             [getgroups return type.])
1           AC_DEFINE_UNQUOTED([$ac_tr_hdr], [1],
1             [Translated header name.])
1 
1    Due to a syntactical bizarreness of the Bourne shell, do not use
1 semicolons to separate `AC_DEFINE' or `AC_DEFINE_UNQUOTED' calls from
1 other macro calls or shell code; that can cause syntax errors in the
1 resulting `configure' script.  Use either blanks or newlines.  That is,
1 do this:
1 
1      AC_CHECK_HEADER([elf.h],
1        [AC_DEFINE([SVR4], [1], [System V Release 4]) LIBS="-lelf $LIBS"])
1 
1 or this:
1 
1      AC_CHECK_HEADER([elf.h],
1        [AC_DEFINE([SVR4], [1], [System V Release 4])
1         LIBS="-lelf $LIBS"])
1 
1 instead of this:
1 
1      AC_CHECK_HEADER([elf.h],
1        [AC_DEFINE([SVR4], [1], [System V Release 4]); LIBS="-lelf $LIBS"])
1