cond-token-plain.mk revision 1.5 1 1.5 rillig # $NetBSD: cond-token-plain.mk,v 1.5 2020/11/09 00:07:06 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for plain tokens (that is, string literals without quotes)
4 1.2 rillig # in .if conditions.
5 1.1 rillig
6 1.3 rillig .MAKEFLAGS: -dc
7 1.3 rillig
8 1.3 rillig .if ${:Uvalue} != value
9 1.3 rillig . error
10 1.3 rillig .endif
11 1.3 rillig
12 1.3 rillig # Malformed condition since comment parsing is done in an early phase
13 1.3 rillig # and removes the '#' and everything behind it long before the condition
14 1.3 rillig # parser gets to see it.
15 1.3 rillig #
16 1.3 rillig # XXX: The error message is missing for this malformed condition.
17 1.3 rillig # The right-hand side of the comparison is just a '"'.
18 1.3 rillig .if ${:U} != "#hash"
19 1.3 rillig . error
20 1.3 rillig .endif
21 1.3 rillig
22 1.3 rillig # To get a '#' into a condition, it has to be escaped using a backslash.
23 1.3 rillig # This prevents the comment parser from removing it, and in turn, it becomes
24 1.3 rillig # visible to CondParser_String.
25 1.3 rillig .if ${:U\#hash} != "\#hash"
26 1.3 rillig . error
27 1.3 rillig .endif
28 1.3 rillig
29 1.3 rillig # Since 2002-12-30, and still as of 2020-09-11, CondParser_Token handles
30 1.3 rillig # the '#' specially, even though at this point, there should be no need for
31 1.3 rillig # comment handling anymore. The comments are supposed to be stripped off
32 1.3 rillig # in a very early parsing phase.
33 1.3 rillig #
34 1.5 rillig # See https://gnats.netbsd.org/19596 for example makefiles demonstrating the
35 1.5 rillig # original problems. This workaround is probably not needed anymore.
36 1.5 rillig #
37 1.3 rillig # XXX: Missing error message for the malformed condition. The right-hand
38 1.3 rillig # side is double-quotes, backslash, backslash.
39 1.3 rillig # XXX: It is unexpected that the right-hand side evaluates to a single
40 1.3 rillig # backslash.
41 1.3 rillig .if ${:U\\} != "\\#hash"
42 1.3 rillig . error
43 1.3 rillig .endif
44 1.3 rillig
45 1.3 rillig # The right-hand side of a comparison is not parsed as a token, therefore
46 1.3 rillig # the code from CondParser_Token does not apply to it.
47 1.3 rillig .if ${:U\#hash} != \#hash
48 1.3 rillig . error
49 1.3 rillig .endif
50 1.3 rillig
51 1.3 rillig # XXX: What is the purpose of treating an escaped '#' in the following
52 1.3 rillig # condition as a comment? And why only at the beginning of a token,
53 1.3 rillig # just as in the shell?
54 1.3 rillig .if 0 \# This is treated as a comment, but why?
55 1.3 rillig . error
56 1.3 rillig .endif
57 1.3 rillig
58 1.3 rillig # Ah, ok, this can be used to add an end-of-condition comment. But does
59 1.3 rillig # anybody really use this? This is neither documented nor obvious since
60 1.3 rillig # the '#' is escaped. It's much clearer to write a comment in the line
61 1.3 rillig # above the condition.
62 1.3 rillig .if ${0 \# comment :?yes:no} != no
63 1.3 rillig . error
64 1.3 rillig .endif
65 1.3 rillig .if ${1 \# comment :?yes:no} != yes
66 1.3 rillig . error
67 1.3 rillig .endif
68 1.1 rillig
69 1.4 rillig # Usually there is whitespace around the comparison operator, but this is
70 1.4 rillig # not required.
71 1.4 rillig .if ${UNDEF:Uundefined}!=undefined
72 1.4 rillig . error
73 1.4 rillig .endif
74 1.4 rillig .if ${UNDEF:U12345}>12345
75 1.4 rillig . error
76 1.4 rillig .endif
77 1.4 rillig .if ${UNDEF:U12345}<12345
78 1.4 rillig . error
79 1.4 rillig .endif
80 1.4 rillig .if (${UNDEF:U0})||0
81 1.4 rillig . error
82 1.4 rillig .endif
83 1.4 rillig
84 1.4 rillig # Only the comparison operator terminates the comparison operand, and it's
85 1.4 rillig # a coincidence that the '!' is both used in the '!=' comparison operator
86 1.4 rillig # as well as for negating a comparison result.
87 1.4 rillig #
88 1.4 rillig # The boolean operators '&' and '|' don't terminate a comparison operand.
89 1.4 rillig .if ${:Uvar}&&name != "var&&name"
90 1.4 rillig . error
91 1.4 rillig .endif
92 1.4 rillig .if ${:Uvar}||name != "var||name"
93 1.4 rillig . error
94 1.4 rillig .endif
95 1.4 rillig
96 1.1 rillig all:
97 1.1 rillig @:;
98