Conditional Directives

A conditional directive can be used to control which parts of a Makefile are executed, based upon the value assigned to certain variables. The familiar

if condition
    ...true...
else
    ...false...
endif

syntax is used for this purpose, where ...true... represents any number of lines which are executed if the condition is true, and ...false... represents any number of lines which are executed if the condition is false. Each of the three conditional directives must appear as the first word on a line. The else directive is optional. The condition may be one of the following:

eq(arg1,arg2) true if arg1 is exactly equal to arg2
neq(arg1,arg2) true if arg1 is not equal to arg2
def(variable) true if variable is defined
ndef(variable) true if variable is undefined
exists(pathname) true if pathname exists in the filesystem
nexists(pathname) true if pathname does not exist in the filesystem

Nested conditionals are acceptable. There is no way to perform logical AND and logical OR operations within the condition expression, so nested conditionals will have to be used instead to do the same job. Each if and else must have a matching endif directive associated with its conditional construct.

The else and endif directives must reside in the same Makefile as their corresponding if directive. A conditional construct cannot be split across Makefiles.

The use of conditional directives in a Makefile is vaguely analogous to the use of #if, #else, and #endif preprocessor directives in C source code to control conditional compilation.