1999-09-14 02:03:19 +00:00
# -*-perl-*-
$description = "Test target-specific variable settings.";
$details = "\
Create a makefile containing various flavors of target-specific variable
values, override and non-override, and using various variable expansion
rules, semicolon interference, etc.";
2009-05-26 01:31:40 +00:00
run_make_test('
1999-09-14 02:03:19 +00:00
export FOO = foo
export BAR = bar
one: override FOO = one
one two: ; @echo $(FOO) $(BAR)
two: BAR = two
three: ; BAR=1000
@echo $(FOO) $(BAR)
2009-05-26 01:31:40 +00:00
# Some things that shouldn not be target vars
1999-09-14 02:03:19 +00:00
funk : override
funk : override adelic
adelic override : ; echo $@
# Test per-target recursive variables
four:FOO=x
four:VAR$(FOO)=ok
2009-05-26 01:31:40 +00:00
four: ; @echo "$(FOO) $(VAR$(FOO)) $(VAR) $(VARx)"
1999-09-14 02:03:19 +00:00
five:FOO=x
five six : VAR$(FOO)=good
2009-05-26 01:31:40 +00:00
five six: ;@echo "$(FOO) $(VAR$(FOO)) $(VAR) $(VARx) $(VARfoo)"
1999-09-14 02:03:19 +00:00
# Test per-target variable inheritance
seven: eight
seven eight: ; @echo $@: $(FOO) $(BAR)
seven: BAR = seven
seven: FOO = seven
eight: BAR = eight
# Test the export keyword with per-target variables
nine: ; @echo $(FOO) $(BAR) $$FOO $$BAR
nine: FOO = wallace
2002-10-13 18:50:10 +00:00
nine-a: export BAZ = baz
nine-a: ; @echo $$BAZ
1999-09-14 02:03:19 +00:00
# Test = escaping
EQ = =
2009-05-26 01:31:40 +00:00
ten: one$(EQ)two
ten: one $(EQ) two
1999-09-14 02:03:19 +00:00
ten one$(EQ)two $(EQ):;@echo $@
.PHONY: one two three four five six seven eight nine ten $(EQ) one$(EQ)two
# Test target-specific vars with pattern/suffix rules
QVAR = qvar
RVAR = =
%.q : ; @echo $(QVAR) $(RVAR)
foo.q : RVAR += rvar
# Target-specific vars with multiple LHS pattern rules
%.r %.s %.t: ; @echo $(QVAR) $(RVAR) $(SVAR) $(TVAR)
foo.r : RVAR += rvar
foo.t : TVAR := $(QVAR)
2009-05-26 01:31:40 +00:00
',
"one two three", "one bar\nfoo two\nBAR=1000\nfoo bar\n");
1999-09-14 02:03:19 +00:00
# TEST #2
2009-05-26 01:31:40 +00:00
run_make_test(undef, "one two FOO=1 BAR=2", "one 2\n1 2\n");
1999-09-14 02:03:19 +00:00
# TEST #3
2009-05-26 01:31:40 +00:00
run_make_test(undef, "four", "x ok ok\n");
1999-09-14 02:03:19 +00:00
# TEST #4
2009-05-26 01:31:40 +00:00
run_make_test(undef, "seven", "eight: seven eight\nseven: seven seven\n");
1999-09-14 02:03:19 +00:00
# TEST #5
2009-05-26 01:31:40 +00:00
run_make_test(undef, "nine", "wallace bar wallace bar\n");
1999-09-14 02:03:19 +00:00
2002-10-13 18:50:10 +00:00
# TEST #5-a
2009-05-26 01:31:40 +00:00
run_make_test(undef, "nine-a", "baz\n");
2002-10-13 18:50:10 +00:00
1999-09-14 02:03:19 +00:00
# TEST #6
2009-05-26 01:31:40 +00:00
run_make_test(undef, "ten", "one=two\none bar\n=\nfoo two\nten\n");
1999-09-14 02:03:19 +00:00
# TEST #6
2009-05-26 01:31:40 +00:00
run_make_test(undef, "foo.q bar.q", "qvar = rvar\nqvar =\n");
1999-09-14 02:03:19 +00:00
# TEST #7
2009-05-26 01:31:40 +00:00
run_make_test(undef, "foo.t bar.s", "qvar = qvar\nqvar =\n");
1999-09-14 02:03:19 +00:00
1999-10-08 06:32:24 +00:00
# TEST #8
# For PR/1378: Target-specific vars don't inherit correctly
2009-05-26 01:31:40 +00:00
run_make_test('
1999-10-08 06:32:24 +00:00
foo: FOO = foo
bar: BAR = bar
foo: bar
bar: baz
baz: ; @echo $(FOO) $(BAR)
2009-05-26 01:31:40 +00:00
', "", "foo bar\n");
1999-10-08 06:32:24 +00:00
1999-11-17 07:33:47 +00:00
# TEST #9
# For PR/1380: Using += assignment in target-specific variables sometimes fails
2000-08-21 06:18:35 +00:00
# Also PR/1831
1999-11-17 07:33:47 +00:00
2009-05-26 01:31:40 +00:00
run_make_test('
1999-11-17 07:33:47 +00:00
.PHONY: all one
all: FOO += baz
all: one; @echo $(FOO)
FOO = bar
one: FOO += biz
2000-08-21 06:18:35 +00:00
one: FOO += boz
1999-11-17 07:33:47 +00:00
one: ; @echo $(FOO)
2009-05-26 01:31:40 +00:00
',
'', "bar baz biz boz\nbar baz\n");
1999-11-17 07:33:47 +00:00
2000-06-22 00:45:34 +00:00
# Test #10
2009-05-26 01:31:40 +00:00
run_make_test(undef, 'one', "bar biz boz\n");
1999-11-17 07:33:47 +00:00
2000-06-22 00:45:34 +00:00
# Test #11
# PR/1709: Test semicolons in target-specific variable values
2009-05-26 01:31:40 +00:00
run_make_test('
2000-06-22 00:45:34 +00:00
foo : FOO = ; ok
2009-05-26 01:31:40 +00:00
foo : ; @echo "$(FOO)"
',
'', "; ok\n");
2000-06-22 00:45:34 +00:00
2001-01-21 06:49:11 +00:00
# Test #12
# PR/2020: More hassles with += target-specific vars. I _really_ think
# I nailed it this time :-/.
2009-05-26 01:31:40 +00:00
run_make_test('
2001-01-21 06:49:11 +00:00
.PHONY: a
BLAH := foo
COMMAND = echo $(BLAH)
a: ; @$(COMMAND)
a: BLAH := bar
a: COMMAND += snafu $(BLAH)
2009-05-26 01:31:40 +00:00
',
'', "bar snafu bar\n");
2001-01-21 06:49:11 +00:00
2002-09-17 21:52:45 +00:00
# Test #13
# Test double-colon rules with target-specific variable values
2009-05-26 01:31:40 +00:00
run_make_test('
2002-09-17 21:52:45 +00:00
W = bad
X = bad
foo: W = ok
foo:: ; @echo $(W) $(X) $(Y) $(Z)
foo:: ; @echo $(W) $(X) $(Y) $(Z)
foo: X = ok
Y = foo
bar: foo
bar: Y = bar
Z = nopat
ifdef PATTERN
fo% : Z = pat
endif
2009-05-26 01:31:40 +00:00
',
'foo', "ok ok foo nopat\nok ok foo nopat\n");
2002-09-17 21:52:45 +00:00
# Test #14
# Test double-colon rules with target-specific variable values and
# inheritance
2009-05-26 01:31:40 +00:00
run_make_test(undef, 'bar', "ok ok bar nopat\nok ok bar nopat\n");
2002-09-17 21:52:45 +00:00
# Test #15
# Test double-colon rules with pattern-specific variable values
2009-05-26 01:31:40 +00:00
run_make_test(undef, 'foo PATTERN=yes', "ok ok foo pat\nok ok foo pat\n");
1999-10-08 06:32:24 +00:00
2003-01-30 07:49:17 +00:00
# Test #16
# Test target-specific variables with very long command line
# (> make default buffer length)
2009-05-26 01:31:40 +00:00
run_make_test('
2020-05-03 17:39:55 +00:00
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 )
2003-01-30 07:49:17 +00:00
deals_changed_since: ; @echo $(BUILD_OBJ)
2009-05-26 01:31:40 +00:00
',
'', "no build information\n");
2003-01-30 07:49:17 +00:00
2006-02-17 13:29:52 +00:00
# TEST #17
# Test a merge of set_lists for files, where one list is much longer
# than the other. See Savannah bug #15757.
2006-03-08 20:15:08 +00:00
mkdir('t1', 0777);
2006-02-17 13:29:52 +00:00
touch('t1/rules.mk');
run_make_test('
VPATH = t1
include rules.mk
.PHONY: all
all: foo.x
foo.x : rules.mk ; @echo MYVAR=$(MYVAR) FOOVAR=$(FOOVAR) ALLVAR=$(ALLVAR)
all: ALLVAR = xxx
foo.x: FOOVAR = bar
rules.mk : MYVAR = foo
.INTERMEDIATE: foo.x rules.mk
',
2009-05-26 01:31:40 +00:00
'-I t1', 'MYVAR= FOOVAR=bar ALLVAR=xxx');
2006-02-17 13:29:52 +00:00
rmfiles('t1/rules.mk');
rmdir('t1');
2006-03-15 03:31:30 +00:00
# TEST #18
# Test appending to a simple variable containing a "$": avoid a
# double-expansion. See Savannah bug #15913.
2009-06-04 06:30:27 +00:00
run_make_test('
VAR := $$FOO
2006-03-15 03:31:30 +00:00
foo: VAR += BAR
2009-06-04 06:30:27 +00:00
foo: ; @echo '."'".'$(VAR)'."'".'
',
2009-05-26 01:31:40 +00:00
'', '$FOO BAR');
2009-06-04 06:30:27 +00:00
# TEST #19: Override with append variables
run_make_test('
a: override FOO += f1
a: FOO += f2
a: ; @echo "$(FOO)"
',
'', "f1\n");
run_make_test(undef, 'FOO=C', "C f1\n");
2010-11-30 14:48:52 +00:00
# TEST #19: Conditional variables with command-line settings
run_make_test('
a: FOO ?= f1
a: ; @echo "$(FOO)"
',
'', "f1\n");
run_make_test(undef, 'FOO=C', "C\n");
2009-06-09 15:35:38 +00:00
# TEST #20: Check for continuation after semicolons
run_make_test(q!
2010-11-06 21:56:23 +00:00
a: A = 'hello;\
2009-06-09 15:35:38 +00:00
world'
a: ; @echo $(A)
!,
'', "hello; world\n");
2019-09-07 02:24:46 +00:00
# TEST #21: SV-56834 Ensure setting PATH in a target var works properly
2019-09-15 20:39:22 +00:00
my $sname = "foobar$scriptsuffix";
2019-09-07 02:24:46 +00:00
mkdir('sd', 0775);
2019-09-15 20:39:22 +00:00
create_file("sd/$sname", "exit 0\n");
chmod 0755, "sd/$sname";
2019-09-07 02:24:46 +00:00
2019-09-15 20:39:22 +00:00
run_make_test(qq!
2019-09-07 02:24:46 +00:00
all: PATH := sd
2019-09-15 20:39:22 +00:00
all: ; $sname >/dev/null
2019-09-07 02:24:46 +00:00
!,
2019-09-15 20:39:22 +00:00
'', "$sname >/dev/null\n");
2019-09-07 02:24:46 +00:00
# Don't use the general PATH if not found on the target path
2020-04-01 05:58:33 +00:00
$ENV{PATH} = "$ENV{PATH}:sd";
2019-09-07 02:24:46 +00:00
2019-09-15 20:39:22 +00:00
run_make_test(qq!
2019-09-07 02:24:46 +00:00
all: PATH := ..
2019-09-15 20:39:22 +00:00
all: ; $sname
2019-09-07 02:24:46 +00:00
!,
2019-09-22 21:02:57 +00:00
'', "$sname\n#MAKE#: $sname: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:3: all] Error 127", 512);
2019-09-07 02:24:46 +00:00
2019-09-15 20:39:22 +00:00
unlink("sd/$sname");
2019-09-07 02:24:46 +00:00
rmdir ('sd');
2009-05-26 01:31:40 +00:00
# TEST #19: Test define/endef variables as target-specific vars
# run_make_test('
# define b
# @echo global
# endef
# a: define b
# @echo local
# endef
# a: ; $(b)
# ',
# '', "local\n");
2006-03-15 03:31:30 +00:00
1999-09-14 02:03:19 +00:00
1;
2017-04-17 19:37:57 +00:00
### Local Variables:
### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
### End: