Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make/unit-tests tests/make: test that MAKEFLAGS is a...
details: https://anonhg.NetBSD.org/src/rev/6113391cb636
branches: trunk
changeset: 373740:6113391cb636
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Feb 25 11:11:16 2023 +0000
description:
tests/make: test that MAKEFLAGS is an environment variable
diffstat:
usr.bin/make/unit-tests/varname-dot-makeflags.exp | 2 +
usr.bin/make/unit-tests/varname-dot-makeflags.mk | 32 +++++++++++++++++++++-
2 files changed, 32 insertions(+), 2 deletions(-)
diffs (60 lines):
diff -r e288f89686c1 -r 6113391cb636 usr.bin/make/unit-tests/varname-dot-makeflags.exp
--- a/usr.bin/make/unit-tests/varname-dot-makeflags.exp Sat Feb 25 10:41:14 2023 +0000
+++ b/usr.bin/make/unit-tests/varname-dot-makeflags.exp Sat Feb 25 11:11:16 2023 +0000
@@ -16,4 +16,6 @@
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 -r e288f89686c1 -r 6113391cb636 usr.bin/make/unit-tests/varname-dot-makeflags.mk
--- a/usr.bin/make/unit-tests/varname-dot-makeflags.mk Sat Feb 25 10:41:14 2023 +0000
+++ b/usr.bin/make/unit-tests/varname-dot-makeflags.mk Sat Feb 25 11:11:16 2023 +0000
@@ -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_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}>'
Home |
Main Index |
Thread Index |
Old Index