132Chapter4 Using GNU make
4.6.1The ifeq Directive
The
ifeq
directive is used to compare two values and make a decision based upon the
result. The general format of this directive is as follows:
ifeq (value1, value2)
block if value 1 is equal to value2
else
block if value 1 is not equal to value2
endif
The
else
part is optional and may not be present. This structure is useful if you want to
make a decision on the basis of some criteria. For example, based upon the value of type of build
(temporary or final) you want to use different levels of optimization. The following code in a
makefile does that.
ifeq ($(BUILD), final)
$(CC) -c -O2 ftp.c
else
$(CC) -c -O1 ftp.c
endif
Please note that there is no TAB character before
ifeq
,
else
and
endif
words.
4.6.2The ifneq Directive
The
ifneq
directive is similar to
ifeq
directive. The only difference is that sense of
equality is reversed. The general syntax is as follows:
ifneq (value1, value2)
block if value 1 is not equal to value2
else
block if value 1 is equal to value2
endif
4.6.3The ifdef Directive
The
ifdef
directive checks if the value of the variable is empty or not. If the variable is
not empty, the
ifdef
block is executed, otherwise the else part is executed. The general struc-
ture of the directive is as follows:
ifdef variable
block if variable is non-empty
else
block if variable is empty
endif
This directive is useful to verify if a variable is defined or not. The
else
part is optional.
Next Page >>
<< Previous Page
Back to the Table of Contents