varparse-dynamic.mk revision 1.8
11.8Srillig# $NetBSD: varparse-dynamic.mk,v 1.8 2023/11/19 22:32:44 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.6Srillig# To trigger the bug, the variable had to be undefined.
61.1Srillig.if ${.TARGET}			# exact match, may be undefined
71.1Srillig.endif
81.7Srillig# expect+1: Malformed conditional (${.TARGEX})
91.1Srillig.if ${.TARGEX}			# 1 character difference, must be defined
101.1Srillig.endif
111.7Srillig# expect+1: Malformed conditional (${.TARGXX})
121.1Srillig.if ${.TARGXX}			# 2 characters difference, must be defined
131.1Srillig.endif
141.1Srillig
151.2Srillig# When a dynamic variable (such as .TARGET) is evaluated in the global
161.4Srillig# scope, it is not yet ready to be expanded.  Therefore the complete
171.2Srillig# expression is returned as the variable value, hoping that it can be
181.2Srillig# resolved at a later point.
191.2Srillig#
201.5Srillig# This test covers the code in Var_Parse that deals with DEF_UNDEF but not
211.5Srillig# DEF_DEFINED for dynamic variables.
221.2Srillig.if ${.TARGET:S,^,,} != "\${.TARGET:S,^,,}"
231.2Srillig.  error
241.2Srillig.endif
251.2Srillig
261.4Srillig# If a dynamic variable is expanded in a non-local scope, the expression
271.8Srillig# based on this variable is not expanded.  But there may be nested
281.3Srillig# expressions in the modifiers, and these are kept unexpanded as well.
291.3Srillig.if ${.TARGET:M${:Ufallback}} != "\${.TARGET:M\${:Ufallback}}"
301.3Srillig.  error
311.3Srillig.endif
321.3Srillig.if ${.TARGET:M${UNDEF}} != "\${.TARGET:M\${UNDEF}}"
331.3Srillig.  error
341.3Srillig.endif
35