aboutsummaryrefslogblamecommitdiff
path: root/contrib/bmake/unit-tests/counter-append.mk
blob: d234835e5ec335fe253078228872926905029030 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
                                                                   















                                                                            
                                                         









                                                                 
# $NetBSD: counter-append.mk,v 1.5 2021/04/04 10:13:09 rillig Exp $
#
# Demonstrates how to let make count the number of times a variable
# is actually accessed, using the ::+= variable modifier.
#
# This works since 2020-09-23.  Before that, the counter ended up at having
# 6 words, even though the NEXT variable was only accessed 3 times.
# The cause for this surprising behavior was that the ::= variable modifiers
# returned an error marker instead of a simple empty string.

RELEVANT=	yes (load-time part)	# just to filter the output

COUNTER=	# zero

NEXT=		${COUNTER::+=a}${COUNTER:[#]}

# This variable is first set to empty and then expanded.
# See parse.c, function Parse_Var, 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}