Changing macro definitions in a command
When macros in the shell commands are defined in the description file, you can change the values that the make command assigns to the macro.
To change the assignment of the macro, put a : (colon) after the macro name, followed by a replacement string. The form is as follows:
$(macro:string1=string2)
where string1
is
either a suffix or a word to be replaced in the macro definition and string2
is
the replacement suffix or word.When the make command reads the macro and begins to assign the values to the macro based on the macro definition, the command replaces each string1 in the macro definition with a value of string2. For example, if the description file contains the macro definition:
FILES=test.o sample.o form.o defs
You can replace the form.o file with a new file, input.o, by using the macro in the description-file commands, as follows:
cc -o $(FILES:form.o=input.o)
cc -c $(FILES:.o=.c)
$(macro: op%os= np%ns)
Where op
is the existing (old) prefix, os
is
the existing (old) suffix, np
is the new prefix,
and ns
is the new suffix.
op
, os
, np
and ns
can
be a string of zero or more characters. The pattern matched by the
percent sign (%) on the left-hand side of the equal-sign, which is
a string of zero or more characters, is used with np
and ns
to
replace the macro value. The percent sign (%) operator can appear
any number of times on the right-hand side of the equal sign (=).
FOO=abc def
BAR=$(FOO:%=dir1/%.o dir1/%_cltn.o)
sets the value of BAR
to dir1/abc.o
dir1/abc_cltn.o
dir1/def.o
dir1/def_cltn.o
Changing the value of a macro in this manner is useful when maintaining archive libraries. For more information, see the ar command.