2 # $Id: foreach,v 1.6 2012/03/04 00:24:33 psmith Exp $
4 $description = "Test the foreach function.";
6 $details = "This is a test of the foreach function in gnu make.
7 This function starts with a space separated list of
8 names and a variable. Each name in the list is subsituted
9 into the variable and the given text evaluated. The general
10 form of the command is $(foreach var,$list,$text). Several
11 types of foreach loops are tested\n";
16 # Set an environment variable that we can test in the makefile.
17 $extraENV{FOOFOO} = 'foo foo';
19 run_make_test("space = ' '".'
21 auto_var = udef space CC null FOOFOO MAKE foo CFLAGS WHITE @ <
22 foo = bletch null @ garf
23 av = $(foreach var, $(auto_var), $(origin $(var)) )
24 override WHITE := BLACK
25 for_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) )
26 fe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) )
30 '-e WHITE=WHITE CFLAGS=',
31 "undefined file default file environment default file command line override automatic automatic
32 foo.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");
34 delete $extraENV{FOOFOO};
36 # TEST 1: Test that foreach variables take precedence over global
37 # variables in a global scope (like inside an eval). Tests bug #11913
47 target: ; @echo "$(x)"
52 $(foreach x,FOREACH,$(eval $(value mktarget)))',
57 # TEST 2: Check some error conditions.
65 "#MAKEFILE#:2: *** insufficient number of arguments (1) to function 'foreach'. Stop.",
74 "#MAKEFILE#:2: *** insufficient number of arguments (1) to function 'foreach'. Stop.",