| @@ -1,26 +1,53 @@ | | | @@ -1,26 +1,53 @@ |
1 | # $NetBSD: varmod-sysv.mk,v 1.7 2020/10/31 09:03:36 rillig Exp $ | | 1 | # $NetBSD: varmod-sysv.mk,v 1.8 2020/10/31 10:18:32 rillig Exp $ |
2 | # | | 2 | # |
3 | # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix | | 3 | # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix |
4 | # "from" with "to". It can also use '%' as a wildcard. | | 4 | # "from" with "to". It can also use '%' as a wildcard. |
5 | # | | 5 | # |
6 | # This modifier is applied when the other modifiers don't match exactly. | | 6 | # This modifier is applied when the other modifiers don't match exactly. |
7 | # | | 7 | # |
8 | # See ApplyModifier_SysV. | | 8 | # See ApplyModifier_SysV. |
9 | | | 9 | |
10 | all: | | 10 | # A typical use case for the :from=to modifier is conversion of filename |
| | | 11 | # extensions. |
| | | 12 | .if ${src.c:L:.c=.o} != "src.o" |
| | | 13 | . error |
| | | 14 | .endif |
| | | 15 | |
| | | 16 | # The modifier applies to each word on its own. |
| | | 17 | .if ${one.c two.c three.c:L:.c=.o} != "one.o two.o three.o" |
| | | 18 | . error |
| | | 19 | .endif |
| | | 20 | |
| | | 21 | # Words that don't match the pattern are passed unmodified. |
| | | 22 | .if ${src.c src.h:L:.c=.o} != "src.o src.h" |
| | | 23 | . error |
| | | 24 | .endif |
11 | | | 25 | |
12 | # The :Q looks like a modifier but isn't. | | 26 | # The :from=to modifier is therefore often combined with the :M modifier. |
13 | # It is part of the replacement string. | | 27 | .if ${src.c src.h:L:M*.c:.c=.o} != "src.o" |
| | | 28 | . error |
| | | 29 | .endif |
| | | 30 | |
| | | 31 | # Another use case for the :from=to modifier is to append a suffix to each |
| | | 32 | # word. In this case, the "from" string is empty, therefore it always |
| | | 33 | # matches. The same effect can be achieved with the :S,$,teen, modifier. |
| | | 34 | .if ${four six seven nine:L:=teen} != "fourteen sixteen seventeen nineteen" |
| | | 35 | . error |
| | | 36 | .endif |
| | | 37 | |
| | | 38 | # When the :from=to modifier is parsed, it lasts until the closing brace |
| | | 39 | # or parenthesis. The :Q in the below expression may look like a modifier |
| | | 40 | # but isn't. It is part of the replacement string. |
14 | .if ${a b c d e:L:%a=x:Q} != "x:Q b c d e" | | 41 | .if ${a b c d e:L:%a=x:Q} != "x:Q b c d e" |
15 | . error | | 42 | . error |
16 | .endif | | 43 | .endif |
17 | | | 44 | |
18 | # Before 2020-07-19, an ampersand could be used in the replacement part | | 45 | # Before 2020-07-19, an ampersand could be used in the replacement part |
19 | # of a SysV substitution modifier, and it was replaced with the whole match, | | 46 | # of a SysV substitution modifier, and it was replaced with the whole match, |
20 | # just like in the :S modifier. | | 47 | # just like in the :S modifier. |
21 | # | | 48 | # |
22 | # This was probably a copy-and-paste mistake since the code for the SysV | | 49 | # This was probably a copy-and-paste mistake since the code for the SysV |
23 | # modifier looked a lot like the code for the :S and :C modifiers. | | 50 | # modifier looked a lot like the code for the :S and :C modifiers. |
24 | # The ampersand is not mentioned in the manual page. | | 51 | # The ampersand is not mentioned in the manual page. |
25 | .if ${a.bcd.e:L:a.%=%} != "bcd.e" | | 52 | .if ${a.bcd.e:L:a.%=%} != "bcd.e" |
26 | . error | | 53 | . error |
| @@ -117,13 +144,15 @@ all: | | | @@ -117,13 +144,15 @@ all: |
117 | .endif | | 144 | .endif |
118 | | | 145 | |
119 | # As of 2020-10-06, the right-hand side of the SysV modifier is expanded | | 146 | # As of 2020-10-06, the right-hand side of the SysV modifier is expanded |
120 | # twice. The first expansion happens in ApplyModifier_SysV, where the | | 147 | # twice. The first expansion happens in ApplyModifier_SysV, where the |
121 | # modifier is split into its two parts. The second expansion happens | | 148 | # modifier is split into its two parts. The second expansion happens |
122 | # when each word is replaced in ModifyWord_SYSVSubst. | | 149 | # when each word is replaced in ModifyWord_SYSVSubst. |
123 | # XXX: This is unexpected. Add more test case to demonstrate the effects | | 150 | # XXX: This is unexpected. Add more test case to demonstrate the effects |
124 | # of removing one of the expansions. | | 151 | # of removing one of the expansions. |
125 | VALUE= value | | 152 | VALUE= value |
126 | INDIRECT= 1:${VALUE} 2:$${VALUE} 4:$$$${VALUE} | | 153 | INDIRECT= 1:${VALUE} 2:$${VALUE} 4:$$$${VALUE} |
127 | .if ${x:L:x=${INDIRECT}} != "1:value 2:value 4:\${VALUE}" | | 154 | .if ${x:L:x=${INDIRECT}} != "1:value 2:value 4:\${VALUE}" |
128 | . error | | 155 | . error |
129 | .endif | | 156 | .endif |
| | | 157 | |
| | | 158 | all: |