diff options
Diffstat (limited to 'unit-tests/counter.mk')
-rw-r--r-- | unit-tests/counter.mk | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/unit-tests/counter.mk b/unit-tests/counter.mk new file mode 100644 index 0000000000000..23e7dcc0e8d29 --- /dev/null +++ b/unit-tests/counter.mk @@ -0,0 +1,31 @@ +# $NetBSD: counter.mk,v 1.1 2020/08/02 14:53:02 rillig Exp $ +# +# Demonstrates that it is not easily possible to let make count +# the number of times a variable is actually accessed. +# +# As of 2020-08-02, the counter ends up at having 4 words, even +# though the NEXT variable is only accessed 3 times. This is +# surprising. +# +# A hint to this surprising behavior is that the variables don't +# get fully expanded. For example, A does not simply contain the +# value "1" but an additional unexpanded ${COUNTER:...} before it. + +RELEVANT= yes (load-time part) # just to filter the output + +COUNTER= # zero + +NEXT= ${COUNTER::=${COUNTER} a}${COUNTER:[#]} + +# This variable is first set to empty and then expanded. +# See parse.c, function Parse_DoVar, keyword "!Var_Exists". +A:= ${NEXT} +B:= ${NEXT} +C:= ${NEXT} + +RELEVANT= no + +all: + @: ${RELEVANT::=yes (run-time part)} + @echo A=${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q} + @: ${RELEVANT::=no} |