xref: /freebsd/contrib/bmake/unit-tests/cmdline-undefined.mk (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1# $NetBSD: cmdline-undefined.mk,v 1.2 2020/11/04 04:49:33 rillig Exp $
2#
3# Tests for undefined variable 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	@echo 'The = assignment operator'
12	@${.MAKE} -f ${MAKEFILE} print-undefined \
13		CMDLINE='Undefined is $${UNDEFINED}.'
14	@echo
15
16	# The interesting case is using the ':=' assignment operator, which
17	# expands its right-hand side.  But only those variables that are
18	# defined.
19	@echo 'The := assignment operator'
20	@${.MAKE} -f ${MAKEFILE} print-undefined \
21		CMDLINE:='Undefined is $${UNDEFINED}.'
22	@echo
23
24.if make(print-undefined)
25
26.MAKEFLAGS: MAKEFLAGS_ASSIGN='Undefined is $${UNDEFINED}.'
27.MAKEFLAGS: MAKEFLAGS_SUBST:='Undefined is $${UNDEFINED}.'
28
29.info From the command line: ${CMDLINE}
30.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN}
31.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST}
32
33UNDEFINED?=	now defined
34
35.info From the command line: ${CMDLINE}
36.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN}
37.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST}
38
39print-undefined:
40.endif
41