| @@ -1,63 +1,70 @@ | | | @@ -1,63 +1,70 @@ |
1 | # $Id: sysv.mk,v 1.8 2020/07/20 16:27:55 rillig Exp $ | | 1 | # $Id: sysv.mk,v 1.9 2020/07/26 11:19:04 rillig Exp $ |
2 | | | 2 | |
3 | all: foo fun sam bla words ampersand anchor-dollar | | 3 | all: foo fun sam bla words ampersand anchor-dollar |
| | | 4 | all: mismatch |
4 | | | 5 | |
5 | FOO ?= | | 6 | FOO ?= |
6 | FOOBAR = ${FOO:=bar} | | 7 | FOOBAR = ${FOO:=bar} |
7 | | | 8 | |
8 | _this := ${.PARSEDIR}/${.PARSEFILE} | | 9 | _this := ${.PARSEDIR}/${.PARSEFILE} |
9 | | | 10 | |
10 | B = /b | | 11 | B = /b |
11 | S = / | | 12 | S = / |
12 | FUN = ${B}${S}fun | | 13 | FUN = ${B}${S}fun |
13 | SUN = the Sun | | 14 | SUN = the Sun |
14 | | | 15 | |
15 | # we expect nothing when FOO is empty | | 16 | # we expect nothing when FOO is empty |
16 | foo: | | 17 | foo: |
17 | @echo FOOBAR = ${FOOBAR} | | 18 | @echo FOOBAR = ${FOOBAR} |
18 | .if empty(FOO) | | 19 | .if empty(FOO) |
19 | @FOO="foo fu" ${.MAKE} -f ${_this} foo | | 20 | @FOO="foo fu" ${.MAKE} -f ${_this} foo |
20 | .endif | | 21 | .endif |
21 | | | 22 | |
22 | fun: | | 23 | fun: |
23 | @echo ${FUN:T} | | 24 | @echo ${FUN:T} |
24 | @echo ${FUN:${B}${S}fun=fun} | | 25 | @echo ${FUN:${B}${S}fun=fun} |
25 | @echo ${FUN:${B}${S}%=%} | | 26 | @echo ${FUN:${B}${S}%=%} |
26 | @echo ${In:L:%=% ${SUN}} | | 27 | @echo ${In:L:%=% ${SUN}} |
27 | | | 28 | |
28 | | | 29 | |
29 | SAM=sam.c | | 30 | SAM=sam.c |
30 | | | 31 | |
31 | sam: | | 32 | sam: |
32 | @echo ${SAM:s%.c=acme} | | 33 | @echo ${SAM:s%.c=acme} |
33 | @echo ${SAM:s%.c=a%.d} | | 34 | @echo ${SAM:s%.c=a%.d} |
34 | @echo ${SAM:s.c=a%.d} | | 35 | @echo ${SAM:s.c=a%.d} |
35 | @echo ${SAM:sam.c=a%.c} | | 36 | @echo ${SAM:sam.c=a%.c} |
36 | @echo ${SAM:%=a%.c} | | 37 | @echo ${SAM:%=a%.c} |
37 | @echo ${SAM:%.c=a%.c} | | 38 | @echo ${SAM:%.c=a%.c} |
38 | @echo ${SAM:sam%=a%.c} | | 39 | @echo ${SAM:sam%=a%.c} |
39 | | | 40 | |
40 | BLA= | | 41 | BLA= |
41 | | | 42 | |
42 | bla: | | 43 | bla: |
43 | @echo $(BLA:%=foo/%x) | | 44 | @echo $(BLA:%=foo/%x) |
44 | | | 45 | |
45 | # The :Q looks like a modifier but isn't. | | 46 | # The :Q looks like a modifier but isn't. |
46 | # It is part of the replacement string. | | 47 | # It is part of the replacement string. |
47 | words: | | 48 | words: |
48 | @echo a${a b c d e:L:%a=x:Q}b | | 49 | @echo a${a b c d e:L:%a=x:Q}b |
49 | | | 50 | |
50 | # Before 2020-07-19, an ampersand could be used in the replacement part | | 51 | # Before 2020-07-19, an ampersand could be used in the replacement part |
51 | # of a SysV substitution modifier. This was probably a copy-and-paste | | 52 | # of a SysV substitution modifier. This was probably a copy-and-paste |
52 | # mistake since the SysV modifier code looked a lot like the code for the | | 53 | # mistake since the SysV modifier code looked a lot like the code for the |
53 | # :S and :C modifiers. The ampersand is not mentioned in the manual page. | | 54 | # :S and :C modifiers. The ampersand is not mentioned in the manual page. |
54 | ampersand: | | 55 | ampersand: |
55 | @echo ${:U${a.bcd.e:L:a.%=%}:Q} | | 56 | @echo ${:U${a.bcd.e:L:a.%=%}:Q} |
56 | @echo ${:U${a.bcd.e:L:a.%=&}:Q} | | 57 | @echo ${:U${a.bcd.e:L:a.%=&}:Q} |
57 | | | 58 | |
58 | # Before 2020-07-20, when a SysV modifier was parsed, a single dollar | | 59 | # Before 2020-07-20, when a SysV modifier was parsed, a single dollar |
59 | # before the '=' was interpreted as an anchor, which doesn't make sense | | 60 | # before the '=' was interpreted as an anchor, which doesn't make sense |
60 | # since the anchor was discarded immediately. | | 61 | # since the anchor was discarded immediately. |
61 | anchor-dollar: | | 62 | anchor-dollar: |
62 | @echo $@: ${:U${value:L:e$=x}:Q} | | 63 | @echo $@: ${:U${value:L:e$=x}:Q} |
63 | @echo $@: ${:U${value:L:e=x}:Q} | | 64 | @echo $@: ${:U${value:L:e=x}:Q} |
| | | 65 | |
| | | 66 | # Words that don't match are copied unmodified. |
| | | 67 | # The % placeholder can be anywhere in the string. |
| | | 68 | mismatch: |
| | | 69 | @echo $@: ${:Ufile.c file.h:%.c=%.cpp} |
| | | 70 | @echo $@: ${:Ufile.c other.c:file.%=renamed.%} |