In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
As we said before, makefile is a scripting language program, so the program will have the corresponding syntax. Conditional judgment statements are supported in makefile. You can determine the execution of make according to the value of the condition, or you can compare two different variables or variables and constant values. It is important to note that conditional judgment statements can only be used to control the statements actually executed by make; however, you cannot control the execution of commands in the rules. The format is as follows
The syntax of the conditional judgment statement is as follows
So what are the key conditions in makefile?
Keyword
Function
Ifeq
Determine whether the parameters are equal, equal to true, otherwise to false
Ifneq
Determine whether the parameter is not equal. It is true, or false.
Ifdef
Determine whether the variable has a value. The value is true, otherwise it is falseifndef
Determine whether the variable has no value, no value is true, otherwise it is false
Let's take the code as an 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
Let's take a look at the compilation results.
We see that the compilation went wrong because ifeq is a rule, not a command, so it must be preceded by a space rather than a Tab key. Let's change it to a space and have a look.
We see that the compilation has passed and the normal operation ends. The variable var2 takes the value of the variable var1, so the first one will definitely output equal when their comparison is equal; the second one uses var2 and null characters to compare, then var2 is definitely not empty; the third directly uses the ifdef keyword to determine whether var2 exists; and the last var3 must be empty. Based on the experience of some predecessors, the following rules are summarized: a > conditional judgment statements can be preceded by spaces, but not Tab characters ('\ t'); b > do not use automatic variables in conditional statements ($@, $^, $a complete conditional statement must be in the same makefile; d > conditional judgment is similar to macros in C language, the preprocessing stage is valid, but the execution phase is invalid. E > make when loading makefile, first evaluate the value of the expression (different ways of assignment, different ways of calculation), and determine the content of execution according to the expression of the judgment statement.
So let's see if the following code output is the same?
.PHNY: tevar1: = var2: = $(var1) var3 = var4 = $(var3) test: ifdef var1 @ echo "var1 is defined" else @ echo "var1 is NOT defined" endif ifdef var2 @ echo "var2 is defined" else @ echo "var2 is NOT defined" endif ifdef var3 @ echo "var3 is defined" else @ echo "var3 is NOT defined" Endif ifdef var4 @ echo "var4 is defined" else @ echo "var4 is NOT defined" endif
We see no difference between the two, the result should be the same, the output is empty. Let's take a look at the compilation results.
So we see that the first three are empty, but the var4 is not empty. Let's take a closer look. Both var1 and var2 are defined as direct assignments (: =), while var3 and var4 are recursive assignments (=). From the compiler's point of view, var4 has a value, but it's just not sure what its value is at compile time. Let's add var3 = A below to give var3 a specific value and try to see if the effect is the same.
The effect is the same. Therefore, we do not recommend this way of recursive assignment in makefile, which can easily lead to misunderstanding. Through the study of conditional judgment sentence, it is summarized as follows: 1, conditional judgment determines the execution of make according to the value of condition; 2, conditional judgment can compare two different variables or variables and constant values; 3, conditional judgment reprocessing stage is effective, execution stage is invalid; 4, conditional judgment can not control the execution process of the command in the rule.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.