Search notes:

GNU make: function $(foreach …)

$(foreach  var,list,text)
The following example iterates over each word in $(list).
In each iteration, first the variable with the name word is set to the value of the word of the iteration, and then, the text $(word)-$(word) is expanded.
Thus, this makefile prints foo-foo bar-bar baz-baz when invoked.
list = foo bar baz
list_2 = $(foreach word,$(list),$(word)-$(word))

all:
	@echo $(list_2)
Github repository about-Makefile, path: /functions/foreach/double-words.mak
Of course, calls to $(foreach) can be nested:
bla      = foo bar baz
list_foo = ding dong
list_bar = one two three
list_baz = XXX

cross_product = $(foreach T, $(bla),   \
	$(foreach U, $(list_$T),             \
	   $T\,$U                            \
	)                                    \
)

all:
	@echo $(cross_product)
Github repository about-Makefile, path: /functions/foreach/nested.mak
When invoked, the above makefile prints foo,ding foo,dong bar,one bar,two bar,three baz,XXX.

See also

make

Index