1# $NetBSD: cmdline-undefined.mk,v 1.5 2024/04/23 22:51:28 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          @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# expect+2: From the command line: Undefined is .
30# expect+1: From the command line: Undefined is .
31.info From the command line: ${CMDLINE}
32# expect+2: From .MAKEFLAGS '=': Undefined is .
33# expect+1: From .MAKEFLAGS '=': Undefined is .
34.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN}
35# expect+2: From .MAKEFLAGS ':=': Undefined is .
36# expect+1: From .MAKEFLAGS ':=': Undefined is .
37.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST}
38
39UNDEFINED?=         now defined
40
41# expect+2: From the command line: Undefined is now defined.
42# expect+1: From the command line: Undefined is now defined.
43.info From the command line: ${CMDLINE}
44# expect+2: From .MAKEFLAGS '=': Undefined is now defined.
45# expect+1: From .MAKEFLAGS '=': Undefined is now defined.
46.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN}
47# expect+2: From .MAKEFLAGS ':=': Undefined is now defined.
48# expect+1: From .MAKEFLAGS ':=': Undefined is now defined.
49.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST}
50
51print-undefined:
52.endif
53