Up: Conditionals   [Contents][Index]

5.1.6.1 Limits of Conditionals

Conditionals should enclose complete statements, such as variable or rule definitions.

For instance, Automake cannot deal with conditionals used inside a variable definition, and is not even able to diagnose this situation. The following example would not work:

# This syntax is not understood by Automake
AM_CPPFLAGS = \
  -DFEATURE_A \
if WANT_DEBUG
  -DDEBUG \
endif
  -DFEATURE_B

The intended definition of AM_CPPFLAGS can be achieved with

if WANT_DEBUG
  DEBUGFLAGS = -DDEBUG
endif
AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B

or

AM_CPPFLAGS = -DFEATURE_A
if WANT_DEBUG
AM_CPPFLAGS += -DDEBUG
endif
AM_CPPFLAGS += -DFEATURE_B

More details and examples of conditionals are described alongside various Automake features in this manual (see Conditional Subdirectories, Conditional Sources, Conditional Programs, Conditional Libtool Libraries, and Conditional Libtool Sources).