manpagez: man pages & more
info make
Home | html | info | man

File: make.info,  Node: Substitution Refs,  Next: Computed Names,  Prev: Advanced.php">Advanced,  Up: Advanced.php">Advanced

6.3.1 Substitution References
-----------------------------

A "substitution reference" substitutes the value of a variable with
alterations that you specify.  It has the form '$(VAR:A=B)' (or
'${VAR:A=B}') and its meaning is to take the value of the variable VAR,
replace every A at the end of a word with B in that value, and
substitute the resulting string.

   When we say "at the end of a word", we mean that A must appear either
followed by whitespace or at the end of the value in order to be
replaced; other occurrences of A in the value are unaltered.  For
example:

     foo := a.o b.o l.a c.o
     bar := $(foo:.o=.c)

sets 'bar' to 'a.c b.c l.a c.c'.  *Note Setting Variables: Setting.

   A substitution reference is shorthand for the 'patsubst' expansion
function (*note Functions for String Substitution and Analysis: Text
Functions.): '$(VAR:A=B)' is equivalent to '$(patsubst %A,%B,VAR)'.  We
provide substitution references as well as 'patsubst' for compatibility
with other implementations of 'make'.

   Another type of substitution reference lets you use the full power of
the 'patsubst' function.  It has the same form '$(VAR:A=B)' described
above, except that now A must contain a single '%' character.  This case
is equivalent to '$(patsubst A,B,$(VAR))'.  *Note Functions for String
Substitution and Analysis: Text Functions, for a description of the
'patsubst' function.  For example:

     foo := a.o b.o l.a c.o
     bar := $(foo:%.o=%.c)

sets 'bar' to 'a.c b.c l.a c.c'.

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.