2013-05-13 06:17:29 +00:00
|
|
|
# -*-perl-*-
|
2009-10-03 20:08:20 +00:00
|
|
|
|
|
|
|
$description = "Test proper behavior of MAKEFLAGS";
|
|
|
|
|
|
|
|
$details = "DETAILS";
|
|
|
|
|
|
|
|
# Normal flags aren't prefixed with "-"
|
|
|
|
run_make_test(q!
|
2022-07-24 18:14:32 +00:00
|
|
|
all: ; @echo /$(MAKEFLAGS)/
|
2009-10-03 20:08:20 +00:00
|
|
|
!,
|
2022-07-24 18:14:32 +00:00
|
|
|
'-e -r -R', '/erR/');
|
2009-10-03 20:08:20 +00:00
|
|
|
|
|
|
|
# Long arguments mean everything is prefixed with "-"
|
|
|
|
run_make_test(q!
|
2022-07-24 18:14:32 +00:00
|
|
|
all: ; @echo /$(MAKEFLAGS)/
|
2009-10-03 20:08:20 +00:00
|
|
|
!,
|
2020-12-05 21:25:12 +00:00
|
|
|
'--no-print-directory -e -r -R --trace', "#MAKEFILE#:2: update target 'all' due to: target does not exist
|
2022-07-24 18:14:32 +00:00
|
|
|
echo /erR --trace --no-print-directory/
|
|
|
|
/erR --trace --no-print-directory/");
|
2009-10-03 20:08:20 +00:00
|
|
|
|
|
|
|
|
2013-05-13 06:17:29 +00:00
|
|
|
# Recursive invocations of make should accumulate MAKEFLAGS values.
|
|
|
|
# Savannah bug #2216
|
|
|
|
run_make_test(q!
|
2009-10-03 20:08:20 +00:00
|
|
|
MSG = Fails
|
2020-12-05 21:25:12 +00:00
|
|
|
.RECIPEPREFIX = >
|
2009-10-03 20:08:20 +00:00
|
|
|
all:
|
2020-12-05 21:25:12 +00:00
|
|
|
> @echo '$@: MAKEFLAGS=$(MAKEFLAGS)'
|
|
|
|
> @MSG=Works $(MAKE) -e -f #MAKEFILE# jump
|
2009-10-03 20:08:20 +00:00
|
|
|
jump:
|
2020-12-05 21:25:12 +00:00
|
|
|
> @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)'
|
|
|
|
> @$(MAKE) -f #MAKEFILE# print
|
2009-10-03 20:08:20 +00:00
|
|
|
print:
|
2020-12-05 21:25:12 +00:00
|
|
|
> @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)'
|
2009-10-03 20:08:20 +00:00
|
|
|
.PHONY: all jump print
|
|
|
|
!,
|
|
|
|
'--no-print-directory',
|
2013-05-22 11:51:46 +00:00
|
|
|
'all: MAKEFLAGS= --no-print-directory
|
|
|
|
jump Works: MAKEFLAGS=e --no-print-directory
|
|
|
|
print Works: MAKEFLAGS=e --no-print-directory');
|
2009-10-03 20:08:20 +00:00
|
|
|
|
2021-09-05 21:11:44 +00:00
|
|
|
# Ensure MAKEFLAGS updates are handled immediately rather than later
|
|
|
|
|
|
|
|
mkdir('foo', 0777);
|
|
|
|
mkdir('bar', 0777);
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
$(info MAKEFLAGS=$(MAKEFLAGS))
|
|
|
|
$(info INCLUDE_DIRS=$(.INCLUDE_DIRS))
|
|
|
|
MAKEFLAGS += -Ibar
|
|
|
|
$(info MAKEFLAGS=$(MAKEFLAGS))
|
|
|
|
$(info INCLUDE_DIRS=$(.INCLUDE_DIRS))
|
|
|
|
.PHONY: all
|
|
|
|
all: ; @echo 'MAKEFLAGS=$(MAKEFLAGS)' "\$$MAKEFLAGS=$$MAKEFLAGS"
|
|
|
|
!,
|
|
|
|
'-I- -Ifoo', 'MAKEFLAGS= -I- -Ifoo
|
|
|
|
INCLUDE_DIRS=foo
|
|
|
|
MAKEFLAGS= -I- -Ifoo -Ibar
|
|
|
|
INCLUDE_DIRS=foo bar
|
|
|
|
MAKEFLAGS= -I- -Ifoo -Ibar $MAKEFLAGS= -I- -Ifoo -Ibar');
|
|
|
|
|
|
|
|
rmdir('foo');
|
|
|
|
rmdir('bar');
|
|
|
|
|
2022-06-18 21:14:46 +00:00
|
|
|
# Test that command line switches are all present in MAKEFLAGS.
|
|
|
|
# sv 62514.
|
|
|
|
my @opts;
|
2022-11-27 19:09:17 +00:00
|
|
|
my @flavors;
|
2022-06-18 21:14:46 +00:00
|
|
|
|
|
|
|
# Simple flags.
|
|
|
|
@opts = ('i', 'k', 'n', 'q', 'r', 's', 'w', 'd');
|
|
|
|
exists $FEATURES{'check-symlink'} and push @opts, 'L';
|
2022-11-27 19:09:17 +00:00
|
|
|
@flavors = ('=', ':=', ':::=', '+=-');
|
2022-06-18 21:14:46 +00:00
|
|
|
|
2022-11-27 19:09:17 +00:00
|
|
|
for my $fl (@flavors) {
|
2022-06-18 21:14:46 +00:00
|
|
|
for my $opt (@opts) {
|
2022-11-27 19:09:17 +00:00
|
|
|
run_make_test("
|
|
|
|
MAKEFLAGS${fl}B
|
|
|
|
all:; \$(info makeflags='\$(MAKEFLAGS)')
|
|
|
|
", "-$opt", "/makeflags='B$opt'/");
|
|
|
|
}
|
2022-06-18 21:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Switches which carry arguments.
|
|
|
|
@opts = (' -I/tmp', ' -Onone', ' --debug=b', ' -l2.5');
|
2022-11-27 19:09:17 +00:00
|
|
|
for my $fl (@flavors) {
|
2022-06-18 21:14:46 +00:00
|
|
|
for my $opt (@opts) {
|
2022-11-27 19:09:17 +00:00
|
|
|
run_make_test("
|
|
|
|
MAKEFLAGS${fl}B
|
|
|
|
all:; \$(info makeflags='\$(MAKEFLAGS)')
|
|
|
|
", "$opt", "/makeflags='B$opt'/");
|
|
|
|
}
|
2022-06-18 21:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Long options which take no arguments.
|
|
|
|
# sv 62514.
|
|
|
|
@opts = (' --no-print-directory', ' --warn-undefined-variables', ' --trace');
|
2022-11-27 19:09:17 +00:00
|
|
|
for my $fl (@flavors) {
|
2022-06-18 21:14:46 +00:00
|
|
|
for my $opt (@opts) {
|
2022-11-27 19:09:17 +00:00
|
|
|
run_make_test("
|
|
|
|
MAKEFLAGS${fl}B
|
|
|
|
all:; \$(info makeflags='\$(MAKEFLAGS)')
|
|
|
|
", "$opt", "/makeflags='B$opt'/");
|
|
|
|
}
|
2022-06-18 21:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Test that make filters out duplicates.
|
|
|
|
# Each option is specified in the makefile, env and on the command line.
|
|
|
|
@opts = (' -I/tmp', ' -Onone', ' --debug=b', ' -l2.5');
|
2022-11-27 19:09:17 +00:00
|
|
|
for my $fl (@flavors) {
|
2022-06-18 21:14:46 +00:00
|
|
|
for my $opt (@opts) {
|
2022-11-27 19:09:17 +00:00
|
|
|
$ENV{'MAKEFLAGS'} = $opt;
|
2022-06-18 21:14:46 +00:00
|
|
|
run_make_test("
|
2022-11-27 19:09:17 +00:00
|
|
|
MAKEFLAGS${fl}B $opt
|
2022-06-18 21:14:46 +00:00
|
|
|
all:; \$(info makeflags='\$(MAKEFLAGS)')
|
|
|
|
", "$opt", "/makeflags='B$opt'/");
|
|
|
|
}
|
2022-11-27 19:09:17 +00:00
|
|
|
}
|
2022-06-18 21:14:46 +00:00
|
|
|
|
|
|
|
# Test that make filters out duplicates.
|
|
|
|
# Each option is specified in the makefile, env and on the command line.
|
|
|
|
# decode_switches reallocates when the number of parameters in sl->list exceeds 5.
|
|
|
|
# This test exercises the realloc branch.
|
2022-11-27 19:09:17 +00:00
|
|
|
for my $fl (@flavors) {
|
2022-06-18 21:14:46 +00:00
|
|
|
$ENV{'MAKEFLAGS'} = '-I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6 -I2 -I2';
|
2022-11-27 19:09:17 +00:00
|
|
|
run_make_test("
|
|
|
|
MAKEFLAGS${fl}B -I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6 -I2 -I2
|
|
|
|
all:; \$(info makeflags='\$(MAKEFLAGS)')
|
|
|
|
",
|
2022-06-18 21:14:46 +00:00
|
|
|
'-I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6',
|
|
|
|
"/makeflags='B -I1 -I2 -I3 -I4 -I5 -I6 -l2.5 -Onone --debug=b'/");
|
2022-11-27 19:09:17 +00:00
|
|
|
}
|
2022-06-18 21:14:46 +00:00
|
|
|
|
|
|
|
# A mix of multiple flags from env, the makefile and command line.
|
|
|
|
# Skip -L since it's not available everywhere
|
2022-11-27 19:09:17 +00:00
|
|
|
for my $fl (@flavors) {
|
2022-06-18 21:14:46 +00:00
|
|
|
$ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn-undefined-variables --trace';
|
2022-11-27 19:09:17 +00:00
|
|
|
run_make_test("
|
|
|
|
MAKEFLAGS${fl}iknqrswd -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5
|
|
|
|
all:; \$(info makeflags='\$(MAKEFLAGS)')
|
|
|
|
",
|
2022-06-18 21:14:46 +00:00
|
|
|
'-Onone -l2.5 -l2.5 -Onone -I/tmp -iknqrswd -i -n -s -k -I/tmp',
|
|
|
|
"/makeflags='Bdiknqrsw -I/tmp -l2.5 -Onone --trace --warn-undefined-variables'/");
|
2022-11-27 19:09:17 +00:00
|
|
|
}
|
2022-06-18 21:14:46 +00:00
|
|
|
|
2022-11-27 19:09:17 +00:00
|
|
|
# Verify MAKEFLAGS are all available to shell function at parse time.
|
|
|
|
for my $fl (@flavors) {
|
|
|
|
my $answer = 'Biknqrs -I/tmp -l2.5 -Onone --no-print-directory --warn-undefined-variables';
|
2022-07-16 23:43:34 +00:00
|
|
|
$ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn-undefined-variables';
|
2022-11-27 19:09:17 +00:00
|
|
|
run_make_test("
|
|
|
|
MAKEFLAGS${fl}iknqrsw -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5 --no-print-directory
|
|
|
|
\$(info at parse time '\$(MAKEFLAGS)')
|
|
|
|
XX := \$(shell echo \"\$\$MAKEFLAGS\")
|
|
|
|
all:; \$(info at build time makeflags='\$(XX)')
|
|
|
|
",
|
|
|
|
'-Onone -l2.5 -l2.5 -Onone -I/tmp -iknqrs -i -n -s -k -I/tmp',
|
|
|
|
"at parse time '$answer'
|
|
|
|
at build time makeflags='$answer'");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify MAKEFLAGS and command line definitions are all available to shell function at parse time.
|
|
|
|
for my $fl (@flavors) {
|
|
|
|
$ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn-undefined-variables';
|
|
|
|
my $answer = 'Biknqrs -I/tmp -l2.5 -Onone --no-print-directory --warn-undefined-variables -- hello=world';
|
|
|
|
run_make_test("
|
|
|
|
MAKEFLAGS${fl}iknqrsw -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5 --no-print-directory
|
|
|
|
\$(info at parse time '\$(MAKEFLAGS)')
|
|
|
|
XX := \$(shell echo \"\$\$MAKEFLAGS\")
|
|
|
|
all:; \$(info at build time makeflags='\$(XX)')
|
|
|
|
",
|
|
|
|
'-Onone -l2.5 -l2.5 -Onone -I/tmp -iknqrs -i -n -s -k -I/tmp hello=world',
|
|
|
|
"at parse time '$answer'
|
|
|
|
at build time makeflags='$answer'");
|
|
|
|
}
|
2022-07-16 23:43:34 +00:00
|
|
|
|
2022-07-24 18:14:32 +00:00
|
|
|
# Verify that command line arguments are included in MAKEFLAGS
|
|
|
|
run_make_test(q!
|
|
|
|
all: ; @echo $(MAKEFLAGS)
|
|
|
|
!,
|
|
|
|
'-e FOO=bar -r -R', 'erR -- FOO=bar');
|
|
|
|
|
|
|
|
# Long arguments mean everything is prefixed with "-"
|
|
|
|
run_make_test(q!
|
|
|
|
all: ; @echo /$(MAKEFLAGS)/
|
|
|
|
!,
|
|
|
|
'--no-print-directory -e -r -R --trace FOO=bar',
|
|
|
|
"#MAKEFILE#:2: update target 'all' due to: target does not exist
|
|
|
|
echo /erR --trace --no-print-directory -- FOO=bar/
|
|
|
|
/erR --trace --no-print-directory -- FOO=bar/");
|
|
|
|
|
|
|
|
|
2022-11-27 19:09:17 +00:00
|
|
|
# sv 63347.
|
|
|
|
# Verify that command line arguments are included in MAKEFLAGS
|
|
|
|
# when makefiles are parsed.
|
|
|
|
my $answer = 'erR -- hello:=world FOO=bar';
|
|
|
|
run_make_test(q!
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
all:; $(info $(MAKEFLAGS))
|
|
|
|
!, '-e FOO=bar -r -R hello:=world',
|
|
|
|
"$answer
|
|
|
|
$answer
|
|
|
|
#MAKE#: 'all' is up to date.\n");
|
|
|
|
|
|
|
|
# sv 63347.
|
|
|
|
# Same as above, with makefile setting the value of the same variables as
|
|
|
|
# defined on the cli.
|
|
|
|
my $answer = 'erR -- hello:=world FOO=bar';
|
|
|
|
run_make_test(q!
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
FOO=moon
|
|
|
|
hello:=moon
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
all:; $(info $(MAKEFLAGS))
|
|
|
|
!, '-e FOO=bar -r -R hello:=world',
|
|
|
|
"$answer
|
|
|
|
$answer
|
|
|
|
$answer
|
|
|
|
#MAKE#: 'all' is up to date.\n");
|
|
|
|
|
|
|
|
# sv 63347.
|
|
|
|
# Same as above, with makefile overriding the value of cli definition.
|
|
|
|
my $answer = 'erR -- hello:=world FOO=bar';
|
|
|
|
run_make_test(q!
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
override FOO=moon
|
|
|
|
override hello:=moon
|
|
|
|
export hello
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
all:; $(info $(MAKEFLAGS))
|
|
|
|
!, '-e FOO=bar -r -R hello:=world',
|
|
|
|
"$answer
|
|
|
|
$answer
|
|
|
|
$answer
|
|
|
|
#MAKE#: 'all' is up to date.\n");
|
|
|
|
|
|
|
|
# Same as above, and makefile overrides the value of cli definition.
|
|
|
|
# resets MAKEOVERRIDES.
|
|
|
|
my $answer = 'rR -- hello:=world FOO=bar';
|
|
|
|
run_make_test(q!
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
override FOO=moon
|
|
|
|
override hello:=moon
|
|
|
|
export hello
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
MAKEOVERRIDES=
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
all:; $(info $(MAKEFLAGS))
|
|
|
|
!, 'FOO=bar -r -R hello:=world',
|
|
|
|
"$answer
|
|
|
|
$answer
|
|
|
|
rR -- \nrR
|
|
|
|
#MAKE#: 'all' is up to date.\n");
|
|
|
|
|
|
|
|
# sv 63347.
|
|
|
|
# MAKEFLAGS set is env and makefile sets MAKEFLAGS and there is a command
|
|
|
|
# line definition.
|
|
|
|
my $answer = ' -- bye=moon hello=world';
|
|
|
|
$ENV{'MAKEFLAGS'} = 'hello=world';
|
|
|
|
run_make_test(q!
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
all:; $(info $(MAKEFLAGS))
|
|
|
|
!, 'bye=moon',
|
|
|
|
" -- bye=moon hello=world
|
|
|
|
-- bye=moon hello=world
|
|
|
|
#MAKE#: 'all' is up to date.\n");
|
|
|
|
|
|
|
|
# sv 63347.
|
|
|
|
# Conditional assignment and MAKEFLAGS.
|
|
|
|
my $answer = 'B -- bye=moon hello=world';
|
|
|
|
$ENV{'MAKEFLAGS'} = 'hello=world';
|
|
|
|
run_make_test(q!
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
MAKEFLAGS?=-k
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
all:; $(info $(MAKEFLAGS))
|
|
|
|
!, '-B bye=moon',
|
|
|
|
"$answer
|
|
|
|
$answer
|
|
|
|
$answer
|
|
|
|
#MAKE#: 'all' is up to date.\n");
|
|
|
|
|
|
|
|
# sv 63347.
|
|
|
|
# MAKEFLAGS set is env and makefile sets MAKEFLAGS and there is a command
|
|
|
|
# line definition.
|
|
|
|
for my $fl (@flavors) {
|
|
|
|
my $answer = ' -- bye=moon hello=world';
|
|
|
|
$ENV{'MAKEFLAGS'} = 'hello=world';
|
|
|
|
run_make_test("
|
|
|
|
\$(info \$(MAKEFLAGS))
|
|
|
|
MAKEFLAGS${fl}R
|
|
|
|
\$(info \$(MAKEFLAGS))
|
|
|
|
all:; \$(info \$(MAKEFLAGS))
|
|
|
|
", 'bye=moon',
|
|
|
|
"$answer
|
|
|
|
R$answer
|
|
|
|
rR$answer
|
|
|
|
#MAKE#: 'all' is up to date.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
# sv 63347.
|
|
|
|
# Test changes introduced by makefiles to MAKEFLAGS.
|
|
|
|
for my $fl (@flavors) {
|
|
|
|
my $answer = 'rR --no-print-directory -- hello:=world FOO=bar';
|
|
|
|
run_make_test(q!
|
|
|
|
MAKEFLAGS+=--no-print-directory
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
MAKEFLAGS+=-k
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
all:; $(info $(MAKEFLAGS))
|
|
|
|
!, 'FOO=bar -r -R hello:=world',
|
|
|
|
"$answer
|
|
|
|
k$answer
|
|
|
|
k$answer
|
|
|
|
#MAKE#: 'all' is up to date.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
# sv 63347.
|
|
|
|
# Test changes introduced by makefiles to MAKEFLAGS.
|
|
|
|
# Same as above, but with -e.
|
|
|
|
for my $fl (@flavors) {
|
|
|
|
my $answer = 'erR -- hello:=world FOO=bar';
|
|
|
|
run_make_test(q!
|
|
|
|
MAKEFLAGS+=--no-print-directory
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
MAKEFLAGS+=-k
|
|
|
|
$(info $(MAKEFLAGS))
|
|
|
|
all:; $(info $(MAKEFLAGS))
|
|
|
|
!, '-e FOO=bar -r -R hello:=world',
|
|
|
|
"$answer
|
|
|
|
$answer
|
|
|
|
$answer
|
|
|
|
#MAKE#: 'all' is up to date.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
mkdir('bye', 0777);
|
|
|
|
|
|
|
|
create_file('bye/makefile',
|
|
|
|
'hello=moon
|
|
|
|
all:; $(info $(hello))');
|
|
|
|
|
|
|
|
# sv 63347.
|
|
|
|
# Test that a cli definition takes precendence over a definition set in
|
|
|
|
# submake.
|
|
|
|
run_make_test(q!
|
|
|
|
v:=$(shell $(MAKE) -C bye --no-print-directory)
|
|
|
|
all: ; $(info $(v))
|
|
|
|
!, 'hello=world', "world #MAKE#[1]: 'all' is up to date.\n#MAKE#: 'all' is up to date.");
|
|
|
|
|
|
|
|
# Same as above with the shell assignment operator.
|
|
|
|
run_make_test(q!
|
|
|
|
v \!= $(MAKE) -C bye --no-print-directory
|
|
|
|
all: ; $(info $(v))
|
|
|
|
!, 'hello=world', "world #MAKE#[1]: 'all' is up to date.\n#MAKE#: 'all' is up to date.");
|
|
|
|
|
|
|
|
unlink('bye/makefile');
|
|
|
|
rmdir('bye');
|
|
|
|
|
|
|
|
# sv 63347
|
|
|
|
# Invalid command line variable definition.
|
|
|
|
run_make_test(q!
|
|
|
|
all:; $(info $(hello))
|
|
|
|
!, 'hello=\'$(world\'', "#MAKEFILE#:2: *** unterminated variable reference. Stop.\n", 512);
|
|
|
|
|
|
|
|
# sv 63347
|
|
|
|
# An unused invalid command line variable definition is ignored.
|
|
|
|
run_make_test(q!
|
|
|
|
all:; $(info good)
|
|
|
|
!, 'hello=\'$(world\'', "good\n#MAKE#: 'all' is up to date.\n");
|
|
|
|
|
|
|
|
|
2009-10-03 20:08:20 +00:00
|
|
|
1;
|