varmod-sysv.mk revision 1.8 1 1.8 rillig # $NetBSD: varmod-sysv.mk,v 1.8 2020/10/31 10:18:32 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix
4 1.2 rillig # "from" with "to". It can also use '%' as a wildcard.
5 1.2 rillig #
6 1.2 rillig # This modifier is applied when the other modifiers don't match exactly.
7 1.6 rillig #
8 1.6 rillig # See ApplyModifier_SysV.
9 1.1 rillig
10 1.8 rillig # A typical use case for the :from=to modifier is conversion of filename
11 1.8 rillig # extensions.
12 1.8 rillig .if ${src.c:L:.c=.o} != "src.o"
13 1.8 rillig . error
14 1.8 rillig .endif
15 1.8 rillig
16 1.8 rillig # The modifier applies to each word on its own.
17 1.8 rillig .if ${one.c two.c three.c:L:.c=.o} != "one.o two.o three.o"
18 1.8 rillig . error
19 1.8 rillig .endif
20 1.8 rillig
21 1.8 rillig # Words that don't match the pattern are passed unmodified.
22 1.8 rillig .if ${src.c src.h:L:.c=.o} != "src.o src.h"
23 1.8 rillig . error
24 1.8 rillig .endif
25 1.8 rillig
26 1.8 rillig # The :from=to modifier is therefore often combined with the :M modifier.
27 1.8 rillig .if ${src.c src.h:L:M*.c:.c=.o} != "src.o"
28 1.8 rillig . error
29 1.8 rillig .endif
30 1.8 rillig
31 1.8 rillig # Another use case for the :from=to modifier is to append a suffix to each
32 1.8 rillig # word. In this case, the "from" string is empty, therefore it always
33 1.8 rillig # matches. The same effect can be achieved with the :S,$,teen, modifier.
34 1.8 rillig .if ${four six seven nine:L:=teen} != "fourteen sixteen seventeen nineteen"
35 1.8 rillig . error
36 1.8 rillig .endif
37 1.1 rillig
38 1.8 rillig # When the :from=to modifier is parsed, it lasts until the closing brace
39 1.8 rillig # or parenthesis. The :Q in the below expression may look like a modifier
40 1.8 rillig # but isn't. It is part of the replacement string.
41 1.4 rillig .if ${a b c d e:L:%a=x:Q} != "x:Q b c d e"
42 1.4 rillig . error
43 1.4 rillig .endif
44 1.3 rillig
45 1.3 rillig # Before 2020-07-19, an ampersand could be used in the replacement part
46 1.4 rillig # of a SysV substitution modifier, and it was replaced with the whole match,
47 1.4 rillig # just like in the :S modifier.
48 1.4 rillig #
49 1.4 rillig # This was probably a copy-and-paste mistake since the code for the SysV
50 1.4 rillig # modifier looked a lot like the code for the :S and :C modifiers.
51 1.4 rillig # The ampersand is not mentioned in the manual page.
52 1.4 rillig .if ${a.bcd.e:L:a.%=%} != "bcd.e"
53 1.4 rillig . error
54 1.4 rillig .endif
55 1.4 rillig # Before 2020-07-19, the result of the expression was "a.bcd.e".
56 1.4 rillig .if ${a.bcd.e:L:a.%=&} != "&"
57 1.4 rillig . error
58 1.4 rillig .endif
59 1.3 rillig
60 1.3 rillig # Before 2020-07-20, when a SysV modifier was parsed, a single dollar
61 1.4 rillig # before the '=' was parsed (but not interpreted) as an anchor.
62 1.4 rillig # Parsing something without then evaluating it accordingly doesn't make
63 1.4 rillig # sense.
64 1.4 rillig .if ${value:L:e$=x} != "value"
65 1.4 rillig . error
66 1.4 rillig .endif
67 1.4 rillig # Before 2020-07-20, the modifier ":e$=x" was parsed as having a left-hand
68 1.4 rillig # side "e" and a right-hand side "x". The dollar was parsed (but not
69 1.4 rillig # interpreted) as 'anchor at the end'. Therefore the modifier was equivalent
70 1.4 rillig # to ":e=x", which doesn't match the string "value$". Therefore the whole
71 1.4 rillig # expression evaluated to "value$".
72 1.4 rillig .if ${${:Uvalue\$}:L:e$=x} != "valux"
73 1.4 rillig . error
74 1.4 rillig .endif
75 1.4 rillig .if ${value:L:e=x} != "valux"
76 1.4 rillig . error
77 1.4 rillig .endif
78 1.3 rillig
79 1.3 rillig # Words that don't match are copied unmodified.
80 1.4 rillig .if ${:Ufile.c file.h:%.c=%.cpp} != "file.cpp file.h"
81 1.4 rillig . error
82 1.4 rillig .endif
83 1.4 rillig
84 1.4 rillig # The % placeholder can be anywhere in the string, it doesn't have to be at
85 1.4 rillig # the beginning of the pattern.
86 1.4 rillig .if ${:Ufile.c other.c:file.%=renamed.%} != "renamed.c other.c"
87 1.4 rillig . error
88 1.4 rillig .endif
89 1.3 rillig
90 1.7 rillig # Each word gets the suffix "X" appended.
91 1.7 rillig .if ${one two:L:=X} != "oneX twoX"
92 1.7 rillig . error
93 1.7 rillig .endif
94 1.7 rillig
95 1.6 rillig # The suffix "o" is replaced with "X".
96 1.6 rillig .if ${one two:L:o=X} != "one twX"
97 1.4 rillig . error
98 1.4 rillig .endif
99 1.6 rillig
100 1.6 rillig # The suffix "o" is replaced with nothing.
101 1.6 rillig .if ${one two:L:o=} != "one tw"
102 1.4 rillig . error
103 1.4 rillig .endif
104 1.6 rillig
105 1.6 rillig # The suffix "o" is replaced with a literal percent. The percent is only
106 1.6 rillig # a wildcard when it appears on the left-hand side.
107 1.6 rillig .if ${one two:L:o=%} != "one tw%"
108 1.4 rillig . error
109 1.4 rillig .endif
110 1.6 rillig
111 1.6 rillig # Each word with the suffix "o" is replaced with "X". The percent is a
112 1.6 rillig # wildcard even though the right-hand side does not contain another percent.
113 1.6 rillig .if ${one two:L:%o=X} != "one X"
114 1.4 rillig . error
115 1.4 rillig .endif
116 1.6 rillig
117 1.6 rillig # Each word with the prefix "o" is replaced with "X". The percent is a
118 1.6 rillig # wildcard even though the right-hand side does not contain another percent.
119 1.6 rillig .if ${one two:L:o%=X} != "X two"
120 1.4 rillig . error
121 1.4 rillig .endif
122 1.6 rillig
123 1.6 rillig # For each word with the prefix "o" and the suffix "e", the whole word is
124 1.6 rillig # replaced with "X".
125 1.6 rillig .if ${one two oe oxen:L:o%e=X} != "X two X oxen"
126 1.4 rillig . error
127 1.4 rillig .endif
128 1.6 rillig
129 1.6 rillig # Only the first '%' is the wildcard.
130 1.6 rillig .if ${one two o%e other%e:L:o%%e=X} != "one two X X"
131 1.4 rillig . error
132 1.4 rillig .endif
133 1.6 rillig
134 1.6 rillig # In the replacement, only the first '%' is the placeholder, all others
135 1.6 rillig # are literal percent characters.
136 1.6 rillig .if ${one two:L:%=%%} != "one% two%"
137 1.4 rillig . error
138 1.4 rillig .endif
139 1.6 rillig
140 1.6 rillig # In the word "one", only a prefix of the pattern suffix "nes" matches,
141 1.6 rillig # the whole word is too short. Therefore it doesn't match.
142 1.6 rillig .if ${one two:L:%nes=%xxx} != "one two"
143 1.4 rillig . error
144 1.3 rillig .endif
145 1.5 rillig
146 1.5 rillig # As of 2020-10-06, the right-hand side of the SysV modifier is expanded
147 1.5 rillig # twice. The first expansion happens in ApplyModifier_SysV, where the
148 1.5 rillig # modifier is split into its two parts. The second expansion happens
149 1.5 rillig # when each word is replaced in ModifyWord_SYSVSubst.
150 1.5 rillig # XXX: This is unexpected. Add more test case to demonstrate the effects
151 1.5 rillig # of removing one of the expansions.
152 1.5 rillig VALUE= value
153 1.5 rillig INDIRECT= 1:${VALUE} 2:$${VALUE} 4:$$$${VALUE}
154 1.5 rillig .if ${x:L:x=${INDIRECT}} != "1:value 2:value 4:\${VALUE}"
155 1.5 rillig . error
156 1.5 rillig .endif
157 1.8 rillig
158 1.8 rillig all:
159