varname-dot-make-save_dollars.mk revision 1.4 1 1.4 rillig # $NetBSD: varname-dot-make-save_dollars.mk,v 1.4 2021/11/30 23:58:10 rillig Exp $
2 1.1 rillig #
3 1.3 rillig # Tests for the special .MAKE.SAVE_DOLLARS variable, which controls whether
4 1.3 rillig # the assignment operator ':=' converts '$$' to a single '$' or keeps it
5 1.3 rillig # as-is.
6 1.3 rillig #
7 1.3 rillig # See also:
8 1.3 rillig # var-op-expand.mk
9 1.3 rillig # varmisc.mk for the boolean values
10 1.3 rillig
11 1.3 rillig # Initially, the variable .MAKE.SAVE_DOLLARS is undefined. At this point the
12 1.3 rillig # behavior of the assignment operator ':=' depends. NetBSD's usr.bin/make
13 1.3 rillig # preserves the '$$' as-is, while the bmake distribution replaces '$$' with
14 1.3 rillig # '$'.
15 1.3 rillig .if ${.MAKE.SAVE_DOLLARS:Uundefined} != "undefined"
16 1.3 rillig . error
17 1.3 rillig .endif
18 1.3 rillig
19 1.3 rillig
20 1.3 rillig # Even when dollars are preserved, it only applies to literal dollars, not
21 1.3 rillig # those that come indirectly from other expressions.
22 1.3 rillig .MAKE.SAVE_DOLLARS= yes
23 1.3 rillig DOLLARS= $$$$$$$$
24 1.3 rillig VAR:= ${DOLLARS}
25 1.3 rillig # The reduction from 8 '$' to 4 '$' happens when ${VAR} is evaluated in the
26 1.3 rillig # condition; .MAKE.SAVE_DOLLARS only applies to the operator ':='.
27 1.3 rillig .if ${VAR} != "\$\$\$\$"
28 1.3 rillig . error
29 1.3 rillig .endif
30 1.3 rillig
31 1.3 rillig # Dollars from the literal value are preserved now.
32 1.3 rillig .MAKE.SAVE_DOLLARS= yes
33 1.3 rillig VAR:= $$$$$$$$
34 1.3 rillig .if ${VAR} != "\$\$\$\$"
35 1.3 rillig . error
36 1.3 rillig .endif
37 1.3 rillig
38 1.3 rillig .MAKE.SAVE_DOLLARS= no
39 1.3 rillig VAR:= $$$$$$$$
40 1.3 rillig .if ${VAR} != "\$\$"
41 1.3 rillig . error
42 1.3 rillig .endif
43 1.3 rillig
44 1.3 rillig # It's even possible to change the dollar interpretation in the middle of
45 1.3 rillig # evaluating an expression, even though there is no practical need for it.
46 1.3 rillig .MAKE.SAVE_DOLLARS= no
47 1.3 rillig VAR:= $$$$-${.MAKE.SAVE_DOLLARS::=yes}-$$$$
48 1.3 rillig .if ${VAR} != "\$--\$\$"
49 1.3 rillig . error
50 1.3 rillig .endif
51 1.1 rillig
52 1.3 rillig # The '$' from the ':U' expressions are indirect, therefore SAVE_DOLLARS
53 1.3 rillig # doesn't apply to them.
54 1.4 rillig .MAKE.SAVE_DOLLARS= no
55 1.3 rillig VAR:= ${:U\$\$\$\$}-${.MAKE.SAVE_DOLLARS::=yes}-${:U\$\$\$\$}
56 1.3 rillig .if ${VAR} != "\$\$--\$\$"
57 1.3 rillig . error
58 1.3 rillig .endif
59 1.1 rillig
60 1.4 rillig # Undefining .MAKE.SAVE_DOLLARS does not have any effect, in particular it
61 1.4 rillig # does not restore the default behavior.
62 1.4 rillig .MAKE.SAVE_DOLLARS= no
63 1.4 rillig .undef .MAKE.SAVE_DOLLARS
64 1.4 rillig VAR:= $$$$$$$$
65 1.4 rillig .if ${VAR} != "\$\$"
66 1.4 rillig . error
67 1.4 rillig .endif
68 1.4 rillig
69 1.4 rillig # Undefining .MAKE.SAVE_DOLLARS does not have any effect, in particular it
70 1.4 rillig # does not restore the default behavior.
71 1.4 rillig .MAKE.SAVE_DOLLARS= yes
72 1.4 rillig .undef .MAKE.SAVE_DOLLARS
73 1.4 rillig VAR:= $$$$$$$$
74 1.4 rillig .if ${VAR} != "\$\$\$\$"
75 1.4 rillig . error
76 1.4 rillig .endif
77 1.4 rillig
78 1.1 rillig all:
79