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
40 nine-a: export BAZ = baz
46 ten one$(EQ)two $(EQ):;@echo $@
47 .PHONY: one two three four five six seven eight nine ten $(EQ) one$(EQ)two
48 # Test target-specific vars with pattern/suffix rules
51 %.q : ; @echo $(QVAR) $(RVAR)
53 # Target-specific vars with multiple LHS pattern rules
54 %.r %.s %.t: ; @echo $(QVAR) $(RVAR) $(SVAR) $(TVAR)
56 foo.t : TVAR := $(QVAR)
63 &run_make_with_options($makefile, "one two three", &get_logfile);
64 $answer = "one bar\nfoo two\nBAR=1000\nfoo bar\n";
65 &compare_output($answer,&get_logfile(1));
69 &run_make_with_options($makefile, "one two FOO=1 BAR=2", &get_logfile);
70 $answer = "one 2\n1 2\n";
71 &compare_output($answer,&get_logfile(1));
75 &run_make_with_options($makefile, "four", &get_logfile);
76 $answer = "x ok ok\n";
77 &compare_output($answer,&get_logfile(1));
81 &run_make_with_options($makefile, "seven", &get_logfile);
82 $answer = "eight: seven eight\nseven: seven seven\n";
83 &compare_output($answer,&get_logfile(1));
87 &run_make_with_options($makefile, "nine", &get_logfile);
88 $answer = "wallace bar wallace bar\n";
89 &compare_output($answer,&get_logfile(1));
93 &run_make_with_options($makefile, "nine-a", &get_logfile);
95 &compare_output($answer,&get_logfile(1));
99 &run_make_with_options($makefile, "ten", &get_logfile);
100 $answer = "one=two\none bar\n=\nfoo two\nten\n";
101 &compare_output($answer,&get_logfile(1));
105 &run_make_with_options($makefile, "foo.q bar.q", &get_logfile);
106 $answer = "qvar = rvar\nqvar =\n";
107 &compare_output($answer,&get_logfile(1));
111 &run_make_with_options($makefile, "foo.t bar.s", &get_logfile);
112 $answer = "qvar = qvar\nqvar =\n";
113 &compare_output($answer,&get_logfile(1));
117 # For PR/1378: Target-specific vars don't inherit correctly
119 $makefile2 = &get_tmpfile;
121 open(MAKEFILE,"> $makefile2");
122 print MAKEFILE <<'EOF';
127 baz: ; @echo $(FOO) $(BAR)
131 &run_make_with_options("$makefile2", "", &get_logfile);
132 $answer = "foo bar\n";
133 &compare_output($answer, &get_logfile(1));
136 # For PR/1380: Using += assignment in target-specific variables sometimes fails
139 $makefile3 = &get_tmpfile;
141 open(MAKEFILE,"> $makefile3");
142 print MAKEFILE <<'EOF';
145 all: one; @echo $(FOO)
155 &run_make_with_options("$makefile3", "", &get_logfile);
156 $answer = "bar baz biz boz\nbar baz\n";
157 &compare_output($answer, &get_logfile(1));
161 &run_make_with_options("$makefile3", "one", &get_logfile);
162 $answer = "bar biz boz\n";
163 &compare_output($answer, &get_logfile(1));
166 # PR/1709: Test semicolons in target-specific variable values
168 $makefile4 = &get_tmpfile;
170 open(MAKEFILE, "> $makefile4");
171 print MAKEFILE <<'EOF';
173 foo : ; @echo '$(FOO)'
177 &run_make_with_options("$makefile4", "", &get_logfile);
179 &compare_output($answer, &get_logfile(1));
182 # PR/2020: More hassles with += target-specific vars. I _really_ think
183 # I nailed it this time :-/.
185 $makefile5 = &get_tmpfile;
187 open(MAKEFILE, "> $makefile5");
188 print MAKEFILE <<'EOF';
192 COMMAND = echo $(BLAH)
197 a: COMMAND += snafu $(BLAH)
201 &run_make_with_options("$makefile5", "", &get_logfile);
202 $answer = "bar snafu bar\n";
203 &compare_output($answer, &get_logfile(1));
206 # Test double-colon rules with target-specific variable values
208 $makefile6 = &get_tmpfile;
210 open(MAKEFILE, "> $makefile6");
211 print MAKEFILE <<'EOF';
215 foo:: ; @echo $(W) $(X) $(Y) $(Z)
216 foo:: ; @echo $(W) $(X) $(Y) $(Z)
231 &run_make_with_options("$makefile6", "foo", &get_logfile);
232 $answer = "ok ok foo nopat\nok ok foo nopat\n";
233 &compare_output($answer, &get_logfile(1));
236 # Test double-colon rules with target-specific variable values and
239 &run_make_with_options("$makefile6", "bar", &get_logfile);
240 $answer = "ok ok bar nopat\nok ok bar nopat\n";
241 &compare_output($answer, &get_logfile(1));
244 # Test double-colon rules with pattern-specific variable values
246 &run_make_with_options("$makefile6", "foo PATTERN=yes", &get_logfile);
247 $answer = "ok ok foo pat\nok ok foo pat\n";
248 &compare_output($answer, &get_logfile(1));
252 # Test target-specific variables with very long command line
253 # (> make default buffer length)
255 $makefile7 = &get_tmpfile;
257 open(MAKEFILE, "> $makefile7");
258 print MAKEFILE <<'EOF';
259 base_metals_fmd_reports.sun5 base_metals_fmd_reports CreateRealPositions CreateMarginFunds deals_changed_since : BUILD_OBJ=$(shell if [ -f "build_information.generate" ]; then echo "$(OBJ_DIR)/build_information.o"; else echo "no build information"; fi )
261 deals_changed_since: ; @echo $(BUILD_OBJ)
266 &run_make_with_options("$makefile7", '', &get_logfile);
267 $answer = "no build information\n";
268 &compare_output($answer, &get_logfile(1));