Module Name: src
Committed By: rillig
Date: Sat Feb 25 11:11:16 UTC 2023
Modified Files:
src/usr.bin/make/unit-tests: varname-dot-makeflags.exp
varname-dot-makeflags.mk
Log Message:
tests/make: test that MAKEFLAGS is an environment variable
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/usr.bin/make/unit-tests/varname-dot-makeflags.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/varname-dot-makeflags.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/unit-tests/varname-dot-makeflags.exp
diff -u src/usr.bin/make/unit-tests/varname-dot-makeflags.exp:1.3 src/usr.bin/make/unit-tests/varname-dot-makeflags.exp:1.4
--- src/usr.bin/make/unit-tests/varname-dot-makeflags.exp:1.3 Sat Feb 25 09:02:45 2023
+++ src/usr.bin/make/unit-tests/varname-dot-makeflags.exp Sat Feb 25 11:11:16 2023
@@ -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
Index: src/usr.bin/make/unit-tests/varname-dot-makeflags.mk
diff -u src/usr.bin/make/unit-tests/varname-dot-makeflags.mk:1.4 src/usr.bin/make/unit-tests/varname-dot-makeflags.mk:1.5
--- src/usr.bin/make/unit-tests/varname-dot-makeflags.mk:1.4 Sat Feb 25 10:41:14 2023
+++ src/usr.bin/make/unit-tests/varname-dot-makeflags.mk Sat Feb 25 11:11:16 2023
@@ -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}>'