Home | History | Annotate | Line # | Download | only in unit-tests
varname-dot-make-save_dollars.mk revision 1.4
      1 # $NetBSD: varname-dot-make-save_dollars.mk,v 1.4 2021/11/30 23:58:10 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
      9 #	varmisc.mk		for 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 # those that come indirectly from other expressions.
     22 .MAKE.SAVE_DOLLARS=	yes
     23 DOLLARS=		$$$$$$$$
     24 VAR:=			${DOLLARS}
     25 # The reduction from 8 '$' to 4 '$' happens when ${VAR} is evaluated in the
     26 # condition; .MAKE.SAVE_DOLLARS only applies to the operator ':='.
     27 .if ${VAR} != "\$\$\$\$"
     28 .  error
     29 .endif
     30 
     31 # Dollars from the literal value are preserved now.
     32 .MAKE.SAVE_DOLLARS=	yes
     33 VAR:=			$$$$$$$$
     34 .if ${VAR} != "\$\$\$\$"
     35 .  error
     36 .endif
     37 
     38 .MAKE.SAVE_DOLLARS=	no
     39 VAR:=			$$$$$$$$
     40 .if ${VAR} != "\$\$"
     41 .  error
     42 .endif
     43 
     44 # It's even possible to change the dollar interpretation in the middle of
     45 # evaluating an expression, even though there is no practical need for it.
     46 .MAKE.SAVE_DOLLARS=	no
     47 VAR:=		$$$$-${.MAKE.SAVE_DOLLARS::=yes}-$$$$
     48 .if ${VAR} != "\$--\$\$"
     49 .  error
     50 .endif
     51 
     52 # The '$' from the ':U' expressions are indirect, therefore SAVE_DOLLARS
     53 # doesn't apply to them.
     54 .MAKE.SAVE_DOLLARS=	no
     55 VAR:=		${:U\$\$\$\$}-${.MAKE.SAVE_DOLLARS::=yes}-${:U\$\$\$\$}
     56 .if ${VAR} != "\$\$--\$\$"
     57 .  error
     58 .endif
     59 
     60 # Undefining .MAKE.SAVE_DOLLARS does not have any effect, in particular it
     61 # does not restore the default behavior.
     62 .MAKE.SAVE_DOLLARS=	no
     63 .undef .MAKE.SAVE_DOLLARS
     64 VAR:=		$$$$$$$$
     65 .if ${VAR} != "\$\$"
     66 .  error
     67 .endif
     68 
     69 # Undefining .MAKE.SAVE_DOLLARS does not have any effect, in particular it
     70 # does not restore the default behavior.
     71 .MAKE.SAVE_DOLLARS=	yes
     72 .undef .MAKE.SAVE_DOLLARS
     73 VAR:=		$$$$$$$$
     74 .if ${VAR} != "\$\$\$\$"
     75 .  error
     76 .endif
     77 
     78 all:
     79