1 | # -*-perl-*-
|
---|
2 | # $Id: foreach,v 1.5 2006/03/10 02:20:46 psmith Exp $
|
---|
3 |
|
---|
4 | $description = "Test the foreach function.";
|
---|
5 |
|
---|
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";
|
---|
12 |
|
---|
13 |
|
---|
14 | # TEST 0
|
---|
15 |
|
---|
16 | # Set an environment variable that we can test in the makefile.
|
---|
17 | # kmk: CC isn't a default.
|
---|
18 | $extraENV{FOOFOO} = 'foo foo';
|
---|
19 | $CC_origin = $is_kmk ? "undefined" : "default";
|
---|
20 |
|
---|
21 | run_make_test("space = ' '".'
|
---|
22 | null :=
|
---|
23 | auto_var = udef space CC null FOOFOO MAKE foo CFLAGS WHITE @ <
|
---|
24 | foo = bletch null @ garf
|
---|
25 | av = $(foreach var, $(auto_var), $(origin $(var)) )
|
---|
26 | override WHITE := BLACK
|
---|
27 | for_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) )
|
---|
28 | fe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) )
|
---|
29 | all: auto for2
|
---|
30 | auto : ; @echo $(av)
|
---|
31 | for2: ; @echo $(fe)',
|
---|
32 | '-j1 -e WHITE=WHITE CFLAGS=',
|
---|
33 | "undefined file ". $CC_origin ." file environment default file command line override automatic automatic
|
---|
34 | foo.o bletch.o null.o @.o garf.o .o .o undefined.o file.o ". $CC_origin .".o file.o environment.o default.o file.o command.o line.o override.o automatic.o automatic.o");
|
---|
35 |
|
---|
36 | delete $extraENV{FOOFOO};
|
---|
37 |
|
---|
38 | # TEST 1: Test that foreach variables take precedence over global
|
---|
39 | # variables in a global scope (like inside an eval). Tests bug #11913
|
---|
40 |
|
---|
41 | run_make_test('
|
---|
42 | .PHONY: all target
|
---|
43 | all: target
|
---|
44 |
|
---|
45 | x := BAD
|
---|
46 |
|
---|
47 | define mktarget
|
---|
48 | target: x := $(x)
|
---|
49 | target: ; @echo "$(x)"
|
---|
50 | endef
|
---|
51 |
|
---|
52 | x := GLOBAL
|
---|
53 |
|
---|
54 | $(foreach x,FOREACH,$(eval $(value mktarget)))',
|
---|
55 | '',
|
---|
56 | 'FOREACH');
|
---|
57 |
|
---|
58 |
|
---|
59 | # TEST 2: Check some error conditions.
|
---|
60 |
|
---|
61 | run_make_test('
|
---|
62 | x = $(foreach )
|
---|
63 | y = $x
|
---|
64 |
|
---|
65 | all: ; @echo $y',
|
---|
66 | '',
|
---|
67 | "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.",
|
---|
68 | 512);
|
---|
69 |
|
---|
70 | run_make_test('
|
---|
71 | x = $(foreach )
|
---|
72 | y := $x
|
---|
73 |
|
---|
74 | all: ; @echo $y',
|
---|
75 | '',
|
---|
76 | "#MAKEFILE#:2: *** insufficient number of arguments (1) to function `foreach'. Stop.",
|
---|
77 | 512);
|
---|
78 |
|
---|
79 | 1;
|
---|