1 minute read

This is from gnu.org

$(subst from, to, text)

Performs a textual replacement on the text text: each occurrence of from is replaced by to.

$(subst ee, EE, feet on the street)

result : ‘fEEt on the strEEt’

$(patsubst pattern, replacement, text)

Finds whitespace-separated words in text that match pattern and replaces them with replacement.

$(patsubst %.c, %.o x.c.c bar.c)

result : ‘x.c.o bar.o’

$(var:pattern=replacement)

is equivalent to

$(patsubst pattern, replacement, $(var))

$(strip string)

Removes leading and trailing whitespace from string and replaces eachi internal sequence of one or more

whitespace characters with a sing space.

$(strip a b c )

result : ‘a b c’

$(findstring find, in)

Searches in for an occurrence of find. If it occurs, the value is find; otherwise, the value is empty.

$(findstring a,a b c)
$(findstring a,b c)

result : ‘a’ ‘‘(the empty string)

$(filter pattern…, text)

Returns all whitespace-separated words in text that do match any of the pattern words, removing any

words that do not match.

sources := foo.c bar.c baz.s ugh.h
foo: $(sources)
	cc $(filter %.c %.s,$(sources)) -o foo

says that foo depends of foo.c bar

$(filter-out pattern…, text)

Returns all whitespace-separated words in text that do not match any of the pattern words, removing the words that do match one or more.

given: objects=main1.o foo.o main2.o bar.o mains=main1.o main2.o

$(filter-out $(mains), $(objedts))

$(sort list)

Sorts the words of list in lexical order, removing duplicate words.

$(sort foo bar lose)

result : ‘bar foo lose’

$(word n, text)

Returns the nth word of text. The legitimate values of n start from 1.

$(word 2, foo bar baz)

result : ‘bar’

$(wordlist s, e, text)

Returns the list of words in text starting with word s and ending with word e (inclusive)/

The legitimate values of s start from 1.

$(wordlist 2, 3, foo bar baz)

return ‘bar baz’

$(words text)

Returns the number of words in text.

$(firstword names…)

The argument names is regarded as a series of names, separated by whitespace.

$(firstword foo bar)

result : ‘foo’

$(lastword names…)

The argument names is regarded as a series of names, separated by wthiespace.

$(lastword foo bar)

result : ‘bar’

Categories:

Updated: