summaryrefslogtreecommitdiff
path: root/tests/scripts/features/patspecific_vars
blob: 31359cfb5bd399804e78edfe6aa062548edc37e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#                                                                    -*-perl-*-
$description = "Test pattern-specific variable settings.";

$details = "\
Create a makefile containing various flavors of pattern-specific variable
settings, override and non-override, and using various variable expansion
rules, semicolon interference, etc.";

open(MAKEFILE,"> $makefile");

print MAKEFILE <<'EOF';
all: one.x two.x three.x
FOO = foo
BAR = bar
BAZ = baz
one.x: override FOO = one
%.x: BAR = two
t%.x: BAR = four
thr% : override BAZ = three
one.x two.x three.x: ; @echo $@: $(FOO) $(BAR) $(BAZ)
four.x: baz ; @echo $@: $(FOO) $(BAR) $(BAZ)
baz: ; @echo $@: $(FOO) $(BAR) $(BAZ)

# test matching multiple patterns
a%: AAA = aaa
%b: BBB = ccc
a%: BBB += ddd
%b: AAA ?= xxx
%b: AAA += bbb
.PHONY: ab
ab: ; @echo $(AAA); echo $(BBB)
EOF

close(MAKEFILE);


# TEST #1 -- basics

&run_make_with_options($makefile, "", &get_logfile);
$answer = "one.x: one two baz\ntwo.x: foo four baz\nthree.x: foo four three\n";
&compare_output($answer,&get_logfile(1));


# TEST #2 -- try the override feature

&run_make_with_options($makefile, "BAZ=five", &get_logfile);
$answer = "one.x: one two five\ntwo.x: foo four five\nthree.x: foo four three\n";
&compare_output($answer,&get_logfile(1));


# TEST #3 -- make sure patterns are inherited properly

&run_make_with_options($makefile, "four.x", &get_logfile);
$answer = "baz: foo two baz\nfour.x: foo two baz\n";
&compare_output($answer,&get_logfile(1));


# TEST #4 -- test multiple patterns matching the same target

&run_make_with_options($makefile, "ab", &get_logfile);
$answer = "aaa bbb\nccc ddd\n";
&compare_output($answer,&get_logfile(1));

# TEST #5 -- test pattern-specific exported variables
#
run_make_test('
/%: export foo := foo

/bar:
	@test "$(foo)" == "$$foo"
', '', '');


# TEST #6 -- test expansion of pattern-specific simple variables
#
run_make_test('
.PHONY: all

all: inherit := good $$t
all: bar baz

b%: pattern := good $$t

global := orginal $$t


# normal target
#
ifdef rec
bar: a = global: $(global) pattern: $(pattern) inherit: $(inherit)
else
bar: a := global: $(global) pattern: $(pattern) inherit: $(inherit)
endif

bar: ; @echo \'normal: $a;\'


# pattern target
#
ifdef rec
%z: a = global: $(global) pattern: $(pattern) inherit: $(inherit)
else
%z: a := global: $(global) pattern: $(pattern) inherit: $(inherit)
endif

%z: ; @echo \'pattrn: $a;\'


global := new $$t
',
'',
'normal: global: orginal $t pattern:  inherit: ;
pattrn: global: orginal $t pattern:  inherit: ;');


# TEST #7 -- test expansion of pattern-specific recursive variables
#
run_make_test(undef, # reuse previous makefile
'rec=1',
'normal: global: new $t pattern: good $t inherit: good $t;
pattrn: global: new $t pattern: good $t inherit: good $t;');


1;