make: Syntax of Functions

1 
1 8.1 Function Call Syntax
1 ========================
1 
1 A function call resembles a variable reference.  It can appear anywhere
1 a variable reference can appear, and it is expanded using the same rules
1 as variable references.  A function call looks like this:
1 
1      $(FUNCTION ARGUMENTS)
1 
1 or like this:
1 
1      ${FUNCTION ARGUMENTS}
1 
1    Here FUNCTION is a function name; one of a short list of names that
1 are part of 'make'.  You can also essentially create your own functions
1 by using the 'call' built-in function.
1 
1    The ARGUMENTS are the arguments of the function.  They are separated
1 from the function name by one or more spaces or tabs, and if there is
1 more than one argument, then they are separated by commas.  Such
1 whitespace and commas are not part of an argument's value.  The
1 delimiters which you use to surround the function call, whether
1 parentheses or braces, can appear in an argument only in matching pairs;
1 the other kind of delimiters may appear singly.  If the arguments
1 themselves contain other function calls or variable references, it is
1 wisest to use the same kind of delimiters for all the references; write
1 '$(subst a,b,$(x))', not '$(subst a,b,${x})'.  This is because it is
1 clearer, and because only one type of delimiter is matched to find the
1 end of the reference.
1 
1    The text written for each argument is processed by substitution of
1 variables and function calls to produce the argument value, which is the
1 text on which the function acts.  The substitution is done in the order
1 in which the arguments appear.
1 
1    Commas and unmatched parentheses or braces cannot appear in the text
1 of an argument as written; leading spaces cannot appear in the text of
1 the first argument as written.  These characters can be put into the
1 argument value by variable substitution.  First define variables 'comma'
1 and 'space' whose values are isolated comma and space characters, then
1 substitute these variables where such characters are wanted, like this:
1 
1      comma:= ,
1      empty:=
1      space:= $(empty) $(empty)
1      foo:= a b c
1      bar:= $(subst $(space),$(comma),$(foo))
1      # bar is now 'a,b,c'.
1 
1 Here the 'subst' function replaces each space with a comma, through the
1 value of 'foo', and substitutes the result.
1