Simple usage of ifeq, filter, and strip in makefile

CSDN does not support Makefile code.

Makefile example

ifneq (,$(filter $(region), global eea ru in id tr tw jp))
ifneq (,$(filter $(region), tw))
PRODUCT_NAME := product_global
else
PRODUCT_NAME := product_$(region)
endif
endif

Determines whether two variables, usually strings, are equal.

ifeq( 变量1, 变量2)

Determine whether they are not equal.

ifneq( 变量1, 变量2)

filter

$(filter PATTERN...,TEXT)
function name: filter function—filter.
Function function: filter out all the words that do not match the pattern "PATTERN" in the string "TEXT", and keep all the words that match this pattern. Multiple patterns can be used. The pattern generally needs to contain the pattern character "%". When there are multiple patterns, the pattern expressions are separated by spaces.
To put it bluntly, it is simple to understand. If there is a matching pattern in TEXT, return the corresponding string, otherwise return empty.

Return value: All strings matching the pattern "PATTERN" in the "TEXT" string separated by spaces. Function description: The "filter" function can be used to remove certain strings in a variable, and this function is used
in the following example . Example:

sources := foo.c bar.c baz.s ugh.h 
foo: $(sources) 
cc $(filter %.c %.s,$(sources)) -o foo 

The return value used “$(filter %.c %.s,$(sources))”is for cc to compile and generate the target "foo", the return
value of the function is "foo.c bar.c baz.s", and the .h suffix file is removed.

$(strip )

strip removes null characters statement, removes the null characters at the beginning and end of the string (null characters include spaces, [Tab] and other non-displayable characters)

ifeq (1, $(strip $(MY_BUILD)))

The only downside is that it has a bunch of nested spaces, which makes it hard to read. It is also inconvenient to understand.

Guess you like

Origin blog.csdn.net/weixin_40557160/article/details/129831232