From the docs:
$(patsubst PATTERN,REPLACEMENT,TEXT)
Finds whitespace-separated words in TEXT that match PATTERN and replaces them with REPLACEMENT. Here PATTERN may contain a%
which acts as a wildcard, matching any number of any characters within a word.
...
Whitespace between words is folded into single space characters; leading and trailing whitespace is discarded.
Now, given a makefile, is:
# The pattern for patsubst, does NOT contain '%' foo := $(patsubst x,y,x x x) # The pattern for patsubst, does contain '%' bar := $(patsubst x%,y,x x x) # The variable 'foo', is a result from a patsubst-pattern, that did NOT contain a '%' # The variable 'bar', is a result from a patsubst-pattern, that did contain a '%' all :: @echo 'foo is: "$(foo)"' @echo 'bar is: "$(bar)"'
Executing, we get:
foo is: "y y y" bar is: "y y y"
So, it is obvious, that Make, may or may not "fold" all whitespace into one and single whitespace.
Or, did I do something wrong.
Expanded assignment = defines a recursively-expanded variable. := defines a simply-expanded variable.
The ifeq directive begins the conditional, and specifies the condition. It contains two arguments, separated by a comma and surrounded by parentheses. Variable substitution is performed on both arguments and then they are compared.
In fact all is explained in the doc:
Finds whitespace-separated words in TEXT ...
means that one or more spaces have to separate the words.
... that match PATTERN ...
means that it select only words that match a pattern (which can include some spaces).
... and replaces them with REPLACEMENT.
means that the selected patterns will be replace by a replacement.
A picture is worth a thousand words.
For PATTERN = X
:
+---- SEPARATORS ----+ | | +-------+-------+ +--------+------+ | | | | X space space space X space space space x | | | +---------------------+---------------------+ | PATTERNS
For PATTERN = X%
:
+---- SEPARATORS ---+ | | +-+-+ +-+-+ | | | | X space space space X space space space x | | | | | +------+-----+ +------+-----+ | | | | +--- PATTERNS ------+--------------+
Interesting thing:
When you use the %
character in your pattern, you can re-use it in the replacement, like this:
$(patsubst x%,y%,xa xb xc) # Will be "ya yb yc"
But when you have space character in the %
variable, make will strip them in the replacement.
$(patsubst x%,y%,xa xb xc) # Will also be "ya yb yc"
EDIT: After reading the source code, the interesting things are:
function.c +146
: The function patsubst_expand_pat
misc.c +337
: The function find_next_token
misc.c +325
: The function next_token
So here is the behavior:
%
in the pattern
, this is a simple substitution (which keep the spaces).text
by words and get rid of all spaces (using the isblank function).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With