01.09.2014 Views

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CH04.fm Page 132 Monday, October 7, 2002 8:54 PM<br />

132 Chapter 4 • <strong>Using</strong> GNU make<br />

4.6.1 <strong>The</strong> ifeq Directive<br />

<strong>The</strong> ifeq directive is used to compare two values <strong>and</strong> make a decision based upon the<br />

result. <strong>The</strong> general format of this directive is as follows:<br />

ifeq (value1, value2)<br />

block if value 1 is equal to value2<br />

else<br />

block if value 1 is not equal to value2<br />

endif<br />

<strong>The</strong> else part is optional <strong>and</strong> may not be present. This structure is useful if you want to<br />

make a decision on the basis of some criteria. For example, based upon the value of type of build<br />

(temporary or final) you want to use different levels of optimization. <strong>The</strong> following code in a<br />

makefile does that.<br />

ifeq ($(BUILD), final)<br />

$(CC) -c -O2 ftp.c<br />

else<br />

$(CC) -c -O1 ftp.c<br />

endif<br />

Please note that there is no TAB character before ifeq, else <strong>and</strong> endif words.<br />

4.6.2 <strong>The</strong> ifneq Directive<br />

<strong>The</strong> ifneq directive is similar to ifeq directive. <strong>The</strong> only difference is that sense of<br />

equality is reversed. <strong>The</strong> general syntax is as follows:<br />

ifneq (value1, value2)<br />

block if value 1 is not equal to value2<br />

else<br />

block if value 1 is equal to value2<br />

endif<br />

4.6.3 <strong>The</strong> ifdef Directive<br />

<strong>The</strong> ifdef directive checks if the value of the variable is empty or not. If the variable is<br />

not empty, the ifdef block is executed, otherwise the else part is executed. <strong>The</strong> general structure<br />

of the directive is as follows:<br />

ifdef variable<br />

block if variable is non-empty<br />

else<br />

block if variable is empty<br />

endif<br />

This directive is useful to verify if a variable is defined or not. <strong>The</strong> else part is optional.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!