Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Definition and call of conditional judgment function of make-- variable

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

one。 Advanced topics for variables

a. Substitution of variable value

1. Replaces the suffix character (string) in the variable with the specified character (string)

two。 Syntax format: $(var:a=b) (replace a with b)

a. There cannot be any spaces in the replacement expression

B.make supports the use of ${} to value variables

Example

Src:=a.cc b.cc c.ccobj test test: @ echo "obj= > $(obj)"

Output result

From the above figure, you can see the replacement of the value of the variable

b. Mode substitution of variables

1. Use% to retain the specified characters in the value of the variable, replacing other characters

two。 Syntax format: $(var:a%b=x%y)

a. There cannot be any spaces in the replacement expression

B.make supports the use of ${} to value variables

Example

Src:=a1b.c a2b.c a3b.cobj test $(src:a%b.c=x%y) test: @ echo "obj= > $(obj)"

Output result

c. Nested references to the values of variables

1. A variable name can contain references to other variables

two。 The essence of nested references is to use one variable to represent another variable.

As shown in the figure

d. Command line variable

1. When you run make, define variables on the command line

two。 Command line variables override variables defined in makefile by default

Example and running result

E.override keyword

1. Used to indicate that variables defined in makefile cannot be overridden

two。 The definition and assignment of variables requires the override keyword

Example and running result

F.define keyword

1. Used to define multiline variables in makefile

two。 The definition of multiline variables starts with the variable name and ends with endef.

3. You can use the override keyword to prevent variables from being overwritten

Variables defined by 4.define are equivalent to variables defined using =

Example and running result

two。 Conditional judgment statement

Conditional judgment statements are supported in A.makefile

1. The execution of make can be determined according to the value of the condition.

two。 You can compare two different variables or variables and constant values

It should be noted 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 rules.

There are four keywords for conditional judgment:

The keyword function ifeq determines whether the parameter is equal, equal is true, otherwise it is falseifneq to judge whether the parameter is not equal, non-equal is true, otherwise it is falseifdef to judge whether the variable has a value, the value is true, otherwise it is falseifndef to determine whether the variable has no value, no value is true, otherwise it is false

Note:

1. Conditional judgment statements can be preceded by spaces, but not Tab characters

two。 Do not use automatic variables ($^, $) in conditional statements

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report