1 # $NetBSD: deptgt-makeflags.mk,v 1.6 2020/11/15 20:20:58 rillig Exp $
3 # Tests for the special target .MAKEFLAGS in dependency declarations,
4 # which adds command line options later, at parse time.
6 # In these unit tests, it is often used to temporarily toggle the debug log
9 # The -D option sets a variable in the "Global" scope and thus can be
16 # Variables that are set via the -D command line option are normal global
17 # variables and can thus be undefined later.
23 # The -D command line option can define a variable again, after it has been
30 # The "dependency" for .MAKEFLAGS is split into words, interpreting the usual
31 # quotes and escape sequences from the backslash.
32 .MAKEFLAGS: VAR="value"' with'\ spaces
33 .if ${VAR} != "value with spaces"
37 # Variables set on the command line as VAR=value are placed in the
38 # "Command" scope and thus cannot be undefined.
40 .if ${VAR} != "value with spaces"
44 # When parsing this line, each '$$' becomes '$', resulting in '$$$$'.
45 # This is assigned to the variable DOLLAR.
46 # In the condition, that variable is expanded, and at that point, each '$$'
47 # becomes '$' again, the final expression is thus '$$'.
49 .MAKEFLAGS: DOLLAR=$$$$$$$$
50 .if ${DOLLAR} != "\$\$"
54 # An empty command line is skipped.
57 # Escape sequences like \n are interpreted.
58 # The following line looks as if it assigned a newline to nl, but it doesn't.
59 # Instead, the \n ends up as a line that is then interpreted as a variable
60 # assignment. At that point, the line is simply "nl=\n", and the \n is
61 # skipped since it is whitespace (see Parse_IsVar).
67 # Next try at defining another newline variable. Since whitespace around the
68 # variable value is trimmed, two empty variable expressions surround the
69 # literal newline now. This prevents the newline from being skipped during
70 # parsing. The ':=' assignment operator expands the empty variable
71 # expressions, leaving only the newline as the variable value.
73 # This is one of the very few ways (maybe even the only one) to inject literal
74 # newlines into a line that is being parsed. This may confuse the parser.
75 # For example, in cond.c the parser only expects horizontal whitespace (' '
76 # and '\t'), but no newlines.
78 .MAKEFLAGS: nl:="$${:U}\n$${:U}"
79 .if ${nl} != ${.newline}
84 # Unbalanced quotes produce an error message. If they occur anywhere in the
85 # command line, the whole command line is skipped.
86 .MAKEFLAGS: VAR=previous
87 .MAKEFLAGS: VAR=initial UNBALANCED='
88 .if ${VAR} != "previous"