Home | History | Annotate | Line # | Download | only in unit-tests
varmod.mk revision 1.4
      1  1.4  rillig # $NetBSD: varmod.mk,v 1.4 2020/11/02 17:30:22 rillig Exp $
      2  1.1  rillig #
      3  1.2  rillig # Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback.
      4  1.1  rillig 
      5  1.3  rillig DOLLAR1=	$$
      6  1.3  rillig DOLLAR2=	${:U\$}
      7  1.1  rillig 
      8  1.3  rillig # To get a single '$' sign in the value of a variable expression, it has to
      9  1.3  rillig # be written as '$$' in a literal variable value.
     10  1.3  rillig #
     11  1.3  rillig # See Var_Parse, where it calls Var_Subst.
     12  1.3  rillig .if ${DOLLAR1} != "\$"
     13  1.3  rillig .  error
     14  1.3  rillig .endif
     15  1.3  rillig 
     16  1.3  rillig # Another way to get a single '$' sign is to use the :U modifier.  In the
     17  1.3  rillig # argument of that modifier, a '$' is escaped using the backslash instead.
     18  1.3  rillig #
     19  1.3  rillig # See Var_Parse, where it calls Var_Subst.
     20  1.3  rillig .if ${DOLLAR2} != "\$"
     21  1.3  rillig .  error
     22  1.3  rillig .endif
     23  1.3  rillig 
     24  1.3  rillig # It is also possible to use the :U modifier directly in the expression.
     25  1.3  rillig #
     26  1.3  rillig # See Var_Parse, where it calls Var_Subst.
     27  1.3  rillig .if ${:U\$} != "\$"
     28  1.3  rillig .  error
     29  1.3  rillig .endif
     30  1.3  rillig 
     31  1.3  rillig # XXX: As of 2020-09-13, it is not possible to use '$$' in a variable name
     32  1.3  rillig # to mean a single '$'.  This contradicts the manual page, which says that
     33  1.3  rillig # '$' can be escaped as '$$'.
     34  1.3  rillig .if ${$$:L} != ""
     35  1.3  rillig .  error
     36  1.3  rillig .endif
     37  1.3  rillig 
     38  1.3  rillig # In lint mode, make prints helpful error messages.
     39  1.3  rillig # For compatibility, make does not print these error messages in normal mode.
     40  1.3  rillig # Should it?
     41  1.3  rillig .MAKEFLAGS: -dL
     42  1.3  rillig .if ${$$:L} != ""
     43  1.3  rillig .  error
     44  1.3  rillig .endif
     45  1.3  rillig 
     46  1.3  rillig # A '$' followed by nothing is an error as well.
     47  1.3  rillig .if ${:Uword:@word@${word}$@} != "word"
     48  1.3  rillig .  error
     49  1.3  rillig .endif
     50  1.3  rillig 
     51  1.4  rillig # The variable modifier :P does not fall back to the SysV modifier.
     52  1.4  rillig # Therefore the modifier :P=RE generates a parse error.
     53  1.4  rillig # XXX: The .error should not be reached since the variable expression is
     54  1.4  rillig # malformed.
     55  1.4  rillig VAR=	STOP
     56  1.4  rillig .if ${VAR:P=RE} != "STORE"
     57  1.4  rillig .  error
     58  1.4  rillig .endif
     59  1.4  rillig 
     60  1.3  rillig all: # nothing
     61