varmod.mk revision 1.6 1 1.6 rillig # $NetBSD: varmod.mk,v 1.6 2022/08/06 07:06:58 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback.
4 1.1 rillig
5 1.6 rillig # As of 2022-08-06, the possible behaviors during parsing are:
6 1.6 rillig #
7 1.6 rillig # * `strict`: the parsing style used by most modifiers:
8 1.6 rillig # * either uses `ParseModifierPart` or parses the modifier literal
9 1.6 rillig # * other modifiers may follow, separated by a ':'
10 1.6 rillig #
11 1.6 rillig # * `greedy`: calls `ParseModifierPart` with `ch->endc`; this means
12 1.6 rillig # that no further modifiers are parsed in that expression.
13 1.6 rillig #
14 1.6 rillig # * `no-colon`: after parsing this modifier, the following modifier
15 1.6 rillig # does not need to be separated by a colon.
16 1.6 rillig # Omitting this colon is bad style.
17 1.6 rillig #
18 1.6 rillig # * `individual`: parsing this modifier does not follow the common
19 1.6 rillig # pattern of calling `ParseModifierPart`.
20 1.6 rillig #
21 1.6 rillig # The SysV column says whether a parse error in the modifier falls back
22 1.6 rillig # trying the `:from=to` System V modifier.
23 1.6 rillig #
24 1.6 rillig # | **Operator** | **Behavior** | **Remarks** | **SysV** |
25 1.6 rillig # |--------------|--------------|--------------------|----------|
26 1.6 rillig # | `!` | no-colon | | no |
27 1.6 rillig # | `:=` | greedy | | yes |
28 1.6 rillig # | `?:` | greedy | | no |
29 1.6 rillig # | `@` | no-colon | | no |
30 1.6 rillig # | `C` | no-colon | | no |
31 1.6 rillig # | `D` | individual | custom parser | N/A |
32 1.6 rillig # | `E` | strict | | yes |
33 1.6 rillig # | `H` | strict | | yes |
34 1.6 rillig # | `L` | no-colon | | N/A |
35 1.6 rillig # | `M` | individual | custom parser | N/A |
36 1.6 rillig # | `N` | individual | custom parser | N/A |
37 1.6 rillig # | `O` | strict | only literal value | no |
38 1.6 rillig # | `P` | no-colon | | N/A |
39 1.6 rillig # | `Q` | strict | | yes |
40 1.6 rillig # | `R` | strict | | yes |
41 1.6 rillig # | `S` | no-colon | | N/A |
42 1.6 rillig # | `T` | strict | | N/A |
43 1.6 rillig # | `U` | individual | custom parser | N/A |
44 1.6 rillig # | `[` | strict | | no |
45 1.6 rillig # | `_` | individual | strcspn | yes |
46 1.6 rillig # | `gmtime` | strict | only literal value | yes |
47 1.6 rillig # | `hash` | strict | | N/A |
48 1.6 rillig # | `localtime` | strict | only literal value | yes |
49 1.6 rillig # | `q` | strict | | yes |
50 1.6 rillig # | `range` | strict | | N/A |
51 1.6 rillig # | `sh` | strict | | N/A |
52 1.6 rillig # | `t` | strict | | no |
53 1.6 rillig # | `u` | strict | | yes |
54 1.6 rillig # | `from=to` | greedy | SysV, fallback | N/A |
55 1.6 rillig
56 1.3 rillig DOLLAR1= $$
57 1.3 rillig DOLLAR2= ${:U\$}
58 1.1 rillig
59 1.3 rillig # To get a single '$' sign in the value of a variable expression, it has to
60 1.3 rillig # be written as '$$' in a literal variable value.
61 1.3 rillig #
62 1.3 rillig # See Var_Parse, where it calls Var_Subst.
63 1.3 rillig .if ${DOLLAR1} != "\$"
64 1.3 rillig . error
65 1.3 rillig .endif
66 1.3 rillig
67 1.3 rillig # Another way to get a single '$' sign is to use the :U modifier. In the
68 1.3 rillig # argument of that modifier, a '$' is escaped using the backslash instead.
69 1.3 rillig #
70 1.3 rillig # See Var_Parse, where it calls Var_Subst.
71 1.3 rillig .if ${DOLLAR2} != "\$"
72 1.3 rillig . error
73 1.3 rillig .endif
74 1.3 rillig
75 1.3 rillig # It is also possible to use the :U modifier directly in the expression.
76 1.3 rillig #
77 1.3 rillig # See Var_Parse, where it calls Var_Subst.
78 1.3 rillig .if ${:U\$} != "\$"
79 1.3 rillig . error
80 1.3 rillig .endif
81 1.3 rillig
82 1.3 rillig # XXX: As of 2020-09-13, it is not possible to use '$$' in a variable name
83 1.3 rillig # to mean a single '$'. This contradicts the manual page, which says that
84 1.3 rillig # '$' can be escaped as '$$'.
85 1.3 rillig .if ${$$:L} != ""
86 1.3 rillig . error
87 1.3 rillig .endif
88 1.3 rillig
89 1.3 rillig # In lint mode, make prints helpful error messages.
90 1.3 rillig # For compatibility, make does not print these error messages in normal mode.
91 1.3 rillig # Should it?
92 1.3 rillig .MAKEFLAGS: -dL
93 1.3 rillig .if ${$$:L} != ""
94 1.3 rillig . error
95 1.3 rillig .endif
96 1.3 rillig
97 1.3 rillig # A '$' followed by nothing is an error as well.
98 1.3 rillig .if ${:Uword:@word@${word}$@} != "word"
99 1.3 rillig . error
100 1.3 rillig .endif
101 1.3 rillig
102 1.4 rillig # The variable modifier :P does not fall back to the SysV modifier.
103 1.4 rillig # Therefore the modifier :P=RE generates a parse error.
104 1.4 rillig # XXX: The .error should not be reached since the variable expression is
105 1.5 rillig # malformed, and this error should be propagated up to Cond_EvalLine.
106 1.4 rillig VAR= STOP
107 1.4 rillig .if ${VAR:P=RE} != "STORE"
108 1.4 rillig . error
109 1.4 rillig .endif
110 1.4 rillig
111 1.3 rillig all: # nothing
112