Previous: , Up: Format of   [Contents][Index]

5.1.6 Conditionals

Automake has a conditional directive to make parts of files conditional. Automake conditionals are checked at configure-time by the configure script, and affect the translation from to Makefile. They are based on options passed to configure and on results that configure has discovered about the host system.

(Note that these conditionals are not the same as conditionals in GNU Make. 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, and don’t rely on GNU Make conditionals.)

Using an Automake conditional requires modifying both and For more information on the format of, see the next section.

Before using a conditional, you must define it in the file by using the AM_CONDITIONAL macro (see Macros supplied with Automake).

Macro: AM_CONDITIONAL (conditional, condition)

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.

Here is an example of how to set the ‘DEBUG’ conditional to “true” only if the user provides the --enable-debug option to the configure script:

[  --enable-debug    Turn on debugging],
[case "${enableval}" in
  yes) debug=true ;;
  no)  debug=false ;;
  *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;

AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])

Here the value of the conditional depends on the result of the shell code ‘test x$debug = xtrue’, given as the second argument to AM_CONDITIONAL. The ‘debug’ variable is set by the AC_ARG_ENABLE macro.

Here is an example of how to use this conditional in 3

DBG = debug
noinst_PROGRAMS = $(DBG)

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 that is closed on the endif line:

DBG = debug
else !DEBUG
endif !DEBUG

Unbalanced conditions are errors. The if, else, and endif statements should not be indented, i.e., start on column one.

In order to allow access to the value of an Automake conditional inside itself, AM_COND_IF may be used:

Macro: AM_COND_IF (conditional, [if-true], [if-false])

If conditional is fulfilled, execute if-true, otherwise execute if-false. If either branch contains AC_CONFIG_FILES, it will cause automake to output the rules for the respective files only for the given condition.

AM_COND_IF macros may be nested when m4 quotation is used properly (see M4 Quotation).

Here is an example of how to define a conditional config file:

AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])



This trivial example could also be handled using EXTRA_PROGRAMS (see Conditional Programs).

Previous: , Up: Format of   [Contents][Index]