90 GNU make
$(and condition1[,condition2[,condition3...]])
The and function provides a “short-circuiting” AND operation. Each argument
is expanded, in order. If an argument expands to an empty string the processing
stops and the result of the expansion is the empty string. If all arguments
expand to a non-empty string then the result of the expansion is the expansion
of the last argument.
8.5 The foreach Function
The foreach function is very different from other functions. It causes one piece of text to
be used repeatedly, each time with a different substitution performed on it. It resembles
the for command in the shell sh and the foreach command in the C-shell csh.
The syntax of the foreach function is:
$(foreach var,list,text)
The first two arguments, var and list, are expanded before anything else is done; note that
the last argument, text, is not expanded at the same time. Then for each word of the
expanded value of list, the variable named by the expanded value of var is set to that word,
and text is expanded. Presumably text contains references to that variable, so its expansion
will be different each time.
The result is that text is expanded as many times as there are whitespace-separated
words in list. The multiple expansions of text are concatenated, with spaces between them,
to make the result of foreach.
This simple example sets the variable ‘files’ to the list of all files in the directories in
the list ‘dirs’:
dirs := a b c d
files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))
Here text is ‘$(wildcard $(dir)/*)’. The first repetition finds the value ‘a’ for dir, so
it produces the same result as ‘$(wildcard a/*)’; the second repetition produces the result
of ‘$(wildcard b/*)’; and the third, that of ‘$(wildcard c/*)’.
This example has the same result (except for setting ‘dirs’) as the following example:
files := $(wildcard a/* b/* c/* d/*)
When text is complicated, you can improve readability by giving it a name, with an
additional variable:
find_files = $(wildcard $(dir)/*)
dirs := a b c d
files := $(foreach dir,$(dirs),$(find_files))
Here we use the variable find_files this way. We use plain ‘=’ to define a recursively-
expanding variable, so that its value contains an actual function call to be re-expanded
under the control of foreach; a simply-expanded variable would not do, since wildcard
would be called only once at the time of defining find_files.
The foreach function has no permanent effect on the variable var; its value and flavor
after the foreach function call are the same as they were beforehand. The other values
which are taken from list are in effect only temporarily, during the execution of foreach.
The variable var is a simply-expanded variable during the execution of foreach. If var was
Comentários a estes Manuais