summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-02-25 11:11:16 +0000
committerrillig <rillig@NetBSD.org>2023-02-25 11:11:16 +0000
commit337df213a80105722ecb8ffe607d75e84bb080ae (patch)
tree020badebc104d51a5ed50c968c0b4ca13ffdb1d2 /usr.bin/make
parent233921554414ef3cc4849e33768d2b769f5fef7e (diff)
tests/make: test that MAKEFLAGS is an environment variable
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/unit-tests/varname-dot-makeflags.exp2
-rw-r--r--usr.bin/make/unit-tests/varname-dot-makeflags.mk32
2 files changed, 32 insertions, 2 deletions
diff --git a/usr.bin/make/unit-tests/varname-dot-makeflags.exp b/usr.bin/make/unit-tests/varname-dot-makeflags.exp
index 1f74b8422e1..c1354177ca4 100644
--- a/usr.bin/make/unit-tests/varname-dot-makeflags.exp
+++ b/usr.bin/make/unit-tests/varname-dot-makeflags.exp
@@ -16,4 +16,6 @@ append_stage_0: MAKEFLAGS=< -r -k >
append_stage_1: MAKEFLAGS=< -r -k -D before-0 -D after-0 VAR0=value>
append_stage_2: MAKEFLAGS=< -r -k -D before-0 -D after-0 -D before-1 -D after-1 VAR0=value VAR1=value>
append_stage_3: MAKEFLAGS=< -r -k -D before-0 -D after-0 -D before-1 -D after-1 -D before-2 -D after-2 VAR0=value VAR1=value VAR2=value>
+override_stage_1: run MAKEFLAGS=< -r -k STAGE=1 VAR=value>
+override_stage_2: STAGE=<2> VAR=<value>
exit status 0
diff --git a/usr.bin/make/unit-tests/varname-dot-makeflags.mk b/usr.bin/make/unit-tests/varname-dot-makeflags.mk
index 01c2f91ce6c..99a9352704b 100644
--- a/usr.bin/make/unit-tests/varname-dot-makeflags.mk
+++ b/usr.bin/make/unit-tests/varname-dot-makeflags.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varname-dot-makeflags.mk,v 1.4 2023/02/25 10:41:14 rillig Exp $
+# $NetBSD: varname-dot-makeflags.mk,v 1.5 2023/02/25 11:11:16 rillig Exp $
#
# Tests for the special .MAKEFLAGS variable, which collects almost all
# command line arguments and passes them on to any child processes via
@@ -7,7 +7,7 @@
# See also:
# varname-dot-makeoverrides.mk
-all: spaces_stage_0 dollars_stage_0 append_stage_0
+all: spaces_stage_0 dollars_stage_0 append_stage_0 override_stage_0
# When options are parsed, the option and its argument are appended as
@@ -119,3 +119,31 @@ append_stage_2:
append_stage_3:
@echo '$@: MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+
+
+# Demonstrates the implementation details of 'MAKEFLAGS', in particular that
+# it is an environment variable rather than a global variable.
+override_stage_0:
+ @${MAKE} -f ${MAKEFILE} STAGE=1 VAR=value override_stage_1
+
+.if make(override_stage_1)
+# While parsing the makefiles, 'MAKEFLAGS' is the value of the environment
+# variable, in this case provided by stage 0.
+. if ${MAKEFLAGS:M*} != "-r -k"
+. error
+. endif
+MAKEFLAGS= overridden # temporarily override it
+. if ${MAKEFLAGS} != "overridden"
+. error
+. endif
+.undef MAKEFLAGS # make the environment variable visible again
+. if ${MAKEFLAGS:M*} != "-r -k"
+. error
+. endif
+.endif
+override_stage_1:
+ @echo '$@: run MAKEFLAGS=<'${MAKEFLAGS:Q}'>'
+ @${MAKE} -f ${MAKEFILE} STAGE=2 override_stage_2
+
+override_stage_2:
+ @echo '$@: STAGE=<${STAGE}> VAR=<${VAR}>'