1 # $NetBSD: var-recursive.mk,v 1.2 2020/10/31 13:45:00 rillig Exp $
3 # Tests for variable expressions that refer to themselves and thus
6 TESTS= direct indirect conditional short
8 # Since make exits immediately when it detects a recursive expression,
9 # the actual tests are run in sub-makes.
14 @${.MAKE} -f ${MAKEFILE} TEST=${test} || :
17 .elif ${TEST} == direct
19 DIRECT= ${DIRECT} # Defining a recursive variable is not yet an error.
20 . info still there # Therefore this line is printed.
21 . info ${DIRECT} # But expanding the variable is an error.
23 .elif ${TEST} == indirect
25 # The chain of variables that refer to each other may be long.
26 INDIRECT1= ${INDIRECT2}
27 INDIRECT2= ${INDIRECT1}
30 .elif ${TEST} == conditional
32 # The variable refers to itself, but only in the branch of a condition that
33 # is never satisfied and is thus not evaluated.
34 CONDITIONAL= ${1:?ok:${CONDITIONAL}}
37 .elif ${TEST} == short
39 # Short variable names can be expanded using the short-hand $V notation,
40 # which takes a different code path in Var_Parse for parsing the variable
41 # name. Ensure that these are checked as well.
46 . error Unknown test "${TEST}"