Conditional Input
Conditional statements allow you to include or exclude specific lines based on some condition. The condition can be that a macro is or is not defined, or that the value of a macro is or is not equal to a particular string. The equivalence/nonequivalence tests provide three different ways of quoting the values. Conditionals may have an optional “else” part; i.e., lines that are used when the condition is not true. The general form is as follows:
ifXXX testlines to include if true[ elselines to include if false] endif
(The square brackets indicate optional parts of the construct; they are not to be entered literally.) Actual tests are as follows:
|
Condition |
Meaning |
|
|
True if macroname is a macro that has been given a value. |
|
|
True if macroname is a macro that has not been given a value. |
|
| |
|
|
True if values v1 and v2 are equal. |
|
| |
|
| |
|
|
True if values v1 and v2 are not equal. |
|
|
For example:
whizprog.o: whizprog.c
ifeq($(ARCH),ENIAC) # Serious retrocomputing in progess!
$(CC) $(CFLAGS) $(ENIACFLAGS) -c $< -o $@
else
$(CC) $(CFLAGS) -c $< -o $@
endifBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access