1 # $NetBSD: var-recursive.mk,v 1.12 2025/04/13 09:29:33 rillig Exp $ 2 # 3 # Tests for expressions that refer to themselves and thus cannot be 4 # evaluated, as that would lead to an endless loop. 5 6 .if make(loadtime) 7 8 DIRECT= ${DIRECT} # Defining a recursive variable is not an error. 9 # expect+2: Variable DIRECT is recursive. 10 # expect+1: <> 11 . info <${DIRECT}> # But expanding such a variable is an error. 12 13 14 # The chain of variables that refer to each other may be long. 15 INDIRECT1= ${INDIRECT2} 16 INDIRECT2= ${INDIRECT1} 17 # expect+2: Variable INDIRECT1 is recursive. 18 # expect+1: <> 19 . info <${INDIRECT1}> 20 21 22 # The variable refers to itself, but only in the branch of a condition that 23 # is not satisfied and is thus not evaluated. 24 CONDITIONAL= ${1:?ok:${CONDITIONAL}} 25 # expect+1: <ok> 26 . info <${CONDITIONAL}> 27 28 29 # An expression with modifiers is skipped halfway. This can lead to wrong 30 # follow-up error messages, but recursive variables occur seldom. 31 MODIFIERS= ${MODIFIERS:Mpattern} 32 # expect+2: Variable MODIFIERS is recursive. 33 # expect+1: <Mpattern}> 34 . info <${MODIFIERS}> 35 36 37 # Short variable names can be expanded using the short-hand $V notation, 38 # which takes a different code path in Var_Parse for parsing the variable 39 # name. Ensure that these are checked as well. 40 V= $V 41 # expect+2: Variable V is recursive. 42 # expect+1: <> 43 . info <$V> 44 45 .elif make(runtime) 46 47 VAR= ${VAR} 48 runtime: 49 # expect: : before-recursive 50 : before-recursive 51 # expect: make: Variable VAR is recursive. 52 # expect-not-matches: ^: recursive%-line%-before 53 # expect-not-matches: ^: recursive%-line%-after 54 : recursive-line-before <${VAR}> recursive-line-after 55 # expect-not-matches: ^: after%-recursive 56 : after-recursive 57 58 .else 59 60 all: 61 @${MAKE} -f ${MAKEFILE} loadtime || echo "sub-exit status $$?" 62 @${MAKE} -f ${MAKEFILE} runtime || echo "sub-exit status $$?" 63 64 .endif 65