diff options
Diffstat (limited to 'tests/scripts/variables')
-rw-r--r-- | tests/scripts/variables/GNUMAKEFLAGS | 22 | ||||
-rw-r--r-- | tests/scripts/variables/INCLUDE_DIRS | 70 | ||||
-rw-r--r-- | tests/scripts/variables/MAKEFLAGS | 143 | ||||
-rw-r--r-- | tests/scripts/variables/MAKE_RESTARTS | 12 | ||||
-rw-r--r-- | tests/scripts/variables/SHELL | 20 | ||||
-rw-r--r-- | tests/scripts/variables/automatic | 26 | ||||
-rw-r--r-- | tests/scripts/variables/define | 29 | ||||
-rw-r--r-- | tests/scripts/variables/flavors | 44 | ||||
-rw-r--r-- | tests/scripts/variables/negative | 14 | ||||
-rw-r--r-- | tests/scripts/variables/undefine | 18 |
10 files changed, 344 insertions, 54 deletions
diff --git a/tests/scripts/variables/GNUMAKEFLAGS b/tests/scripts/variables/GNUMAKEFLAGS index 6e50794..6dc9fd8 100644 --- a/tests/scripts/variables/GNUMAKEFLAGS +++ b/tests/scripts/variables/GNUMAKEFLAGS @@ -5,7 +5,7 @@ $description = "Test proper behavior of GNUMAKEFLAGS"; # Accept flags from GNUMAKEFLAGS as well as MAKEFLAGS # Results always go in MAKEFLAGS -$extraENV{'GNUMAKEFLAGS'} = '-e -r -R'; +$ENV{'GNUMAKEFLAGS'} = '-e -r -R'; run_make_test(q! all: ; @echo $(MAKEFLAGS) @@ -14,12 +14,12 @@ all: ; @echo $(MAKEFLAGS) # Long arguments mean everything is prefixed with "-" -$extraENV{'GNUMAKEFLAGS'} = '--no-print-directory -e -r -R --trace'; +$ENV{'GNUMAKEFLAGS'} = '--no-print-directory -e -r -R --trace'; run_make_test(q! all: ; @echo $(MAKEFLAGS) !, - '', "#MAKEFILE#:2: target 'all' does not exist + '', "#MAKEFILE#:2: update target 'all' due to: target does not exist echo erR --trace --no-print-directory erR --trace --no-print-directory"); @@ -27,7 +27,7 @@ erR --trace --no-print-directory"); unlink('x.mk'); -$extraENV{GNUMAKEFLAGS} = '-Itst/bad'; +$ENV{GNUMAKEFLAGS} = '-Itst/bad'; run_make_test(q! recurse: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAGS; #MAKEPATH# -f #MAKEFILE# all @@ -35,8 +35,20 @@ all: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAG -include x.mk x.mk: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAGS; echo > $@ !, - "", "x.mk\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\nrecurse\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Entering directory '#PWD#'\nall\nMAKEFLAGS = w -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Leaving directory '#PWD#'\n"); + "", "x.mk\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\nrecurse\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Entering directory '#PWD#'\nall\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Leaving directory '#PWD#'\n"); unlink('x.mk'); +# Ensure that we don't add GNUMAKEFLAGS to the environment if it's not there +run_make_test(q! +all: ; @env | grep GNUMAKEFLAGS; true +!, + '', ''); + +$ENV{GNUMAKEFLAGS} = '-Itst/bad'; +run_make_test(q! +all: ; @env | grep GNUMAKEFLAGS; true +!, + '', 'GNUMAKEFLAGS='); + 1; diff --git a/tests/scripts/variables/INCLUDE_DIRS b/tests/scripts/variables/INCLUDE_DIRS index c9662e9..6881292 100644 --- a/tests/scripts/variables/INCLUDE_DIRS +++ b/tests/scripts/variables/INCLUDE_DIRS @@ -8,11 +8,12 @@ use Cwd; $dir = cwd; $dir =~ s,.*/([^/]+)$,../$1,; -# Test #1: The content of .INCLUDE_DIRS depends on the platform for which -# make was built. What we know for sure is that it shouldn't be -# empty. -# -run_make_test(' +if (-d '/usr/include') { + # Test #1: The content of .INCLUDE_DIRS depends on the platform for which + # make was built. What we know for sure is that it shouldn't be + # empty. + # + run_make_test(' ifeq ($(.INCLUDE_DIRS),) $(warning .INCLUDE_DIRS is empty) endif @@ -20,9 +21,8 @@ endif .PHONY: all all:;@: ', -'', -''); - + '', ''); +} # Test #2: Make sure -I paths end up in .INCLUDE_DIRS. # @@ -32,15 +32,63 @@ $(warning dir is empty) endif ifeq ($(filter $(dir),$(.INCLUDE_DIRS)),) -$(warning .INCLUDE_DIRS does not contain $(dir)) +$(warning .INCLUDE_DIRS does not contain $(dir): $(.INCLUDE_DIRS)) endif .PHONY: all all:;@: ', -"-I$dir dir=$dir", -''); + "-I$dir dir=$dir", ''); + +# Find the default .INCLUDE_DIRS +create_file('defaultdirs.mk', "\$(info \$(.INCLUDE_DIRS))\nall:;\@:\n"); +my $cmd = subst_make_string("#MAKEPATH# -f defaultdirs.mk"); +my @dirs = `$cmd`; +my $dirs = $dirs[0]; +chomp $dirs; +unlink('defaultdirs.mk'); + +run_make_test(" +ifneq (\$(.INCLUDE_DIRS),$dirs) +\$(warning Mismatched \$(.INCLUDE_DIRS) != $dirs) +endif +all:;\@: +", + '', ''); + +# Verify that -I- disables content from .INCLUDE_DIRS + +run_make_test(q/ +ifneq ($(.INCLUDE_DIRS),) +$(warning Mismatched $(.INCLUDE_DIRS) != ) +endif +all:;@: +/, + '-I-', ''); + +# Prefix -I dirs to the front +mkdir('somedir', 0777); + +my $xdirs = $dirs ? " $dirs" : ''; +run_make_test(" +ifneq (\$(.INCLUDE_DIRS),somedir$xdirs) +\$(warning Mismatched '\$(.INCLUDE_DIRS)' != 'somedir$xdirs') +endif +all:;\@: +", + '-I somedir', ''); + +# Verify .INCLUDE_DIRS contains files after -I- + +run_make_test(q/ +ifneq ($(.INCLUDE_DIRS),somedir) +$(warning Mismatched $(.INCLUDE_DIRS) != somedir) +endif +all:;@: +/, + '-I - -I somedir', ''); +rmdir('somedir'); # This tells the test driver that the perl test script executed properly. 1; diff --git a/tests/scripts/variables/MAKEFLAGS b/tests/scripts/variables/MAKEFLAGS index 0fac74a..a41f1cf 100644 --- a/tests/scripts/variables/MAKEFLAGS +++ b/tests/scripts/variables/MAKEFLAGS @@ -6,31 +6,32 @@ $details = "DETAILS"; # Normal flags aren't prefixed with "-" run_make_test(q! -all: ; @echo $(MAKEFLAGS) +all: ; @echo /$(MAKEFLAGS)/ !, - '-e -r -R', 'erR'); + '-e -r -R', '/erR/'); # Long arguments mean everything is prefixed with "-" run_make_test(q! -all: ; @echo $(MAKEFLAGS) +all: ; @echo /$(MAKEFLAGS)/ !, - '--no-print-directory -e -r -R --trace', "#MAKEFILE#:2: target 'all' does not exist -echo erR --trace --no-print-directory -erR --trace --no-print-directory"); + '--no-print-directory -e -r -R --trace', "#MAKEFILE#:2: update target 'all' due to: target does not exist +echo /erR --trace --no-print-directory/ +/erR --trace --no-print-directory/"); # Recursive invocations of make should accumulate MAKEFLAGS values. # Savannah bug #2216 run_make_test(q! MSG = Fails +.RECIPEPREFIX = > all: - @echo '$@: MAKEFLAGS=$(MAKEFLAGS)' - @MSG=Works $(MAKE) -e -f #MAKEFILE# jump +> @echo '$@: MAKEFLAGS=$(MAKEFLAGS)' +> @MSG=Works $(MAKE) -e -f #MAKEFILE# jump jump: - @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)' - @$(MAKE) -f #MAKEFILE# print +> @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)' +> @$(MAKE) -f #MAKEFILE# print print: - @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)' +> @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)' .PHONY: all jump print !, '--no-print-directory', @@ -38,8 +39,120 @@ print: jump Works: MAKEFLAGS=e --no-print-directory print Works: MAKEFLAGS=e --no-print-directory'); -1; +# 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'); + +# Test that command line switches are all present in MAKEFLAGS. +# sv 62514. +my @opts; + +# Simple flags. +@opts = ('i', 'k', 'n', 'q', 'r', 's', 'w', 'd'); +exists $FEATURES{'check-symlink'} and push @opts, 'L'; + +for my $opt (@opts) { + run_make_test(q! +MAKEFLAGS:=B +all:; $(info makeflags='$(MAKEFLAGS)') +!, "-$opt", "/makeflags='B$opt'/"); +} + +# Switches which carry arguments. +@opts = (' -I/tmp', ' -Onone', ' --debug=b', ' -l2.5'); +for my $opt (@opts) { + run_make_test(q! +MAKEFLAGS:=B +all:; $(info makeflags='$(MAKEFLAGS)') +!, "$opt", "/makeflags='B$opt'/"); +} + +# Long options which take no arguments. +# sv 62514. +@opts = (' --no-print-directory', ' --warn-undefined-variables', ' --trace'); +for my $opt (@opts) { +run_make_test(q! +MAKEFLAGS:=B +all:; $(info makeflags='$(MAKEFLAGS)') +!, "$opt", "/makeflags='B$opt'/"); +} + +# 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'); +$ENV{'MAKEFLAGS'} = $opt; +for my $opt (@opts) { + run_make_test(" +MAKEFLAGS:=B $opt +all:; \$(info makeflags='\$(MAKEFLAGS)') +", "$opt", "/makeflags='B$opt'/"); +} + +# 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. +$ENV{'MAKEFLAGS'} = '-I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6 -I2 -I2'; +run_make_test(q! +MAKEFLAGS:=B -I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6 -I2 -I2 +all:; $(info makeflags='$(MAKEFLAGS)') +!, +'-I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6', +"/makeflags='B -I1 -I2 -I3 -I4 -I5 -I6 -l2.5 -Onone --debug=b'/"); -### Local Variables: -### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) -### End: +# A mix of multiple flags from env, the makefile and command line. +# Skip -L since it's not available everywhere +$ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn-undefined-variables --trace'; +run_make_test(q! +MAKEFLAGS:=iknqrswd -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5 +all:; $(info makeflags='$(MAKEFLAGS)') +!, +'-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'/"); + +# Verify MAKEFLAGS are all available to shell functions +$ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn-undefined-variables'; +run_make_test(q! +MAKEFLAGS := iknqrsw -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5 --no-print-directory +XX := $(shell echo "$$MAKEFLAGS") +all:; $(info makeflags='$(XX)') +!, + '-Onone -l2.5 -l2.5 -Onone -I/tmp -iknqrs -i -n -s -k -I/tmp', + "makeflags='iknqrsw -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5 --no-print-directory'"); + +# 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/"); + + +1; diff --git a/tests/scripts/variables/MAKE_RESTARTS b/tests/scripts/variables/MAKE_RESTARTS index 01bf55e..e1683a3 100644 --- a/tests/scripts/variables/MAKE_RESTARTS +++ b/tests/scripts/variables/MAKE_RESTARTS @@ -33,11 +33,11 @@ rmfiles('foo.x', 'bar.x'); # Test multiple restarts and make sure the variable is cleaned up run_make_test(' +.RECIPEPREFIX = > recurse: - @echo recurse MAKE_RESTARTS=$$MAKE_RESTARTS - @$(MAKE) -f #MAKEFILE# all -all: - @echo all MAKE_RESTARTS=$$MAKE_RESTARTS +> @echo recurse MAKE_RESTARTS=$$MAKE_RESTARTS +> @$(MAKE) -f #MAKEFILE# all +all: ; @echo all MAKE_RESTARTS=$$MAKE_RESTARTS $(info MAKE_RESTARTS=$(MAKE_RESTARTS)) include foo.x foo.x: ; @echo "include bar.x" > $@ @@ -55,7 +55,3 @@ all MAKE_RESTARTS= rmfiles('foo.x', 'bar.x'); 1; - -### Local Variables: -### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action)) -### End: diff --git a/tests/scripts/variables/SHELL b/tests/scripts/variables/SHELL index 4ff1ac2..78d887c 100644 --- a/tests/scripts/variables/SHELL +++ b/tests/scripts/variables/SHELL @@ -14,21 +14,19 @@ $mshell = $sh_name; # According to POSIX, the value of SHELL in the environment has no impact on # the value in the makefile. -# Note %extraENV takes precedence over the default value for the shell. -$extraENV{SHELL} = '/dev/null'; +$ENV{SHELL} = '/dev/null'; run_make_test('all:;@echo "$(SHELL)"', '', $mshell); -# According to POSIX, any value of SHELL set in the makefile should _NOT_ be -# exported to the subshell! I wanted to set SHELL to be $^X (perl) in the -# makefile, but make runs $(SHELL) -c 'commandline' and that doesn't work at -# all when $(SHELL) is perl :-/. So, we just add an extra initial /./ which -# works well on UNIX and seems to work OK on at least some non-UNIX systems. +# According to POSIX, any value of SHELL set in the makefile should not be +# exported to the subshell. A more portable option might be to set SHELL to +# be $^X (perl) in the makefile, and set .SHELLFLAGS to -e. -$extraENV{SHELL} = $mshell; +$ENV{SHELL} = $mshell; my $altshell = "/./$mshell"; my $altshell2 = "/././$mshell"; + if ($mshell =~ m,^([a-zA-Z]:)([\\/])(.*),) { $altshell = "$1$2.$2$3"; $altshell2 = "$1$2.$2.$2$3"; @@ -41,7 +39,7 @@ all:;@echo "$(SHELL) $$SHELL" # As a GNU make extension, if make's SHELL variable is explicitly exported, # then we really _DO_ export it. -$extraENV{SHELL} = $mshell; +$ENV{SHELL} = $mshell; run_make_test("export SHELL := $altshell\n".' all:;@echo "$(SHELL) $$SHELL" @@ -51,13 +49,13 @@ all:;@echo "$(SHELL) $$SHELL" # Test out setting of SHELL, both exported and not, as a target-specific # variable. -$extraENV{SHELL} = $mshell; +$ENV{SHELL} = $mshell; run_make_test("all: SHELL := $altshell\n".' all:;@echo "$(SHELL) $$SHELL" ', '', "$altshell $mshell"); -$extraENV{SHELL} = $mshell; +$ENV{SHELL} = $mshell; run_make_test(" SHELL := $altshell2 diff --git a/tests/scripts/variables/automatic b/tests/scripts/variables/automatic index 0b2e451..771bbda 100644 --- a/tests/scripts/variables/automatic +++ b/tests/scripts/variables/automatic @@ -91,6 +91,30 @@ mbr.src: ; @:', '', 'mbr'); +# Same as above with second expansion. +# +run_make_test(' +.SECONDEXPANSION: +.SUFFIXES: .b .src + +p:=mbr.src +mbr.b: $$p + @echo $* + +mbr.src: ; @:', + '', + 'mbr'); + +# Test that $* is set to empty string for unknown suffixes. + +run_make_test(' +mbr.b: mbr.src + @echo star=$* + +mbr.src: ; @:', + '', + "star=\n"); + # TEST #3 -- test for Savannah bug #8154 # Make sure that nonexistent prerequisites are listed in $?, since they are # considered reasons for the target to be rebuilt. @@ -107,7 +131,7 @@ bar: ;', unlink('foo'); -# TEST #4: ensure prereq ordering is correct when the commmand target has none +# TEST #4: ensure prereq ordering is correct when the command target has none # See Savannah bug #21198 run_make_test(' diff --git a/tests/scripts/variables/define b/tests/scripts/variables/define index 7324cbc..eecbd8f 100644 --- a/tests/scripts/variables/define +++ b/tests/scripts/variables/define @@ -61,7 +61,7 @@ all: ; $(multi) # TEST 1a: Various new-style define/endef, with no spaces -run_make_test(' +run_make_test(q! FOO = foo define multi= @@ -77,6 +77,10 @@ define posix::= @echo $(FOO) endef +define posixbsd:::= +@echo '$(FOO)$$bar' +endef + append = @echo a define append+= @@ -97,10 +101,11 @@ FOO = there all: ; $(multi) $(simple) $(posix) + $(posixbsd) $(append) $(cond) -', - '', "echo hi\nhi\nthere\nfoo\nfoo\na\nb\nfirst\n"); +!, + '', "echo hi\nhi\nthere\nfoo\nfoo\nfoo\$bar\na\nb\nfirst\n"); # TEST 2: define in true section of conditional (containing conditional) @@ -279,4 +284,22 @@ hello world '); +# Ensure that define can be a target when not appearing in a variable +# definition context. See SV 59870 + +run_make_test(q! +define = define + +$(define) : ;@echo $@ + +%:define + +all: define foo + +%.x : define + +foo:; +!, + '', "define\n"); + 1; diff --git a/tests/scripts/variables/flavors b/tests/scripts/variables/flavors index 831e5d8..627672f 100644 --- a/tests/scripts/variables/flavors +++ b/tests/scripts/variables/flavors @@ -153,4 +153,48 @@ dep: ; @: $(info recur=/$(recur)/ simple=/$(simple)/) !, '', "recur=/onetwothree/ simple=/fourfivesix/\n"); +# Test POSIX :::= +# This creates a recursive variable, but it expands the RHS first. Any +# variable escapes ('$$') are preserved so that this recursive variable can be +# expanded again without changing its contents. +run_make_test(' +bar = Goodbye +foo :::= $(bar) +bar = ${ugh} +ugh = Hello +all: ; @echo $(foo) +', + '', "Goodbye"); + +# POSIX :::= no spaces +run_make_test(q! +bar = Goodbye +foo:::=$(bar) +bar = ${ugh} +ugh = Hello +all: ; @echo $(foo) +!, + '', "Goodbye"); + +# Variable escapes ('$$') are preserved. +run_make_test(q! +bar = Good$$bye +foo :::= $(bar) $$what +bar = ${ugh} +ugh = Hello +all: ; @echo '$(foo)' +!, + '', 'Good$bye $what'); + +# Append works as expected +run_make_test(q! +bar = Good$$bye +foo :::= $(bar) +foo += $$what $(bar) +bar = ${ugh} +ugh = Hello +all: ; @echo '$(foo)' +!, + '', 'Good$bye $what Hello'); + 1; diff --git a/tests/scripts/variables/negative b/tests/scripts/variables/negative index 0f9abc8..5cb600a 100644 --- a/tests/scripts/variables/negative +++ b/tests/scripts/variables/negative @@ -43,4 +43,18 @@ run_make_test(undef, '#MAKEFILE#:4: *** unterminated variable reference. Stop.', 512); +# Whitespace not allowed in variable names +run_make_test('x y =', '', + '#MAKEFILE#:1: *** missing separator. Stop.', 512); + +run_make_test('x y=', '', + '#MAKEFILE#:1: *** missing separator. Stop.', 512); + +# In theory an empty variable should be ignored, but during parsing it's a +# real token and so this fails. I'm not 100% sure if this is right or not. + +run_make_test('x $X=', '', + '#MAKEFILE#:1: *** missing separator. Stop.', 512); + + 1; diff --git a/tests/scripts/variables/undefine b/tests/scripts/variables/undefine index 38707b8..1732351 100644 --- a/tests/scripts/variables/undefine +++ b/tests/scripts/variables/undefine @@ -70,4 +70,22 @@ all: ;@echo ouch ', '', "#MAKEFILE#:3: *** empty variable name. Stop.\n", 512); +# Ensure that define can be a target when not appearing in a variable +# definition context. See SV 59870 + +run_make_test(q! +undefine = undefine + +$(undefine) : ;@echo $@ + +%:undefine + +all: undefine foo + +%.x : undefine + +foo:; +!, + '', "undefine\n"); + 1; |