1 # $NetBSD: counter.mk,v 1.1 2020/08/02 14:53:02 rillig Exp $
3 # Demonstrates that it is not easily possible to let make count
4 # the number of times a variable is actually accessed.
6 # As of 2020-08-02, the counter ends up at having 4 words, even
7 # though the NEXT variable is only accessed 3 times. This is
10 # A hint to this surprising behavior is that the variables don't
11 # get fully expanded. For example, A does not simply contain the
12 # value "1" but an additional unexpanded ${COUNTER:...} before it.
14 RELEVANT= yes (load-time part) # just to filter the output
18 NEXT= ${COUNTER::=${COUNTER} a}${COUNTER:[#]}
20 # This variable is first set to empty and then expanded.
21 # See parse.c, function Parse_DoVar, keyword "!Var_Exists".
29 @: ${RELEVANT::=yes (run-time part)}
30 @echo A=${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q}