1*6a7405f5SSimon J. Gerraty# $NetBSD: varparse-dynamic.mk,v 1.10 2025/01/11 21:21:34 rillig Exp $ 22c3632d1SSimon J. Gerraty 32c3632d1SSimon J. Gerraty# Before 2020-07-27, there was an off-by-one error in Var_Parse that skipped 42c3632d1SSimon J. Gerraty# the last character in the variable name. 5148ee845SSimon J. Gerraty# To trigger the bug, the variable had to be undefined. 62c3632d1SSimon J. Gerraty.if ${.TARGET} # exact match, may be undefined 72c3632d1SSimon J. Gerraty.endif 8*6a7405f5SSimon J. Gerraty# expect+1: Variable ".TARGEX" is undefined 92c3632d1SSimon J. Gerraty.if ${.TARGEX} # 1 character difference, must be defined 102c3632d1SSimon J. Gerraty.endif 11*6a7405f5SSimon J. Gerraty# expect+1: Variable ".TARGXX" is undefined 122c3632d1SSimon J. Gerraty.if ${.TARGXX} # 2 characters difference, must be defined 132c3632d1SSimon J. Gerraty.endif 142c3632d1SSimon J. Gerraty 15956e45f6SSimon J. Gerraty# When a dynamic variable (such as .TARGET) is evaluated in the global 16dba7b0efSSimon J. Gerraty# scope, it is not yet ready to be expanded. Therefore the complete 17956e45f6SSimon J. Gerraty# expression is returned as the variable value, hoping that it can be 18956e45f6SSimon J. Gerraty# resolved at a later point. 19956e45f6SSimon J. Gerraty# 20b0c40a00SSimon J. Gerraty# This test covers the code in Var_Parse that deals with DEF_UNDEF but not 21b0c40a00SSimon J. Gerraty# DEF_DEFINED for dynamic variables. 22956e45f6SSimon J. Gerraty.if ${.TARGET:S,^,,} != "\${.TARGET:S,^,,}" 23956e45f6SSimon J. Gerraty. error 24956e45f6SSimon J. Gerraty.endif 25956e45f6SSimon J. Gerraty 26dba7b0efSSimon J. Gerraty# If a dynamic variable is expanded in a non-local scope, the expression 27d5e0a182SSimon J. Gerraty# based on this variable is not expanded. But there may be nested 2806b9b3e0SSimon J. Gerraty# expressions in the modifiers, and these are kept unexpanded as well. 2906b9b3e0SSimon J. Gerraty.if ${.TARGET:M${:Ufallback}} != "\${.TARGET:M\${:Ufallback}}" 3006b9b3e0SSimon J. Gerraty. error 3106b9b3e0SSimon J. Gerraty.endif 3206b9b3e0SSimon J. Gerraty.if ${.TARGET:M${UNDEF}} != "\${.TARGET:M\${UNDEF}}" 3306b9b3e0SSimon J. Gerraty. error 3406b9b3e0SSimon J. Gerraty.endif 35