1*548bfc56SSimon J. Gerraty# $NetBSD: cmdline-undefined.mk,v 1.5 2024/04/23 22:51:28 rillig Exp $ 2e2eeea75SSimon J. Gerraty# 3*548bfc56SSimon J. Gerraty# Tests for undefined variables in expressions in the command line. 4e2eeea75SSimon J. Gerraty 5e2eeea75SSimon J. Gerratyall: 6e2eeea75SSimon J. Gerraty # When the command line is parsed, variable assignments using the 7e2eeea75SSimon J. Gerraty # '=' assignment operator do get their variable name expanded 8e2eeea75SSimon J. Gerraty # (which probably occurs rarely in practice, if at all), but their 9e2eeea75SSimon J. Gerraty # variable value is not expanded, as usual. 10e2eeea75SSimon J. Gerraty # 11e2eeea75SSimon J. Gerraty @echo 'The = assignment operator' 12e2eeea75SSimon J. Gerraty @${.MAKE} -f ${MAKEFILE} print-undefined \ 13e2eeea75SSimon J. Gerraty CMDLINE='Undefined is $${UNDEFINED}.' 14e2eeea75SSimon J. Gerraty @echo 15e2eeea75SSimon J. Gerraty 16e2eeea75SSimon J. Gerraty # The interesting case is using the ':=' assignment operator, which 17e2eeea75SSimon J. Gerraty # expands its right-hand side. But only those variables that are 18e2eeea75SSimon J. Gerraty # defined. 19e2eeea75SSimon J. Gerraty @echo 'The := assignment operator' 20e2eeea75SSimon J. Gerraty @${.MAKE} -f ${MAKEFILE} print-undefined \ 21e2eeea75SSimon J. Gerraty CMDLINE:='Undefined is $${UNDEFINED}.' 22e2eeea75SSimon J. Gerraty @echo 23e2eeea75SSimon J. Gerraty 24e2eeea75SSimon J. Gerraty.if make(print-undefined) 25e2eeea75SSimon J. Gerraty 26e2eeea75SSimon J. Gerraty.MAKEFLAGS: MAKEFLAGS_ASSIGN='Undefined is $${UNDEFINED}.' 27e2eeea75SSimon J. Gerraty.MAKEFLAGS: MAKEFLAGS_SUBST:='Undefined is $${UNDEFINED}.' 28e2eeea75SSimon J. Gerraty 29148ee845SSimon J. Gerraty# expect+2: From the command line: Undefined is . 30148ee845SSimon J. Gerraty# expect+1: From the command line: Undefined is . 31e2eeea75SSimon J. Gerraty.info From the command line: ${CMDLINE} 32148ee845SSimon J. Gerraty# expect+2: From .MAKEFLAGS '=': Undefined is . 33148ee845SSimon J. Gerraty# expect+1: From .MAKEFLAGS '=': Undefined is . 34e2eeea75SSimon J. Gerraty.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN} 35148ee845SSimon J. Gerraty# expect+2: From .MAKEFLAGS ':=': Undefined is . 36148ee845SSimon J. Gerraty# expect+1: From .MAKEFLAGS ':=': Undefined is . 37e2eeea75SSimon J. Gerraty.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST} 38e2eeea75SSimon J. Gerraty 39e2eeea75SSimon J. GerratyUNDEFINED?= now defined 40e2eeea75SSimon J. Gerraty 41148ee845SSimon J. Gerraty# expect+2: From the command line: Undefined is now defined. 42148ee845SSimon J. Gerraty# expect+1: From the command line: Undefined is now defined. 43e2eeea75SSimon J. Gerraty.info From the command line: ${CMDLINE} 44148ee845SSimon J. Gerraty# expect+2: From .MAKEFLAGS '=': Undefined is now defined. 45148ee845SSimon J. Gerraty# expect+1: From .MAKEFLAGS '=': Undefined is now defined. 46e2eeea75SSimon J. Gerraty.info From .MAKEFLAGS '=': ${MAKEFLAGS_ASSIGN} 47148ee845SSimon J. Gerraty# expect+2: From .MAKEFLAGS ':=': Undefined is now defined. 48148ee845SSimon J. Gerraty# expect+1: From .MAKEFLAGS ':=': Undefined is now defined. 49e2eeea75SSimon J. Gerraty.info From .MAKEFLAGS ':=': ${MAKEFLAGS_SUBST} 50e2eeea75SSimon J. Gerraty 51e2eeea75SSimon J. Gerratyprint-undefined: 52e2eeea75SSimon J. Gerraty.endif 53