1 # $NetBSD: var-recursive.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $
3 # Tests for variable expressions that refer to themselves and thus
6 TESTS= direct indirect conditional short target
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 # expect+1: still there
21 . info still there # Therefore this line is printed.
22 . info ${DIRECT} # But expanding the variable is an error.
24 .elif ${TEST} == indirect
26 # The chain of variables that refer to each other may be long.
27 INDIRECT1= ${INDIRECT2}
28 INDIRECT2= ${INDIRECT1}
31 .elif ${TEST} == conditional
33 # The variable refers to itself, but only in the branch of a condition that
34 # is never satisfied and is thus not evaluated.
35 CONDITIONAL= ${1:?ok:${CONDITIONAL}}
39 .elif ${TEST} == short
41 # Short variable names can be expanded using the short-hand $V notation,
42 # which takes a different code path in Var_Parse for parsing the variable
43 # name. Ensure that these are checked as well.
47 .elif ${TEST} == target
49 # If a recursive variable is accessed in a command of a target, the makefiles
50 # are not parsed anymore, so there is no location information from the
51 # .includes and .for directives. In such a case, use the location of the last
52 # command of the target to provide at least a hint to the location.
60 . error Unknown test "${TEST}"