Today , as work need ,I saw something about the foreach function in makefile and now I am writing it out.
$(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 textcontains references to that variable, so its expansion will be different each time.
OK,let see some examples.
dirs := a b c d files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))
As you can see from the example, the dir represent a,b,c and d. The
This example has the same result (except for setting ‘dirs’) as the following example:
files := $(wildcard a/* b/* c/* d/*)