By using conditional judgment, you can have make to select different execution branches depending on the runtime's circumstances. A conditional expression can be a value of a comparison variable, or a value that compares variables and constants.
One, example
The following example determines whether the $ (CC) variable is "gcc" and, if so, compiles the target using the GNU function.
It can be seen that in this rule of the example above, the target "foo" could choose a different library of functions to compile the program based on the variable "$ (CC)" value.
We can see three keywords from the example above: ifeq, Else, and endif. Ifeq means the beginning of a conditional statement, and specifies a conditional expression that contains two arguments, separated by commas, with expressions enclosed in parentheses. else indicates that the conditional expression is false. ENDIF represents the end of a conditional statement, and any one of the conditional expressions should end with endif.
When our variable $ (CC) value is "gcc", the rule for the target Foo is:
where <conditional-directive> represents a conditional keyword, such as "ifeq". There are four of these keywords.
The first one is the "ifeq" we've seen before.
Whether the values for the comparison parameters "Arg1" and "arg2" are the same, or true if they are different. Similar to "ifeq".
The third conditional keyword is "ifdef". The syntax is:
Ifdef <variable-name>
If the value of the variable <variable-name> is not null, then the expression is true. Otherwise, the expression is false. Of course, <vari able-name> can also be the return value of a function. Note that ifdef just tests whether a variable has a value, and does not extend the variable to its current position. Let's take a look at two examples:
Example one:
Bar =
Foo = $ (bar)
ifdef foo
Frobozz = yes
Else
Frobozz = No
endif
Example two:
Foo =
ifdef foo
Frobozz = yes
Else
Frobozz = No
endif
In the first example, the "$ (frobozz)" value is "yes" and the second is "no".
The fourth conditional keyword is "ifndef". Its syntax is:
Ifndef <variable-name>
I will not say more, and "ifdef" is the opposite meaning.
In <conditional-directive> this line, the extra space is allowed, but cannot start with the [Tab] key (otherwise it is considered a command). The comment "#" is also safe. "Else" and "endif" are the same, as long as you do not start with the [Tab] key.
It is especially important to note that make is the value of the conditional expression when reading the makefile and selects the statement based on the value of the conditional expression, so you'd better not put the automation variable (such as "$@", etc.) into the conditional expression, because the automation variable is available at run time.
Also, to avoid confusion, make does not allow the entire conditional statement to be divided into two parts in separate files.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.