Makefile(03)_ condition judgment
8. Conditional judgment statement 8.1. rule of grammar
Conditional judgment statements are supported in Makefile, which can directly compare the values and constant values of two different variables.
Note: conditional judgment statements can only be used to control the statements actually executed by make, not the execution of commands in rules.
Conditional interpretation grammar description:
Conditional judgment keyword:
Example:
.PHONY: testvar1: = Avar2: = $(var1) var3: = test: ifeq ($(var1), $(var2)) @ echo "var1 = = var2" else @ echo "var1! = var2" endif ifneq ($(var2) ) @ echo "var2 is NOT empty" else @ echo "var2 is empty" endif ifdef var2 @ echo "var2 is NOT empty" else @ echo "var2 is empty" endif ifndef var3 @ echo "var3 is empty" else @ echo "var3 is NOT empty" endif
Output result:
8.2. Engineering experience
1. Conditional judgment statements can be preceded by spaces, but cannot have Tab characters ('\ t')
two。 Do not use automatic variables ($@ $^ @) in conditional statements