]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/counter.mk
Import tzdata 2020c
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / counter.mk
1 # $NetBSD: counter.mk,v 1.1 2020/08/02 14:53:02 rillig Exp $
2 #
3 # Demonstrates that it is not easily possible to let make count
4 # the number of times a variable is actually accessed.
5 #
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
8 # surprising.
9 #
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.
13
14 RELEVANT=       yes (load-time part)    # just to filter the output
15
16 COUNTER=        # zero
17
18 NEXT=           ${COUNTER::=${COUNTER} a}${COUNTER:[#]}
19
20 # This variable is first set to empty and then expanded.
21 # See parse.c, function Parse_DoVar, keyword "!Var_Exists".
22 A:=             ${NEXT}
23 B:=             ${NEXT}
24 C:=             ${NEXT}
25
26 RELEVANT=       no
27
28 all:
29         @: ${RELEVANT::=yes (run-time part)}
30         @echo A=${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q}
31         @: ${RELEVANT::=no}