var-op-sunsh.mk revision 1.2 1 1.2 rillig # $NetBSD: var-op-sunsh.mk,v 1.2 2020/10/04 07:49:45 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # Tests for the :sh= variable assignment operator, which runs its right-hand
4 1.1 rillig # side through the shell. It is a seldom-used alternative to the !=
5 1.2 rillig # assignment operator, adopted from Sun make.
6 1.1 rillig
7 1.1 rillig .MAKEFLAGS: -dL # Enable sane error messages
8 1.1 rillig
9 1.1 rillig # This is the idiomatic form of the Sun shell assignment operator.
10 1.1 rillig # The assignment operator is directly preceded by the ':sh'.
11 1.1 rillig VAR:sh= echo colon-sh
12 1.1 rillig .if ${VAR} != "colon-sh"
13 1.1 rillig . error
14 1.1 rillig .endif
15 1.1 rillig
16 1.2 rillig # It is also possible to have whitespace around the :sh assignment
17 1.2 rillig # operator modifier.
18 1.2 rillig VAR :sh = echo colon-sh-spaced
19 1.2 rillig .if ${VAR} != "colon-sh-spaced"
20 1.2 rillig . error
21 1.2 rillig .endif
22 1.2 rillig
23 1.2 rillig # Until 2020-10-04, the ':sh' could even be followed by other characters.
24 1.2 rillig # This was neither documented by NetBSD make nor by Solaris make and was
25 1.2 rillig # an implementation error.
26 1.2 rillig #
27 1.2 rillig # Since 2020-10-04, this is a normal variable assignment using the '='
28 1.2 rillig # assignment operator.
29 1.1 rillig VAR:shell= echo colon-shell
30 1.2 rillig .if ${${:UVAR\:shell}} != "echo colon-shell"
31 1.1 rillig . error
32 1.1 rillig .endif
33 1.1 rillig
34 1.2 rillig # Several colons can syntactically appear in a variable name.
35 1.2 rillig # Until 2020-10-04, the last of them was interpreted as the ':sh'
36 1.2 rillig # assignment operator.
37 1.2 rillig #
38 1.2 rillig # Since 2020-10-04, the colons are part of the variable name.
39 1.1 rillig VAR:shoe:shore= echo two-colons
40 1.2 rillig .if ${${:UVAR\:shoe\:shore}} != "echo two-colons"
41 1.1 rillig . error
42 1.1 rillig .endif
43 1.1 rillig
44 1.2 rillig # Until 2020-10-04, the following expression was wrongly marked as
45 1.2 rillig # a parse error. This was because the parser for variable assignments
46 1.2 rillig # just looked for the previous ":sh", without taking any contextual
47 1.2 rillig # information into account.
48 1.1 rillig #
49 1.1 rillig # There are two different syntactical elements that look exactly the same:
50 1.1 rillig # The variable modifier ':sh' and the assignment operator modifier ':sh'.
51 1.2 rillig # Intuitively this variable name contains the variable modifier, but until
52 1.2 rillig # 2020-10-04, the parser regarded it as an assignment operator modifier, in
53 1.2 rillig # Parse_DoVar.
54 1.2 rillig VAR.${:Uecho 123:sh}= ok-123
55 1.2 rillig .if ${VAR.123} != "ok-123"
56 1.1 rillig . error
57 1.1 rillig .endif
58 1.1 rillig
59 1.2 rillig # Same pattern here. Until 2020-10-04, the ':sh' inside the nested expression
60 1.2 rillig # was taken for the :sh assignment operator modifier, even though it was
61 1.2 rillig # escaped by a backslash.
62 1.2 rillig VAR.${:U echo\:shell}= ok-shell
63 1.2 rillig .if ${VAR.${:U echo\:shell}} != "ok-shell"
64 1.1 rillig . error
65 1.1 rillig .endif
66 1.1 rillig
67 1.2 rillig # Until 2020-10-04, the word 'shift' was also affected since it starts with
68 1.2 rillig # ':sh'.
69 1.2 rillig VAR.key:shift= Shift
70 1.2 rillig .if ${${:UVAR.key\:shift}} != "Shift"
71 1.1 rillig . error
72 1.1 rillig .endif
73 1.1 rillig
74 1.1 rillig all:
75 1.1 rillig @:;
76