Regarding https://www.gnu.org/software/make/manual/html_node/Foreach-Function.html I have spent hours and hours trying to figure out what you are trying to say.
Yes I understand the sh, and perl "for" functions just fine. The problem apparently is your example, dirs := a b c d files := $(foreach dir,$(dirs),$(wildcard $(dir)/*)) In it you are trying to do many things at once, causing your example to go beyond simple users' comprehension. Therefore please add an additional previous simpler example, refraining from using any other function than just the foreach function. Something simple, like sh's $ for i in a b c; do echo =$i=; done =a= =b= =c=