aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/cmdline-undefined.mk
diff options
context:
space:
mode:
Diffstat (limited to 'unit-tests/cmdline-undefined.mk')
-rw-r--r--unit-tests/cmdline-undefined.mk40
1 files changed, 40 insertions, 0 deletions
diff --git a/unit-tests/cmdline-undefined.mk b/unit-tests/cmdline-undefined.mk
new file mode 100644
index 000000000000..5a3375cbbfb8
--- /dev/null
+++ b/unit-tests/cmdline-undefined.mk
@@ -0,0 +1,40 @@
+# $NetBSD: cmdline-undefined.mk,v 1.2 2020/11/04 04:49:33 rillig Exp $
+#
+# Tests for undefined variable expressions in the command line.
+
+all:
+ # When the command line is parsed, variable assignments using the
+ # '=' assignment operator do get their variable name expanded
+ # (which probably occurs rarely in practice, if at all), but their
+ # variable value is not expanded, as usual.
+ #
+ @echo 'The = assignment operator'
+ @${.MAKE} -f ${MAKEFILE} print-undefined \
+ CMDLINE='Undefined is $${UNDEFINED}.'
+ @echo
+
+ # The interesting case is using the ':=' assignment operator, which
+ # expands its right-hand side. But only those variables that are
+ # defined.
+ @echo 'The := assignment operator'
+ @${.MAKE} -f ${MAKEFILE} print-undefined \
+ CMDLINE:='Undefined is $${UNDEFINED}.'
+ @echo
+
+.if make(print-undefined)
+
+.MAKEFLAGS: MAKEFLAGS_ASSIGN='Undefined is $${UNDEFINED}.'
+.MAKEFLAGS: MAKEFLAGS_SUBST:='Undefined is $${UNDEFINED}.'
+
+.info From the command line: ${CMDLINE}
+.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN}
+.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST}
+
+UNDEFINED?= now defined
+
+.info From the command line: ${CMDLINE}
+.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN}
+.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST}
+
+print-undefined:
+.endif