2 $description = "Test target-specific variable settings.";
5 Create a makefile containing various flavors of target-specific variable
6 values, override and non-override, and using various variable expansion
7 rules, semicolon interference, etc.";
9 open(MAKEFILE,"> $makefile");
11 print MAKEFILE <<'EOF';
15 one: override FOO = one
16 one two: ; @echo $(FOO) $(BAR)
20 # Some things that shouldn't be target vars
22 funk : override adelic
23 adelic override : ; echo $@
24 # Test per-target recursive variables
27 four: ; @echo '$(FOO) $(VAR$(FOO)) $(VAR) $(VARx)'
29 five six : VAR$(FOO)=good
30 five six: ;@echo '$(FOO) $(VAR$(FOO)) $(VAR) $(VARx) $(VARfoo)'
31 # Test per-target variable inheritance
33 seven eight: ; @echo $@: $(FOO) $(BAR)
37 # Test the export keyword with per-target variables
38 nine: ; @echo $(FOO) $(BAR) $$FOO $$BAR
44 ten one$(EQ)two $(EQ):;@echo $@
45 .PHONY: one two three four five six seven eight nine ten $(EQ) one$(EQ)two
46 # Test target-specific vars with pattern/suffix rules
49 %.q : ; @echo $(QVAR) $(RVAR)
51 # Target-specific vars with multiple LHS pattern rules
52 %.r %.s %.t: ; @echo $(QVAR) $(RVAR) $(SVAR) $(TVAR)
54 foo.t : TVAR := $(QVAR)
61 &run_make_with_options($makefile, "one two three", &get_logfile);
62 $answer = "one bar\nfoo two\nBAR=1000\nfoo bar\n";
63 &compare_output($answer,&get_logfile(1));
67 &run_make_with_options($makefile, "one two FOO=1 BAR=2", &get_logfile);
68 $answer = "one 2\n1 2\n";
69 &compare_output($answer,&get_logfile(1));
73 &run_make_with_options($makefile, "four", &get_logfile);
74 $answer = "x ok ok\n";
75 &compare_output($answer,&get_logfile(1));
79 &run_make_with_options($makefile, "seven", &get_logfile);
80 $answer = "eight: seven eight\nseven: seven seven\n";
81 &compare_output($answer,&get_logfile(1));
85 &run_make_with_options($makefile, "nine", &get_logfile);
86 $answer = "wallace bar wallace bar\n";
87 &compare_output($answer,&get_logfile(1));
91 &run_make_with_options($makefile, "ten", &get_logfile);
92 $answer = "one=two\none bar\n=\nfoo two\nten\n";
93 &compare_output($answer,&get_logfile(1));
97 &run_make_with_options($makefile, "foo.q bar.q", &get_logfile);
98 $answer = "qvar = rvar\nqvar =\n";
99 &compare_output($answer,&get_logfile(1));
103 &run_make_with_options($makefile, "foo.t bar.s", &get_logfile);
104 $answer = "qvar = qvar\nqvar =\n";
105 &compare_output($answer,&get_logfile(1));
109 # For PR/1378: Target-specific vars don't inherit correctly
111 $makefile2 = &get_tmpfile;
113 open(MAKEFILE,"> $makefile2");
114 print MAKEFILE <<'EOF';
119 baz: ; @echo $(FOO) $(BAR)
123 &run_make_with_options("$makefile2", "", &get_logfile);
124 $answer = "foo bar\n";
125 &compare_output($answer, &get_logfile(1));
128 # For PR/1380: Using += assignment in target-specific variables sometimes fails
131 $makefile3 = &get_tmpfile;
133 open(MAKEFILE,"> $makefile3");
134 print MAKEFILE <<'EOF';
137 all: one; @echo $(FOO)
147 &run_make_with_options("$makefile3", "", &get_logfile);
148 $answer = "bar baz biz boz\nbar baz\n";
149 &compare_output($answer, &get_logfile(1));
153 &run_make_with_options("$makefile3", "one", &get_logfile);
154 $answer = "bar biz boz\n";
155 &compare_output($answer, &get_logfile(1));
158 # PR/1709: Test semicolons in target-specific variable values
160 $makefile4 = &get_tmpfile;
162 open(MAKEFILE, "> $makefile4");
163 print MAKEFILE <<'EOF';
165 foo : ; @echo '$(FOO)'
169 &run_make_with_options("$makefile4", "", &get_logfile);
171 &compare_output($answer, &get_logfile(1));
174 # PR/2020: More hassles with += target-specific vars. I _really_ think
175 # I nailed it this time :-/.
177 $makefile5 = &get_tmpfile;
179 open(MAKEFILE, "> $makefile5");
180 print MAKEFILE <<'EOF';
184 COMMAND = echo $(BLAH)
189 a: COMMAND += snafu $(BLAH)
193 &run_make_with_options("$makefile5", "", &get_logfile);
194 $answer = "bar snafu bar\n";
195 &compare_output($answer, &get_logfile(1));
198 # Test double-colon rules with target-specific variable values
200 $makefile6 = &get_tmpfile;
202 open(MAKEFILE, "> $makefile6");
203 print MAKEFILE <<'EOF';
207 foo:: ; @echo $(W) $(X) $(Y) $(Z)
208 foo:: ; @echo $(W) $(X) $(Y) $(Z)
223 &run_make_with_options("$makefile6", "foo", &get_logfile);
224 $answer = "ok ok foo nopat\nok ok foo nopat\n";
225 &compare_output($answer, &get_logfile(1));
228 # Test double-colon rules with target-specific variable values and
231 &run_make_with_options("$makefile6", "bar", &get_logfile);
232 $answer = "ok ok bar nopat\nok ok bar nopat\n";
233 &compare_output($answer, &get_logfile(1));
236 # Test double-colon rules with pattern-specific variable values
238 &run_make_with_options("$makefile6", "foo PATTERN=yes", &get_logfile);
239 $answer = "ok ok foo pat\nok ok foo pat\n";
240 &compare_output($answer, &get_logfile(1));