Text Manipulation with Macros and Functions
Standard versions of make provide a limited text manipulation facility:
-
$(
macro
:
s1
=
s2
)
Evaluates to the current definition of
$(
macro)
, after substituting the string s2 for every occurrence of s1 that occurs either immediately before a blank or tab, or at the end of the macro definition.
GNU make supports this for compatibility with Unix make and the POSIX standard. However, GNU make goes far beyond simple text substitution, providing a host of functions for text manipulation. The following list provides a brief description of each function.
$(addprefix
prefix
,
names
...)
Generates a new list, created by prepending prefix to each of the names.
$(addsuffix
suffix
,
names
...)
Generates a new list, created by appending suffix to each of the names.
$(basename
names
...)
Returns a list of the basename of each of the names. The basename is the text up to but not including the final period.
$(call
var
,
param
,
...)
The
call
function allows you to treat the value of a variable as a procedure. var is the name of a variable, not a variable reference. The params are assigned to temporary variables that may be referenced as$(1)
,$(2)
, and so on.$(0)
will be the name of the variable. The value of var should reference the temporary values. The result ofcall
is the result of evaluating var in this way. If var names a built-in function, that function is always called, even if a make variable of the same name exists. Finally,call
may be used recursively; each ...
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.