1 |
# -*-perl-*- |
# -*-perl-*- |
2 |
|
|
3 |
# Updated 6.16.93 variable "MAKE" is default was environment override |
# Updated 16 June 1993 variable "MAKE" is default was environment override |
4 |
# For make 3.63 and above |
# For make 3.63 and above |
5 |
|
|
6 |
$description = "The following test creates a makefile to verify |
$description = "The following test creates a makefile to verify |
14 |
types of foreach loops are tested\n"; |
types of foreach loops are tested\n"; |
15 |
|
|
16 |
|
|
17 |
open(MAKEFILE,"> $makefile"); |
# TEST 0 |
|
|
|
|
# The Contents of the MAKEFILE ... |
|
18 |
|
|
19 |
# On WIN32 systems, the user's path is found in %Path% ($Path) |
# On WIN32 systems, the user's path is found in %Path% ($Path) |
20 |
# |
# |
21 |
$pathvar = (($port_type eq 'Windows') ? "Path" : "PATH"); |
$pathvar = (($port_type eq 'Windows') ? "Path" : "PATH"); |
22 |
|
|
23 |
print MAKEFILE <<EOF; |
run_make_test(" |
|
foo = bletch null \@ garf |
|
24 |
null := |
null := |
25 |
space = ' ' |
space = ' ' |
26 |
auto_var = udef space CC null $pathvar MAKE foo CFLAGS WHITE \@ < |
auto_var = udef space CC null $pathvar".' MAKE foo CFLAGS WHITE @ < |
27 |
av = \$(foreach var, \$(auto_var), \$(origin \$(var)) ) |
foo = bletch null @ garf |
28 |
|
av = $(foreach var, $(auto_var), $(origin $(var)) ) |
29 |
override WHITE := BLACK |
override WHITE := BLACK |
30 |
for_var = \$(addsuffix .c,foo \$(null) \$(foo) \$(space) \$(av) ) |
for_var = $(addsuffix .c,foo $(null) $(foo) $(space) $(av) ) |
31 |
fe = \$(foreach var2, \$(for_var),\$(subst .c,.o, \$(var2) ) ) |
fe = $(foreach var2, $(for_var),$(subst .c,.o, $(var2) ) ) |
32 |
all: auto for2 |
all: auto for2 |
33 |
auto : |
auto : ; @echo $(av) |
34 |
\t\@echo \$(av) |
for2: ; @echo $(fe)', |
35 |
for2: |
'-e WHITE=WHITE CFLAGS=', |
36 |
\t\@echo \$(fe) |
"undefined file default file environment default file command line override automatic automatic |
37 |
EOF |
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"); |
38 |
|
|
39 |
close(MAKEFILE); |
|
40 |
|
# TEST 1: Test that foreach variables take precedence over global |
41 |
&run_make_with_options($makefile, |
# variables in a global scope (like inside an eval). Tests bug #11913 |
42 |
"-e WHITE=WHITE CFLAGS=", |
|
43 |
&get_logfile); |
run_make_test(' |
44 |
|
.PHONY: all target |
45 |
# Create the answer to what should be produced by this Makefile |
all: target |
46 |
$answer = "undefined file default file environment default file command line override automatic automatic |
|
47 |
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\n"; |
x := BAD |
48 |
|
|
49 |
|
define mktarget |
50 |
|
target: x := $(x) |
51 |
|
target: ; @echo "$(x)" |
52 |
|
endef |
53 |
|
|
54 |
|
x := GLOBAL |
55 |
|
|
56 |
&compare_output($answer,&get_logfile(1)); |
$(foreach x,FOREACH,$(eval $(value mktarget)))', |
57 |
|
'', |
58 |
|
'FOREACH'); |
59 |
|
|
60 |
1; |
1; |