Home | History | Annotate | Line # | Download | only in unit-tests
      1  1.5  rillig # $NetBSD: counter-append.mk,v 1.5 2021/04/04 10:13:09 rillig Exp $
      2  1.1  rillig #
      3  1.2  rillig # Demonstrates how to let make count the number of times a variable
      4  1.2  rillig # is actually accessed, using the ::+= variable modifier.
      5  1.1  rillig #
      6  1.2  rillig # This works since 2020-09-23.  Before that, the counter ended up at having
      7  1.2  rillig # 6 words, even though the NEXT variable was only accessed 3 times.
      8  1.4  rillig # The cause for this surprising behavior was that the ::= variable modifiers
      9  1.4  rillig # returned an error marker instead of a simple empty string.
     10  1.1  rillig 
     11  1.1  rillig RELEVANT=	yes (load-time part)	# just to filter the output
     12  1.1  rillig 
     13  1.1  rillig COUNTER=	# zero
     14  1.1  rillig 
     15  1.1  rillig NEXT=		${COUNTER::+=a}${COUNTER:[#]}
     16  1.1  rillig 
     17  1.1  rillig # This variable is first set to empty and then expanded.
     18  1.5  rillig # See parse.c, function Parse_Var, keyword "!Var_Exists".
     19  1.1  rillig A:=		${NEXT}
     20  1.1  rillig B:=		${NEXT}
     21  1.1  rillig C:=		${NEXT}
     22  1.1  rillig 
     23  1.1  rillig RELEVANT=	no
     24  1.1  rillig 
     25  1.1  rillig all:
     26  1.1  rillig 	@: ${RELEVANT::=yes (run-time part)}
     27  1.1  rillig 	@echo A=${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q}
     28  1.1  rillig 	@: ${RELEVANT::=no}
     29