varparse-dynamic.mk revision 1.4
11.4Srillig# $NetBSD: varparse-dynamic.mk,v 1.4 2021/02/04 21:42:47 rillig Exp $
21.1Srillig
31.1Srillig# Before 2020-07-27, there was an off-by-one error in Var_Parse that skipped
41.1Srillig# the last character in the variable name.
51.1Srillig# To trigger the bug, the variable must not be defined.
61.1Srillig.if ${.TARGET}			# exact match, may be undefined
71.1Srillig.endif
81.1Srillig.if ${.TARGEX}			# 1 character difference, must be defined
91.1Srillig.endif
101.1Srillig.if ${.TARGXX}			# 2 characters difference, must be defined
111.1Srillig.endif
121.1Srillig
131.2Srillig# When a dynamic variable (such as .TARGET) is evaluated in the global
141.4Srillig# scope, it is not yet ready to be expanded.  Therefore the complete
151.2Srillig# expression is returned as the variable value, hoping that it can be
161.2Srillig# resolved at a later point.
171.2Srillig#
181.2Srillig# This test covers the code in Var_Parse that deals with VAR_JUNK but not
191.2Srillig# VAR_KEEP for dynamic variables.
201.2Srillig.if ${.TARGET:S,^,,} != "\${.TARGET:S,^,,}"
211.2Srillig.  error
221.2Srillig.endif
231.2Srillig
241.4Srillig# If a dynamic variable is expanded in a non-local scope, the expression
251.3Srillig# based on this variable is not expanded.  But there may be nested variable
261.3Srillig# expressions in the modifiers, and these are kept unexpanded as well.
271.3Srillig.if ${.TARGET:M${:Ufallback}} != "\${.TARGET:M\${:Ufallback}}"
281.3Srillig.  error
291.3Srillig.endif
301.3Srillig.if ${.TARGET:M${UNDEF}} != "\${.TARGET:M\${UNDEF}}"
311.3Srillig.  error
321.3Srillig.endif
331.3Srillig
341.1Srilligall:
351.1Srillig	@:
36