Home | History | Annotate | Line # | Download | only in unit-tests
deptgt-makeflags.mk revision 1.5
      1  1.5  rillig # $NetBSD: deptgt-makeflags.mk,v 1.5 2020/11/08 02:31:24 rillig Exp $
      2  1.1  rillig #
      3  1.3  rillig # Tests for the special target .MAKEFLAGS in dependency declarations,
      4  1.3  rillig # which adds command line options later, at parse time.
      5  1.1  rillig 
      6  1.3  rillig # The -D option sets a variable in the "Global" scope and thus can be
      7  1.3  rillig # undefined later.
      8  1.3  rillig .MAKEFLAGS: -D VAR
      9  1.3  rillig .if ${VAR} != 1
     10  1.3  rillig .  error
     11  1.3  rillig .endif
     12  1.3  rillig 
     13  1.5  rillig # Variables that are set via the -D command line option are normal global
     14  1.5  rillig # variables and can thus be undefined later.
     15  1.3  rillig .undef VAR
     16  1.3  rillig .if defined(VAR)
     17  1.3  rillig .  error
     18  1.3  rillig .endif
     19  1.3  rillig 
     20  1.5  rillig # The -D command line option can define a variable again, after it has been
     21  1.5  rillig # undefined.
     22  1.3  rillig .MAKEFLAGS: -D VAR
     23  1.3  rillig .if ${VAR} != 1
     24  1.3  rillig .  error
     25  1.3  rillig .endif
     26  1.3  rillig 
     27  1.5  rillig # The "dependency" for .MAKEFLAGS is split into words, interpreting the usual
     28  1.5  rillig # quotes and escape sequences from the backslash.
     29  1.3  rillig .MAKEFLAGS: VAR="value"' with'\ spaces
     30  1.3  rillig .if ${VAR} != "value with spaces"
     31  1.3  rillig .  error
     32  1.3  rillig .endif
     33  1.3  rillig 
     34  1.3  rillig # Variables set on the command line as VAR=value are placed in the
     35  1.3  rillig # "Command" scope and thus cannot be undefined.
     36  1.3  rillig .undef VAR
     37  1.3  rillig .if ${VAR} != "value with spaces"
     38  1.3  rillig .  error
     39  1.3  rillig .endif
     40  1.1  rillig 
     41  1.4  rillig # When parsing this line, each '$$' becomes '$', resulting in '$$$$'.
     42  1.4  rillig # This is assigned to the variable DOLLAR.
     43  1.4  rillig # In the condition, that variable is expanded, and at that point, each '$$'
     44  1.4  rillig # becomes '$' again, the final expression is thus '$$'.
     45  1.4  rillig .MAKEFLAGS: -dcv
     46  1.4  rillig .MAKEFLAGS: DOLLAR=$$$$$$$$
     47  1.4  rillig .if ${DOLLAR} != "\$\$"
     48  1.4  rillig .endif
     49  1.4  rillig .MAKEFLAGS: -d0
     50  1.4  rillig 
     51  1.5  rillig # An empty command line is skipped.
     52  1.5  rillig .MAKEFLAGS: # none
     53  1.5  rillig 
     54  1.5  rillig # Escape sequences like \n are interpreted.
     55  1.5  rillig # The following line looks as if it assigned a newline to nl, but it doesn't.
     56  1.5  rillig # Instead, the \n ends up as a line that is then interpreted as a variable
     57  1.5  rillig # assignment.  At that point, the line is simply "nl=\n", and the \n is
     58  1.5  rillig # skipped since it is whitespace (see Parse_IsVar).
     59  1.5  rillig .MAKEFLAGS: nl="\n"
     60  1.5  rillig .if ${nl} != ""
     61  1.5  rillig .  error
     62  1.5  rillig .endif
     63  1.5  rillig 
     64  1.5  rillig # Next try at defining another newline variable.  Since whitespace around the
     65  1.5  rillig # variable value is trimmed, two empty variable expressions surround the
     66  1.5  rillig # literal newline now.  This prevents the newline from being skipped during
     67  1.5  rillig # parsing.  The ':=' assignment operator expands the empty variable
     68  1.5  rillig # expressions, leaving only the newline as the variable value.
     69  1.5  rillig #
     70  1.5  rillig # This is one of the very few ways (maybe even the only one) to inject literal
     71  1.5  rillig # newlines into a line that is being parsed.  This may confuse the parser.
     72  1.5  rillig # For example, in cond.c the parser only expects horizontal whitespace (' '
     73  1.5  rillig # and '\t'), but no newlines.
     74  1.5  rillig #.MAKEFLAGS: -dcpv
     75  1.5  rillig .MAKEFLAGS: nl:="$${:U}\n$${:U}"
     76  1.5  rillig .if ${nl} != ${.newline}
     77  1.5  rillig .  error
     78  1.5  rillig .endif
     79  1.5  rillig #.MAKEFLAGS: -d0
     80  1.5  rillig 
     81  1.5  rillig # Unbalanced quotes produce an error message.  If they occur anywhere in the
     82  1.5  rillig # command line, the whole command line is skipped.
     83  1.5  rillig .MAKEFLAGS: VAR=previous
     84  1.5  rillig .MAKEFLAGS: VAR=initial UNBALANCED='
     85  1.5  rillig .if ${VAR} != "previous"
     86  1.5  rillig .  error
     87  1.5  rillig .endif
     88  1.5  rillig 
     89  1.1  rillig all:
     90  1.1  rillig 	@:;
     91