xref: /freebsd/contrib/bmake/unit-tests/cmdline-undefined.mk (revision a8c56be47166295d37600ff81fc1857db87b3a9b)
1# $NetBSD: cmdline-undefined.mk,v 1.6 2025/06/30 21:44:39 rillig Exp $
2#
3# Tests for undefined variables in expressions in the command line.
4
5all:
6	# When the command line is parsed, variable assignments using the
7	# '=' assignment operator do get their variable name expanded
8	# (which probably occurs rarely in practice, if at all), but their
9	# variable value is not expanded, as usual.
10	#
11# expect+30: From the command line: Undefined is .
12# expect+30: From .MAKEFLAGS '=': Undefined is .
13# expect+30: From .MAKEFLAGS ':=': Undefined is .
14# expect+33: From the command line: Undefined is now defined.
15# expect+33: From .MAKEFLAGS '=': Undefined is now defined.
16# expect+33: From .MAKEFLAGS ':=': Undefined is now defined.
17	@echo 'The = assignment operator'
18	@${.MAKE} -f ${MAKEFILE} print-undefined \
19		CMDLINE='Undefined is $${UNDEFINED}.'
20	@echo
21
22	# The interesting case is using the ':=' assignment operator, which
23	# expands its right-hand side.  But only those variables that are
24	# defined.
25# expect+16: From the command line: Undefined is .
26# expect+16: From .MAKEFLAGS '=': Undefined is .
27# expect+16: From .MAKEFLAGS ':=': Undefined is .
28# expect+19: From the command line: Undefined is now defined.
29# expect+19: From .MAKEFLAGS '=': Undefined is now defined.
30# expect+19: From .MAKEFLAGS ':=': Undefined is now defined.
31	@echo 'The := assignment operator'
32	@${.MAKE} -f ${MAKEFILE} print-undefined \
33		CMDLINE:='Undefined is $${UNDEFINED}.'
34	@echo
35
36.if make(print-undefined)
37
38.MAKEFLAGS: MAKEFLAGS_ASSIGN='Undefined is $${UNDEFINED}.'
39.MAKEFLAGS: MAKEFLAGS_SUBST:='Undefined is $${UNDEFINED}.'
40
41.info From the command line: ${CMDLINE}
42.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN}
43.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST}
44
45UNDEFINED?=	now defined
46
47.info From the command line: ${CMDLINE}
48.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN}
49.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST}
50
51print-undefined:
52.endif
53