1 1.1 rillig # $NetBSD: var-op-sunsh.mk,v 1.1 2020/10/04 06:53:15 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.1 rillig # assignment operator. 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.1 rillig # XXX: As of 2020-10-04, the ':sh' can even be followed by other characters. 17 1.1 rillig # This is neither documented by NetBSD make nor by Solaris make. 18 1.1 rillig VAR:shell= echo colon-shell 19 1.1 rillig .if ${VAR} != "colon-shell" 20 1.1 rillig . error 21 1.1 rillig .endif 22 1.1 rillig 23 1.1 rillig # XXX: Several colons can syntactically appear in a variable name. 24 1.1 rillig # Neither of these should be interpreted as the ':sh' assignment operator 25 1.1 rillig # modifier. 26 1.1 rillig VAR:shoe:shore= echo two-colons 27 1.1 rillig .if ${VAR${:U\:}shoe} != "two-colons" 28 1.1 rillig . error 29 1.1 rillig .endif 30 1.1 rillig 31 1.1 rillig #.MAKEFLAGS: -dcpv 32 1.1 rillig 33 1.1 rillig # XXX: As of 2020-10-04, the following expression is wrongly marked as 34 1.1 rillig # a parse error. This is caused by the ':sh' modifier. 35 1.1 rillig # 36 1.1 rillig # There are two different syntactical elements that look exactly the same: 37 1.1 rillig # The variable modifier ':sh' and the assignment operator modifier ':sh'. 38 1.1 rillig # Intuitively this variable name contains the variable modifier, but the 39 1.1 rillig # parser sees it as operator modifier, in Parse_DoVar. 40 1.1 rillig # 41 1.1 rillig VAR.${:Uecho 123:sh}= echo oops 42 1.1 rillig .if ${VAR.echo 123} != "oops" 43 1.1 rillig . error 44 1.1 rillig .endif 45 1.1 rillig 46 1.1 rillig # XXX: Same pattern here. The ':sh' inside the nested expression is taken 47 1.1 rillig # for the assignment operator, even though it is escaped by a backslash. 48 1.1 rillig # 49 1.1 rillig VAR.${:U echo\:shell}= echo oops 50 1.1 rillig .if ${VAR.${:U echo\\}} != "oops" 51 1.1 rillig . error 52 1.1 rillig .endif 53 1.1 rillig 54 1.1 rillig # XXX: The word 'shift' is also affected since it starts with ':sh'. 55 1.1 rillig # 56 1.1 rillig VAR.key:shift= echo Shift 57 1.1 rillig .if ${VAR.key} != "Shift" 58 1.1 rillig . error 59 1.1 rillig .endif 60 1.1 rillig 61 1.1 rillig .MAKEFLAGS: -d0 62 1.1 rillig 63 1.1 rillig # XXX: Despite the error messages the exit status is still 0. 64 1.1 rillig 65 1.1 rillig all: 66 1.1 rillig @:; 67