Chapter 8: Functions for Transforming Text 85
$(objects:.o=.c)
instead of using the general form:
$(patsubst %.o,%.c,$(objects))
$(strip string)
Removes leading and trailing whitespace from string and replaces each inter-
nal sequence of one or more whitespace characters with a single space. Thus,
‘$(strip a b c )’ results in ‘a b c’.
The function strip can be very useful when used in conjunction with condi-
tionals. When comparing something with the empty string ‘’ using ifeq or
ifneq, you usually want a string of just whitespace to match the empty string
(see Chapter 7 [Conditionals], page 77).
Thus, the following may fail to have the desired results:
.PHONY: all
ifneq "$(needs_made)" ""
all: $(needs_made)
else
all:;@echo ’Nothing to make!’
endif
Replacing the variable reference ‘$(needs_made)’ with the function call
‘$(strip $(needs_made))’ in the ifneq directive would make it more robust.
$(findstring find,in)
Searches in for an occurrence of find. If it occurs, the value is find; otherwise,
the value is empty. You can use this function in a conditional to test for the
presence of a specific substring in a given string. Thus, the two examples,
$(findstring a,a b c)
$(findstring a,b c)
produce the values ‘a’ and ‘’ (the empty string), respectively. See Section 7.3
[Testing Flags], page 80, for a practical application of findstring.
$(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. The patterns are written using
‘%’, just like the patterns used in the patsubst function above.
The filter function can be used to separate out different types of strings (such
as file names) in a variable. For example:
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.c, baz.s and ugh.h but only foo.c, bar.c
and baz.s should be specified in the command to the compiler.
$(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. This is the
exact opposite of the filter function.
Comentários a estes Manuais