1 1.5 rillig # $NetBSD: varmod-match.mk,v 1.5 2020/09/13 05:36:26 rillig Exp $ 2 1.1 rillig # 3 1.2 rillig # Tests for the :M variable modifier, which filters words that match the 4 1.2 rillig # given pattern. 5 1.4 rillig # 6 1.4 rillig # See ApplyModifier_Match and ModifyWord_Match for the implementation. 7 1.1 rillig 8 1.4 rillig .MAKEFLAGS: -dc 9 1.3 rillig 10 1.3 rillig NUMBERS= One Two Three Four five six seven 11 1.3 rillig 12 1.5 rillig # Only keep words that start with an uppercase letter. 13 1.4 rillig .if ${NUMBERS:M[A-Z]*} != "One Two Three Four" 14 1.4 rillig . error 15 1.4 rillig .endif 16 1.4 rillig 17 1.5 rillig # Only keep words that start with a character other than an uppercase letter. 18 1.4 rillig .if ${NUMBERS:M[^A-Z]*} != "five six seven" 19 1.4 rillig . error 20 1.4 rillig .endif 21 1.4 rillig 22 1.5 rillig # Only keep words that don't start with s and at the same time end with 23 1.5 rillig # either of [ex]. 24 1.5 rillig # 25 1.5 rillig # This test case ensures that the negation from the first character class 26 1.5 rillig # does not propagate to the second character class. 27 1.4 rillig .if ${NUMBERS:M[^s]*[ex]} != "One Three five" 28 1.4 rillig . error 29 1.4 rillig .endif 30 1.3 rillig 31 1.3 rillig # Before 2020-06-13, this expression took quite a long time in Str_Match, 32 1.3 rillig # calling itself 601080390 times for 16 asterisks. 33 1.4 rillig .if ${:U****************:M****************b} 34 1.4 rillig .endif 35 1.4 rillig 36 1.4 rillig # To match a dollar sign in a word, double it. 37 1.5 rillig # 38 1.4 rillig # This is different from the :S and :C variable modifiers, where a '$' 39 1.5 rillig # has to be escaped as '\$'. 40 1.4 rillig .if ${:Ua \$ sign:M*$$*} != "\$" 41 1.4 rillig . error 42 1.4 rillig .endif 43 1.4 rillig 44 1.5 rillig # In the :M modifier, '\$' does not escape a dollar. Instead it is 45 1.5 rillig # interpreted as a backslash followed by whatever expression the 46 1.5 rillig # '$' starts. 47 1.5 rillig # 48 1.5 rillig # This differs from the :S, :C and several other variable modifiers. 49 1.4 rillig ${:U*}= asterisk 50 1.4 rillig .if ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk" 51 1.4 rillig . error 52 1.4 rillig .endif 53 1.4 rillig 54 1.4 rillig all: 55 1.4 rillig @:; 56