Imported Upstream version 4.3
[platform/upstream/make.git] / tests / scripts / features / se_explicit
1 #                                                                    -*-perl-*-
2 $description = "Test second expansion in ordinary rules.";
3
4 $details = "";
5
6 # TEST #0: Test handing of '$' in prerequisites with and without second
7 # expansion.
8
9 # If we don't support archives then the prerequisite is different
10 my $prereq = exists $FEATURES{'archives'} ? '$' : '$(PRE)';
11
12 run_make_test(q!
13 ifdef SE
14   .SECONDEXPANSION:
15 endif
16 foo$$bar: bar$$baz bar$$biz ; @echo '$@ : $^'
17 PRE = one two
18 bar$$baz: $$(PRE)
19 baraz: $$(PRE)
20 PRE = three four
21 .DEFAULT: ; @echo '$@'
22 !,
23               '',
24               "$prereq\nbar\$biz\nfoo\$bar : bar\$baz bar\$biz");
25
26 run_make_test(undef, 'SE=1', "three\nfour\nbariz\nfoo\$bar : baraz bariz");
27
28 # TEST #1: automatic variables.
29 #
30 run_make_test(q!
31 .SECONDEXPANSION:
32 .DEFAULT: ; @echo '$@'
33
34 foo: bar baz
35
36 foo: biz | buz
37
38 foo: $$@.1 \
39      $$<.2 \
40      $$(addsuffix .3,$$^) \
41      $$(addsuffix .4,$$+) \
42      $$|.5 \
43      $$*.6
44
45 !,
46 '',
47 'bar
48 baz
49 biz
50 buz
51 foo.1
52 bar.2
53 bar.3
54 baz.3
55 biz.3
56 bar.4
57 baz.4
58 biz.4
59 buz.5
60 .6
61 ');
62
63
64 # Test #2: target/pattern -specific variables.
65 #
66 run_make_test(q!
67 .SECONDEXPANSION:
68 .DEFAULT: ; @echo '$@'
69
70 foo.x: $$a $$b
71
72 foo.x: a := bar
73
74 %.x: b := baz
75 !,
76 '',
77 'bar
78 baz
79 ');
80
81
82 # Test #3: order of prerequisites.
83 #
84 run_make_test(q!
85 .SECONDEXPANSION:
86 .DEFAULT: ; @echo '$@'
87
88 all: foo bar baz
89
90 # Subtest #1
91 foo: foo.1; @:
92 foo: foo.2
93 foo: foo.3
94
95 # Subtest #2
96 bar: bar.2
97 bar: bar.1; @:
98 bar: bar.3
99
100 # Subtest #3
101 baz: baz.1
102 baz: baz.2
103 baz: ; @:
104 !,
105 '',
106 'foo.1
107 foo.2
108 foo.3
109 bar.1
110 bar.2
111 bar.3
112 baz.1
113 baz.2
114 ');
115
116 # TEST #4: eval in a context where there is no reading_file
117 run_make_test(q!
118 .SECONDEXPANSION:
119 all : $$(eval $$(info test))
120 !,
121             '', "test\n#MAKE#: Nothing to be done for 'all'.\n");
122
123 # TEST #5: (NEGATIVE) catch eval in a prereq list trying to create new
124 # target/prereq relationships.
125
126 run_make_test(q!
127 .SECONDEXPANSION:
128 proj1.exe : proj1.o $$(eval $$(test))
129 define test
130 proj1.o : proj1.c
131 proj1.c: proj1.h
132 endef
133 !,
134               '', "#MAKE#: *** prerequisites cannot be defined in recipes.  Stop.\n", 512);
135
136
137 # Automatic $$+ variable expansion issue.  Savannah bug #25780
138 run_make_test(q!
139 all : foo foo
140 .SECONDEXPANSION:
141 all : $$+ ; @echo '$+'
142 foo : ;
143 !,
144                   '', "foo foo foo foo\n");
145
146
147 # Automatic $$+ variable expansion issue.  Savannah bug #25780
148 run_make_test(q!
149 all : bar bar
150 bar : ;
151 q%x : ;
152 .SECONDEXPANSION:
153 a%l: q1x $$+ q2x ; @echo '$+'
154 !,
155                   '', "q1x bar bar q2x bar bar\n");
156
157
158 # Allow patsubst shorthand in second expansion context.
159 # Requires the colon to be quoted.  Savannah bug #16545
160 run_make_test(q!
161 .PHONY: foo.bar
162 .SECONDEXPANSION:
163 foo: $$(@\\:%=%.bar); @echo '$^'
164 !,
165               '', "foo.bar\n");
166
167 # SV 54549 : Ensure we don't free used variable_sets
168 run_make_test(q!
169 foo: -lcat
170
171 # Removing second expansion prevents segfault
172 .SECONDEXPANSION:
173 foo: $$@.o ;
174
175 # Having an empty command here prevents segfault unless,
176 # the environment is empty. `env -i make foo`
177 # MFLAGS=-w or MAKEFLAGS=-w `env MFLAGS=-w make foo`
178 # libcat.a target calls an extra command, `@true \n @touch $@`
179 # odd.
180 %.o: ; @true
181
182 # Having an empty command prevents segfault.
183 -l%: lib%.a ; @true
184
185 # Not creating libcat.a here prevents segfault,
186 libcat.a: ; @touch $@
187 !,
188               '', q!#MAKEFILE#:16: Recipe was specified for file '-lcat' at #MAKEFILE#:19,
189 #MAKEFILE#:16: but '-lcat' is now considered the same file as 'libcat.a'.
190 #MAKEFILE#:16: Recipe for 'libcat.a' will be ignored in favor of the one for '-lcat'.!);
191 unlink('libcat.a');
192
193 # SV 28456 : Don't reset $$< for default recipes
194 run_make_test(q!
195 .SECONDEXPANSION:
196
197 .PHONY: biz baz
198 biz: baz ;
199 biz: $$(info $$<)
200 !,
201               '', "baz\n#MAKE#: Nothing to be done for 'biz'.\n");
202
203 1;