make: Substitution Refs
1
1 6.3.1 Substitution References
1 -----------------------------
1
1 A "substitution reference" substitutes the value of a variable with
1 alterations that you specify. It has the form '$(VAR:A=B)' (or
1 '${VAR:A=B}') and its meaning is to take the value of the variable VAR,
1 replace every A at the end of a word with B in that value, and
1 substitute the resulting string.
1
1 When we say "at the end of a word", we mean that A must appear either
1 followed by whitespace or at the end of the value in order to be
1 replaced; other occurrences of A in the value are unaltered. For
1 example:
1
1 foo := a.o b.o c.o
1 bar := $(foo:.o=.c)
1
1 sets 'bar' to 'a.c b.c c.c'. ⇒Setting Variables Setting.
1
1 A substitution reference is actually an abbreviation for use of the
11 'patsubst' expansion function (⇒Functions for String Substitution
and Analysis Text Functions.). We provide substitution references as
1 well as 'patsubst' for compatibility with other implementations of
1 'make'.
1
1 Another type of substitution reference lets you use the full power of
1 the 'patsubst' function. It has the same form '$(VAR:A=B)' described
1 above, except that now A must contain a single '%' character. This case
11 is equivalent to '$(patsubst A,B,$(VAR))'. ⇒Functions for String
Substitution and Analysis Text Functions, for a description of the
1 'patsubst' function.
1
1 For example:
1
1 foo := a.o b.o c.o
1 bar := $(foo:%.o=%.c)
1
1 sets 'bar' to 'a.c b.c c.c'.
1