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