Home | History | Annotate | Line # | Download | only in unit-tests
      1  1.7  rillig # $NetBSD: varname-dot-make-save_dollars.mk,v 1.7 2021/12/03 18:43:52 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.6  rillig # When dollars are preserved, this setting not only applies to literal
     21  1.6  rillig # dollars, but also 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.6  rillig # When dollars are preserved, this setting not only applies to literal
     33  1.6  rillig # dollars, but also to those that come indirectly from other expressions.
     34  1.6  rillig DOLLARS=		$$$$$$$$
     35  1.6  rillig .MAKE.SAVE_DOLLARS=	no
     36  1.6  rillig VAR:=			${DOLLARS}
     37  1.6  rillig .if ${VAR} != "\$\$"
     38  1.6  rillig .  error
     39  1.6  rillig .endif
     40  1.6  rillig 
     41  1.5  rillig # The 'yes' preserves the dollars from the literal.
     42  1.3  rillig .MAKE.SAVE_DOLLARS=	yes
     43  1.3  rillig VAR:=			$$$$$$$$
     44  1.3  rillig .if ${VAR} != "\$\$\$\$"
     45  1.3  rillig .  error
     46  1.3  rillig .endif
     47  1.3  rillig 
     48  1.5  rillig # The 'no' converts each '$$' to '$'.
     49  1.3  rillig .MAKE.SAVE_DOLLARS=	no
     50  1.3  rillig VAR:=			$$$$$$$$
     51  1.3  rillig .if ${VAR} != "\$\$"
     52  1.3  rillig .  error
     53  1.3  rillig .endif
     54  1.3  rillig 
     55  1.3  rillig # It's even possible to change the dollar interpretation in the middle of
     56  1.5  rillig # evaluating an expression, but there is no practical need for it.
     57  1.3  rillig .MAKE.SAVE_DOLLARS=	no
     58  1.3  rillig VAR:=		$$$$-${.MAKE.SAVE_DOLLARS::=yes}-$$$$
     59  1.3  rillig .if ${VAR} != "\$--\$\$"
     60  1.3  rillig .  error
     61  1.3  rillig .endif
     62  1.1  rillig 
     63  1.6  rillig # The '$' from the ':U' expressions do not appear as literal '$$' to the
     64  1.6  rillig # parser (no matter whether directly or indirectly), they only appear as '$$'
     65  1.6  rillig # in the value of an expression, therefore .MAKE.SAVE_DOLLARS doesn't apply
     66  1.6  rillig # here.
     67  1.4  rillig .MAKE.SAVE_DOLLARS=	no
     68  1.3  rillig VAR:=		${:U\$\$\$\$}-${.MAKE.SAVE_DOLLARS::=yes}-${:U\$\$\$\$}
     69  1.3  rillig .if ${VAR} != "\$\$--\$\$"
     70  1.3  rillig .  error
     71  1.3  rillig .endif
     72  1.1  rillig 
     73  1.4  rillig # Undefining .MAKE.SAVE_DOLLARS does not have any effect, in particular it
     74  1.4  rillig # does not restore the default behavior.
     75  1.4  rillig .MAKE.SAVE_DOLLARS=	no
     76  1.4  rillig .undef .MAKE.SAVE_DOLLARS
     77  1.4  rillig VAR:=		$$$$$$$$
     78  1.4  rillig .if ${VAR} != "\$\$"
     79  1.4  rillig .  error
     80  1.4  rillig .endif
     81  1.4  rillig 
     82  1.4  rillig # Undefining .MAKE.SAVE_DOLLARS does not have any effect, in particular it
     83  1.4  rillig # does not restore the default behavior.
     84  1.4  rillig .MAKE.SAVE_DOLLARS=	yes
     85  1.4  rillig .undef .MAKE.SAVE_DOLLARS
     86  1.4  rillig VAR:=		$$$$$$$$
     87  1.4  rillig .if ${VAR} != "\$\$\$\$"
     88  1.4  rillig .  error
     89  1.4  rillig .endif
     90  1.4  rillig 
     91  1.6  rillig # The variable '.MAKE.SAVE_DOLLARS' not only affects literal '$$' on the
     92  1.6  rillig # right-hand side of the assignment operator ':=', it also affects dollars
     93  1.6  rillig # in indirect expressions.
     94  1.6  rillig #
     95  1.6  rillig # In this example, it affects the command in CMD itself, not the result of
     96  1.6  rillig # running that command.
     97  1.6  rillig .MAKE.SAVE_DOLLARS=	no
     98  1.6  rillig CMD=			echo '$$$$$$$$'
     99  1.6  rillig VAR:=			${CMD:sh}
    100  1.6  rillig .if ${VAR} != "\$\$"
    101  1.6  rillig .  error
    102  1.6  rillig .endif
    103  1.6  rillig 
    104  1.6  rillig .MAKE.SAVE_DOLLARS=	yes
    105  1.6  rillig CMD=			echo '$$$$$$$$'
    106  1.6  rillig VAR:=			${CMD:sh}
    107  1.6  rillig .if ${VAR} != "\$\$\$\$"
    108  1.6  rillig .  error
    109  1.6  rillig .endif
    110  1.6  rillig 
    111  1.7  rillig 
    112  1.7  rillig # In the modifier ':@var@body@', .MAKE.SAVE_DOLLARS does not affect the body.
    113  1.7  rillig # In both cases, each '$$' is replaced with a single '$', no matter whether
    114  1.7  rillig # directly or indirectly via another expression.
    115  1.7  rillig .MAKE.SAVE_DOLLARS=	no
    116  1.7  rillig DOLLARS=		$$$$$$$$
    117  1.7  rillig VAR:=			${word:L:@word@$$$$$$$$-${DOLLARS}@}
    118  1.7  rillig .if ${VAR} != "\$\$-\$\$"
    119  1.7  rillig .  error
    120  1.7  rillig .endif
    121  1.7  rillig 
    122  1.7  rillig .MAKE.SAVE_DOLLARS=	yes
    123  1.7  rillig DOLLARS=		$$$$$$$$
    124  1.7  rillig VAR:=			${word:L:@word@$$$$$$$$-${DOLLARS}@}
    125  1.7  rillig .if ${VAR} != "\$\$-\$\$"
    126  1.7  rillig .  error
    127  1.7  rillig .endif
    128  1.7  rillig 
    129  1.7  rillig 
    130  1.1  rillig all:
    131