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.";
12 one: override FOO = one
13 one two: ; @echo $(FOO) $(BAR)
18 # Some things that shouldn not be target vars
20 funk : override adelic
21 adelic override : ; echo $@
22 # Test per-target recursive variables
25 four: ; @echo "$(FOO) $(VAR$(FOO)) $(VAR) $(VARx)"
27 five six : VAR$(FOO)=good
28 five six: ;@echo "$(FOO) $(VAR$(FOO)) $(VAR) $(VARx) $(VARfoo)"
29 # Test per-target variable inheritance
31 seven eight: ; @echo $@: $(FOO) $(BAR)
35 # Test the export keyword with per-target variables
36 nine: ; @echo $(FOO) $(BAR) $$FOO $$BAR
38 nine-a: export BAZ = baz
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)
56 "one two three", "one bar\nfoo two\nBAR=1000\nfoo bar\n");
60 run_make_test(undef, "one two FOO=1 BAR=2", "one 2\n1 2\n");
64 run_make_test(undef, "four", "x ok ok\n");
68 run_make_test(undef, "seven", "eight: seven eight\nseven: seven seven\n");
72 run_make_test(undef, "nine", "wallace bar wallace bar\n");
76 run_make_test(undef, "nine-a", "baz\n");
80 run_make_test(undef, "ten", "one=two\none bar\n=\nfoo two\nten\n");
84 run_make_test(undef, "foo.q bar.q", "qvar = rvar\nqvar =\n");
88 run_make_test(undef, "foo.t bar.s", "qvar = qvar\nqvar =\n");
91 # For PR/1378: Target-specific vars don't inherit correctly
98 baz: ; @echo $(FOO) $(BAR)
102 # For PR/1380: Using += assignment in target-specific variables sometimes fails
108 all: one; @echo $(FOO)
116 '', "bar baz biz boz\nbar baz\n");
120 run_make_test(undef, 'one', "bar biz boz\n");
123 # PR/1709: Test semicolons in target-specific variable values
127 foo : ; @echo "$(FOO)"
132 # PR/2020: More hassles with += target-specific vars. I _really_ think
133 # I nailed it this time :-/.
139 COMMAND = echo $(BLAH)
144 a: COMMAND += snafu $(BLAH)
146 '', "bar snafu bar\n");
149 # Test double-colon rules with target-specific variable values
155 foo:: ; @echo $(W) $(X) $(Y) $(Z)
156 foo:: ; @echo $(W) $(X) $(Y) $(Z)
168 'foo', "ok ok foo nopat\nok ok foo nopat\n");
171 # Test double-colon rules with target-specific variable values and
174 run_make_test(undef, 'bar', "ok ok bar nopat\nok ok bar nopat\n");
177 # Test double-colon rules with pattern-specific variable values
179 run_make_test(undef, 'foo PATTERN=yes', "ok ok foo pat\nok ok foo pat\n");
182 # Test target-specific variables with very long command line
183 # (> make default buffer length)
186 base_metals_fmd_reports.sun5 base_metals_fmd_reports CreateRealPositions CreateMarginFunds deals_changed_since : BUILD_OBJ=$(shell if test -f "build_information.generate" ; then echo "$(OBJ_DIR)/build_information.o"; else echo "no build information"; fi )
188 deals_changed_since: ; @echo $(BUILD_OBJ)
190 '', "no build information\n");
194 # Test a merge of set_lists for files, where one list is much longer
195 # than the other. See Savannah bug #15757.
198 touch('t1/rules.mk');
205 foo.x : rules.mk ; @echo MYVAR=$(MYVAR) FOOVAR=$(FOOVAR) ALLVAR=$(ALLVAR)
208 rules.mk : MYVAR = foo
209 .INTERMEDIATE: foo.x rules.mk
211 '-I t1', 'MYVAR= FOOVAR=bar ALLVAR=xxx');
213 rmfiles('t1/rules.mk');
218 # Test appending to a simple variable containing a "$": avoid a
219 # double-expansion. See Savannah bug #15913.
224 foo: ; @echo '."'".'$(VAR)'."'".'
228 # TEST #19: Override with append variables
231 a: override FOO += f1
237 run_make_test(undef, 'FOO=C', "C f1\n");
239 # TEST #19: Conditional variables with command-line settings
247 run_make_test(undef, 'FOO=C', "C\n");
249 # TEST #20: Check for continuation after semicolons
256 '', "hello; world\n");
258 # TEST #21: SV-56834 Ensure setting PATH in a target var works properly
259 my $sname = "foobar$scriptsuffix";
262 create_file("sd/$sname", "exit 0\n");
263 chmod 0755, "sd/$sname";
267 all: ; $sname >/dev/null
269 '', "$sname >/dev/null\n");
271 # Don't use the general PATH if not found on the target path
273 $ENV{PATH} = "$ENV{PATH}:sd";
276 if ($port_type eq 'W32') {
278 $erstr = "'$sname' is not recognized as an internal or external command,\noperable program or batch file.";
281 $erstr = "#MAKE#: $sname: $ERR_no_such_file";
288 '', "$sname\n$erstr\n#MAKE#: *** [#MAKEFILE#:3: all] Error $ernum", 512);
293 # SV 59230: Conditional (non-)assignment of target-specific variables should
294 # preserve export settings.
296 $ENV{hello} = 'moon';
298 all:; @echo hello=$$hello
303 # SV 59230: Assignment of a global variable should not affect export of a
304 # target specific variable.
306 $ENV{hello} = "moon";
308 all:; @echo hello=$$hello
314 # Support target-specific unexport
316 $ENV{hello} = "moon";
320 base exp: ; @echo hello=$$hello
321 exp: export hello=world
323 '', "hello=\nhello=world\n");
325 $ENV{hello} = "moon";
329 base exp: ; @echo hello=$$hello
330 exp: unexport hello=world
332 '', "hello=sun\nhello=\n");
335 all:; @echo hello=$$hello
341 $ENV{hello} = "moon";
343 all:; @echo hello=$$hello
345 dummy: unexport hello=world
353 ifeq ($(midexport),export)
354 mid: export hello=mid
355 else ifeq ($(midexport),unexport)
356 mid: unexport hello=mid
361 ifeq ($(baseexport),export)
362 base: export hello=base
363 else ifeq ($(baseexport),unexport)
364 base: unexport hello=base
369 all mid base:; @echo $@ make=$(hello) shell=$$hello
371 '', "base make=base shell=\nmid make=mid shell=\nall make= shell=\n");
373 # Test base settings with env var
374 $ENV{hello} = "environ";
376 '', "base make=base shell=base\nmid make=mid shell=mid\nall make=environ shell=environ\n");
378 $ENV{hello} = "environ";
380 'baseexport=export', "base make=base shell=base\nmid make=mid shell=mid\nall make=environ shell=environ\n");
382 $ENV{hello} = "environ";
384 'baseexport=unexport', "base make=base shell=\nmid make=mid shell=mid\nall make=environ shell=environ\n");
386 # Test mid settings with env var
387 $ENV{hello} = "environ";
389 'midexport=export', "base make=base shell=base\nmid make=mid shell=mid\nall make=environ shell=environ\n");
391 $ENV{hello} = "environ";
393 'midexport=export baseexport=unexport', "base make=base shell=\nmid make=mid shell=mid\nall make=environ shell=environ\n");
395 $ENV{hello} = "environ";
397 'midexport=unexport', "base make=base shell=\nmid make=mid shell=\nall make=environ shell=environ\n");
399 $ENV{hello} = "environ";
401 'midexport=unexport baseexport=export', "base make=base shell=base\nmid make=mid shell=\nall make=environ shell=environ\n");
403 # Test base settings without env var
405 'baseexport=export', "base make=base shell=base\nmid make=mid shell=\nall make= shell=\n");
408 'baseexport=unexport', "base make=base shell=\nmid make=mid shell=\nall make= shell=\n");
410 # Test mid settings with env var
412 'midexport=export', "base make=base shell=base\nmid make=mid shell=mid\nall make= shell=\n");
415 'midexport=export baseexport=unexport', "base make=base shell=\nmid make=mid shell=mid\nall make= shell=\n");
418 'midexport=unexport', "base make=base shell=\nmid make=mid shell=\nall make= shell=\n");
421 'midexport=unexport baseexport=export', "base make=base shell=base\nmid make=mid shell=\nall make= shell=\n");
425 # TEST #19: Test define/endef variables as target-specific vars