1*69606e3fSchristos# -*-perl-*- 2*69606e3fSchristos# $Id: foreach,v 1.1.1.1 2014/08/18 06:47:57 christos Exp $ 3*69606e3fSchristos 4*69606e3fSchristos$description = "Test the foreach function."; 5*69606e3fSchristos 6*69606e3fSchristos$details = "This is a test of the foreach function in gnu make. 7*69606e3fSchristosThis function starts with a space separated list of 8*69606e3fSchristosnames and a variable. Each name in the list is subsituted 9*69606e3fSchristosinto the variable and the given text evaluated. The general 10*69606e3fSchristosform of the command is $(foreach var,$list,$text). Several 11*69606e3fSchristostypes of foreach loops are tested\n"; 12*69606e3fSchristos 13*69606e3fSchristos 14*69606e3fSchristos# TEST 0 15*69606e3fSchristos 16*69606e3fSchristos# Set an environment variable that we can test in the makefile. 17*69606e3fSchristos$extraENV{FOOFOO} = 'foo foo'; 18*69606e3fSchristos 19*69606e3fSchristosrun_make_test("space = ' '".' 20*69606e3fSchristosnull := 21*69606e3fSchristosauto_var = udef space CC null FOOFOO MAKE foo CFLAGS WHITE @ < 22*69606e3fSchristosfoo = bletch null @ garf 23*69606e3fSchristosav = $(foreach var, $(auto_var), $(origin $(var)) ) 24*69606e3fSchristosoverride WHITE := BLACK 25*69606e3fSchristosfor_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) ) 26*69606e3fSchristosfe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) ) 27*69606e3fSchristosall: auto for2 28*69606e3fSchristosauto : ; @echo $(av) 29*69606e3fSchristosfor2: ; @echo $(fe)', 30*69606e3fSchristos '-e WHITE=WHITE CFLAGS=', 31*69606e3fSchristos "undefined file default file environment default file command line override automatic automatic 32*69606e3fSchristosfoo.o bletch.o null.o @.o garf.o .o .o undefined.o file.o default.o file.o environment.o default.o file.o command.o line.o override.o automatic.o automatic.o"); 33*69606e3fSchristos 34*69606e3fSchristosdelete $extraENV{FOOFOO}; 35*69606e3fSchristos 36*69606e3fSchristos# TEST 1: Test that foreach variables take precedence over global 37*69606e3fSchristos# variables in a global scope (like inside an eval). Tests bug #11913 38*69606e3fSchristos 39*69606e3fSchristosrun_make_test(' 40*69606e3fSchristos.PHONY: all target 41*69606e3fSchristosall: target 42*69606e3fSchristos 43*69606e3fSchristosx := BAD 44*69606e3fSchristos 45*69606e3fSchristosdefine mktarget 46*69606e3fSchristostarget: x := $(x) 47*69606e3fSchristostarget: ; @echo "$(x)" 48*69606e3fSchristosendef 49*69606e3fSchristos 50*69606e3fSchristosx := GLOBAL 51*69606e3fSchristos 52*69606e3fSchristos$(foreach x,FOREACH,$(eval $(value mktarget)))', 53*69606e3fSchristos '', 54*69606e3fSchristos 'FOREACH'); 55*69606e3fSchristos 56*69606e3fSchristos 57*69606e3fSchristos# TEST 2: Check some error conditions. 58*69606e3fSchristos 59*69606e3fSchristosrun_make_test(' 60*69606e3fSchristosx = $(foreach ) 61*69606e3fSchristosy = $x 62*69606e3fSchristos 63*69606e3fSchristosall: ; @echo $y', 64*69606e3fSchristos '', 65*69606e3fSchristos "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.", 66*69606e3fSchristos 512); 67*69606e3fSchristos 68*69606e3fSchristosrun_make_test(' 69*69606e3fSchristosx = $(foreach ) 70*69606e3fSchristosy := $x 71*69606e3fSchristos 72*69606e3fSchristosall: ; @echo $y', 73*69606e3fSchristos '', 74*69606e3fSchristos "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.", 75*69606e3fSchristos 512); 76*69606e3fSchristos 77*69606e3fSchristos1; 78