Next: Functions for String Substitution and Analysis, Previous: Functions for Transforming Text, Up: Functions for Transforming Text [Contents][Index]
A function call resembles a variable reference. It can appear anywhere a variable reference can appear, and it is expanded using the same rules as variable references. A function call looks like this:
$(function arguments)
or like this:
${function arguments}
Here function is a function name; one of a short list of names
that are part of make
. You can also essentially create your own
functions by using the call
built-in function.
The arguments are the arguments of the function. They are separated from the function name by one or more spaces or tabs, and if there is more than one argument, then they are separated by commas. Such whitespace and commas are not part of an argument’s value. The delimiters which you use to surround the function call, whether parentheses or braces, can appear in an argument only in matching pairs; the other kind of delimiters may appear singly. If the arguments themselves contain other function calls or variable references, it is wisest to use the same kind of delimiters for all the references; write ‘$(subst a,b,$(x))’, not ‘$(subst a,b,${x})’. This is because it is clearer, and because only one type of delimiter is matched to find the end of the reference.
Each argument is expanded before the function is invoked, unless otherwise noted below. The substitution is done in the order in which the arguments appear.
When using characters that are special to make
as function arguments,
you may need to hide them. GNU make
doesn’t support escaping
characters with backslashes or other escape sequences; however, because
arguments are split before they are expanded you can hide them by putting them
into variables.
Characters you may need to hide include:
For example, you can define variables comma
and space
whose
values are isolated comma and space characters, then substitute these
variables where such characters are wanted, like this:
comma:= ,
empty:=
space:= $(empty) $(empty)
foo:= a b c
bar:= $(subst $(space),$(comma),$(foo))
# bar is now ‘a,b,c’.
Here the subst
function replaces each space with a comma, through
the value of foo
, and substitutes the result.