Next: The effect of --gnu
and --gnits
, Previous: Include, Up: GNU Automake [Contents][Index]
Automake supports a simple type of conditionals.
Before using a conditional, you must define it by using
AM_CONDITIONAL
in the configure.in
file (see Autoconf macros supplied with Automake).
The conditional name, conditional, should be a simple string starting with a letter and containing only letters, digits, and underscores. It must be different from ‘TRUE’ and ‘FALSE’ which are reserved by Automake.
The shell condition (suitable for use in a shell if
statement) is evaluated when configure
is run. Note that you
must arrange for every AM_CONDITIONAL
to be invoked every
time configure
is run – if AM_CONDITIONAL
is run
conditionally (e.g., in a shell if
statement), then the result
will confuse automake.
Conditionals typically depend upon options which the user provides to
the configure
script. Here is an example of how to write a
conditional which is true if the user uses the ‘--enable-debug’
option.
AC_ARG_ENABLE(debug, [ --enable-debug Turn on debugging], [case "${enableval}" in yes) debug=true ;; no) debug=false ;; *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;; esac],[debug=false]) AM_CONDITIONAL(DEBUG, test x$debug = xtrue)
Here is an example of how to use that conditional in Makefile.am:
if DEBUG DBG = debug else DBG = endif noinst_PROGRAMS = $(DBG)
This trivial example could also be handled using EXTRA_PROGRAMS (see Building a program).
You may only test a single variable in an if
statement, possibly
negated using ‘!’. The else
statement may be omitted.
Conditionals may be nested to any depth. You may specify an argument to
else
in which case it must be the negation of the condition used
for the current if
. Similarly you may specify the condition
which is closed by an end
:
if DEBUG DBG = debug else !DEBUG DBG = endif !DEBUG
Unbalanced conditions are errors.
Conditionals do not interact very smoothly with the append operator. In particular, an append must happen in the same conditional context as the original assignment. This means that the following will not work:
DBG = foo if DEBUG DBG += bar endif DEBUG
The behaviour which is probably desired in this situation can be obtained using a temporary variable:
if DEBUG TMP_DBG = bar endif DEBUG DBG = foo $(TMP_DBG)
This restriction may be lifted in future versions of automake.
Note that conditionals in Automake are not the same as conditionals in
GNU Make. Automake conditionals are checked at configure time by the
configure script, and affect the translation from
Makefile.in to Makefile. They are based on options passed
to configure and on results that configure has discovered
about the host system. GNU Make conditionals are checked at make
time, and are based on variables passed to the make program or defined
in the Makefile.
Automake conditionals will work with any make program.
Next: The effect of --gnu
and --gnits
, Previous: Include, Up: GNU Automake [Contents][Index]