Home | History | Annotate | Line # | Download | only in unit-tests
varmod-indirect.mk revision 1.1
      1  1.1  rillig # $NetBSD: varmod-indirect.mk,v 1.1 2020/12/01 22:16:36 rillig Exp $
      2  1.1  rillig #
      3  1.1  rillig # Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
      4  1.1  rillig # These can be used for very basic purposes like converting a string to either
      5  1.1  rillig # uppercase or lowercase, as well as for fairly advanced modifiers that first
      6  1.1  rillig # look like line noise and are hard to decipher.
      7  1.1  rillig #
      8  1.1  rillig # TODO: Since when are indirect modifiers supported?
      9  1.1  rillig 
     10  1.1  rillig 
     11  1.1  rillig # The nested variable expression expands to "tu", and this is interpreted as
     12  1.1  rillig # a variable modifier for the value "Upper", resulting in "UPPER".
     13  1.1  rillig .if ${Upper:L:${:Utu}} != "UPPER"
     14  1.1  rillig .  error
     15  1.1  rillig .endif
     16  1.1  rillig 
     17  1.1  rillig # The nested variable expression expands to "tl", and this is interpreted as
     18  1.1  rillig # a variable modifier for the value "Lower", resulting in "lower".
     19  1.1  rillig .if ${Lower:L:${:Utl}} != "lower"
     20  1.1  rillig .  error
     21  1.1  rillig .endif
     22  1.1  rillig 
     23  1.1  rillig 
     24  1.1  rillig # The nested variable expression is ${1 != 1:?Z:tl}, consisting of the
     25  1.1  rillig # condition "1 != 1", the then-branch "Z" and the else-branch "tl".  Since
     26  1.1  rillig # the condition evaluates to false, the then-branch is ignored (it would
     27  1.1  rillig # have been an unknown modifier anyway) and the ":tl" modifier is applied.
     28  1.1  rillig .if ${Mixed:L:${1 != 1:?Z:tl}} != "mixed"
     29  1.1  rillig .  error
     30  1.1  rillig .endif
     31  1.1  rillig 
     32  1.1  rillig 
     33  1.1  rillig # The indirect modifier can also replace an ':L' modifier, which allows for
     34  1.1  rillig # brain twisters since by reading the expression alone, it is not possible
     35  1.1  rillig # to say whether the variable name will be evaluated as a variable name or
     36  1.1  rillig # as the immediate value of the expression.
     37  1.1  rillig VAR=	value
     38  1.1  rillig M_ExpandVar=	# an empty modifier
     39  1.1  rillig M_VarAsValue=	L
     40  1.1  rillig #
     41  1.1  rillig .if ${VAR:${M_ExpandVar}} != "value"
     42  1.1  rillig .  error
     43  1.1  rillig .endif
     44  1.1  rillig .if ${VAR:${M_VarAsValue}} != "VAR"
     45  1.1  rillig .  error
     46  1.1  rillig .endif
     47  1.1  rillig 
     48  1.1  rillig # The indirect modifier M_ListToSkip, when applied to a list of patterns,
     49  1.1  rillig # expands to a sequence of ':N' modifiers, each of which filters one of the
     50  1.1  rillig # patterns.  This list of patterns can then be applied to another variable
     51  1.1  rillig # to actually filter that variable.
     52  1.1  rillig #
     53  1.1  rillig M_ListToSkip=	@pat@N$${pat}@:ts:
     54  1.1  rillig #
     55  1.1  rillig # The dollar signs need to be doubled in the above modifier expression,
     56  1.1  rillig # otherwise they would be expanded too early, that is, when parsing the
     57  1.1  rillig # modifier itself.
     58  1.1  rillig #
     59  1.1  rillig # In the following example, M_NoPrimes expands to 'N2:N3:N5:N7:N1[1379]'.
     60  1.1  rillig # The 'N' comes from the expression 'N${pat}', the separating colons come
     61  1.1  rillig # from the modifier ':ts:'.
     62  1.1  rillig #
     63  1.1  rillig #.MAKEFLAGS: -dcv		# Uncomment this line to see the details
     64  1.1  rillig #
     65  1.1  rillig PRIMES=		2 3 5 7 1[1379]
     66  1.1  rillig M_NoPrimes=	${PRIMES:${M_ListToSkip}}
     67  1.1  rillig .if ${:U:range=20:${M_NoPrimes}} != "1 4 6 8 9 10 12 14 15 16 18 20"
     68  1.1  rillig .  error
     69  1.1  rillig .endif
     70  1.1  rillig .MAKEFLAGS: -d0
     71  1.1  rillig 
     72  1.1  rillig all:
     73