varname-dot-make-save_dollars.mk revision 1.5 1 1.5 rillig # $NetBSD: varname-dot-make-save_dollars.mk,v 1.5 2021/12/01 23:15:38 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.5 rillig # var-op-expand.mk for ':=' in general
9 1.5 rillig # varmisc.mk for parsing 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.5 rillig # to those that come indirectly from other expressions.
22 1.5 rillig DOLLARS= $$$$$$$$
23 1.3 rillig .MAKE.SAVE_DOLLARS= yes
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.5 rillig # condition; .MAKE.SAVE_DOLLARS only applies at the moment where the
27 1.5 rillig # assignment is performed using ':='.
28 1.3 rillig .if ${VAR} != "\$\$\$\$"
29 1.3 rillig . error
30 1.3 rillig .endif
31 1.3 rillig
32 1.5 rillig # The 'yes' preserves the dollars from the literal.
33 1.3 rillig .MAKE.SAVE_DOLLARS= yes
34 1.3 rillig VAR:= $$$$$$$$
35 1.3 rillig .if ${VAR} != "\$\$\$\$"
36 1.3 rillig . error
37 1.3 rillig .endif
38 1.3 rillig
39 1.5 rillig # The 'no' converts each '$$' to '$'.
40 1.3 rillig .MAKE.SAVE_DOLLARS= no
41 1.3 rillig VAR:= $$$$$$$$
42 1.3 rillig .if ${VAR} != "\$\$"
43 1.3 rillig . error
44 1.3 rillig .endif
45 1.3 rillig
46 1.3 rillig # It's even possible to change the dollar interpretation in the middle of
47 1.5 rillig # evaluating an expression, but there is no practical need for it.
48 1.3 rillig .MAKE.SAVE_DOLLARS= no
49 1.3 rillig VAR:= $$$$-${.MAKE.SAVE_DOLLARS::=yes}-$$$$
50 1.3 rillig .if ${VAR} != "\$--\$\$"
51 1.3 rillig . error
52 1.3 rillig .endif
53 1.1 rillig
54 1.5 rillig # The '$' from the ':U' expressions are indirect, therefore .MAKE.SAVE_DOLLARS
55 1.3 rillig # doesn't apply to them.
56 1.4 rillig .MAKE.SAVE_DOLLARS= no
57 1.3 rillig VAR:= ${:U\$\$\$\$}-${.MAKE.SAVE_DOLLARS::=yes}-${:U\$\$\$\$}
58 1.3 rillig .if ${VAR} != "\$\$--\$\$"
59 1.3 rillig . error
60 1.3 rillig .endif
61 1.1 rillig
62 1.4 rillig # Undefining .MAKE.SAVE_DOLLARS does not have any effect, in particular it
63 1.4 rillig # does not restore the default behavior.
64 1.4 rillig .MAKE.SAVE_DOLLARS= no
65 1.4 rillig .undef .MAKE.SAVE_DOLLARS
66 1.4 rillig VAR:= $$$$$$$$
67 1.4 rillig .if ${VAR} != "\$\$"
68 1.4 rillig . error
69 1.4 rillig .endif
70 1.4 rillig
71 1.4 rillig # Undefining .MAKE.SAVE_DOLLARS does not have any effect, in particular it
72 1.4 rillig # does not restore the default behavior.
73 1.4 rillig .MAKE.SAVE_DOLLARS= yes
74 1.4 rillig .undef .MAKE.SAVE_DOLLARS
75 1.4 rillig VAR:= $$$$$$$$
76 1.4 rillig .if ${VAR} != "\$\$\$\$"
77 1.4 rillig . error
78 1.4 rillig .endif
79 1.4 rillig
80 1.1 rillig all:
81