2021-12-18 07:27:22 +00:00
|
|
|
# $NetBSD: deptgt-makeflags.mk,v 1.7 2021/11/29 00:17:10 rillig Exp $
|
2020-09-05 16:11:04 +00:00
|
|
|
#
|
2020-11-07 19:39:21 +00:00
|
|
|
# Tests for the special target .MAKEFLAGS in dependency declarations,
|
|
|
|
# which adds command line options later, at parse time.
|
2020-11-20 03:54:37 +00:00
|
|
|
#
|
|
|
|
# In these unit tests, it is often used to temporarily toggle the debug log
|
|
|
|
# during parsing.
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
# The -D option sets a variable in the "Global" scope and thus can be
|
|
|
|
# undefined later.
|
|
|
|
.MAKEFLAGS: -D VAR
|
|
|
|
.if ${VAR} != 1
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# Variables that are set via the -D command line option are normal global
|
|
|
|
# variables and can thus be undefined later.
|
2020-11-07 19:39:21 +00:00
|
|
|
.undef VAR
|
|
|
|
.if defined(VAR)
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# The -D command line option can define a variable again, after it has been
|
|
|
|
# undefined.
|
2020-11-07 19:39:21 +00:00
|
|
|
.MAKEFLAGS: -D VAR
|
|
|
|
.if ${VAR} != 1
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# The "dependency" for .MAKEFLAGS is split into words, interpreting the usual
|
|
|
|
# quotes and escape sequences from the backslash.
|
2020-11-07 19:39:21 +00:00
|
|
|
.MAKEFLAGS: VAR="value"' with'\ spaces
|
|
|
|
.if ${VAR} != "value with spaces"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# Variables set on the command line as VAR=value are placed in the
|
|
|
|
# "Command" scope and thus cannot be undefined.
|
|
|
|
.undef VAR
|
|
|
|
.if ${VAR} != "value with spaces"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# When parsing this line, each '$$' becomes '$', resulting in '$$$$'.
|
|
|
|
# This is assigned to the variable DOLLAR.
|
|
|
|
# In the condition, that variable is expanded, and at that point, each '$$'
|
|
|
|
# becomes '$' again, the final expression is thus '$$'.
|
|
|
|
.MAKEFLAGS: -dcv
|
|
|
|
.MAKEFLAGS: DOLLAR=$$$$$$$$
|
|
|
|
.if ${DOLLAR} != "\$\$"
|
|
|
|
.endif
|
|
|
|
.MAKEFLAGS: -d0
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# An empty command line is skipped.
|
|
|
|
.MAKEFLAGS: # none
|
|
|
|
|
|
|
|
# Escape sequences like \n are interpreted.
|
|
|
|
# The following line looks as if it assigned a newline to nl, but it doesn't.
|
|
|
|
# Instead, the \n ends up as a line that is then interpreted as a variable
|
|
|
|
# assignment. At that point, the line is simply "nl=\n", and the \n is
|
|
|
|
# skipped since it is whitespace (see Parse_IsVar).
|
|
|
|
.MAKEFLAGS: nl="\n"
|
|
|
|
.if ${nl} != ""
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# Next try at defining another newline variable. Since whitespace around the
|
2021-12-18 07:27:22 +00:00
|
|
|
# variable value is trimmed, two empty variable expressions ${:U} surround the
|
2020-11-20 03:54:37 +00:00
|
|
|
# literal newline now. This prevents the newline from being skipped during
|
|
|
|
# parsing. The ':=' assignment operator expands the empty variable
|
|
|
|
# expressions, leaving only the newline as the variable value.
|
|
|
|
#
|
|
|
|
# This is one of the very few ways (maybe even the only one) to inject literal
|
|
|
|
# newlines into a line that is being parsed. This may confuse the parser.
|
|
|
|
# For example, in cond.c the parser only expects horizontal whitespace (' '
|
|
|
|
# and '\t'), but no newlines.
|
|
|
|
#.MAKEFLAGS: -dcpv
|
|
|
|
.MAKEFLAGS: nl:="$${:U}\n$${:U}"
|
|
|
|
.if ${nl} != ${.newline}
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
#.MAKEFLAGS: -d0
|
|
|
|
|
2021-12-18 07:27:22 +00:00
|
|
|
# Now do the same for the other escape sequences; see Substring_Words.
|
|
|
|
.MAKEFLAGS: CHAR_BS:="$${:U}\b$${:U}"
|
|
|
|
.MAKEFLAGS: CHAR_FF:="$${:U}\f$${:U}"
|
|
|
|
.MAKEFLAGS: CHAR_NL:="$${:U}\n$${:U}"
|
|
|
|
.MAKEFLAGS: CHAR_CR:="$${:U}\r$${:U}"
|
|
|
|
.MAKEFLAGS: CHAR_TAB:="$${:U}\t$${:U}"
|
|
|
|
|
|
|
|
# Note: backspace is not whitespace, it is a control character.
|
|
|
|
.if ${CHAR_BS:C,^[[:cntrl:]]$,found,W} != "found"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
.if ${CHAR_FF:C,^[[:space:]]$,found,W} != "found"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
.if ${CHAR_NL:C,^[[:space:]]$,found,W} != "found"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
.if ${CHAR_CR:C,^[[:space:]]$,found,W} != "found"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
.if ${CHAR_TAB:C,^[[:space:]]$,found,W} != "found"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# Unbalanced quotes produce an error message. If they occur anywhere in the
|
|
|
|
# command line, the whole command line is skipped.
|
|
|
|
.MAKEFLAGS: VAR=previous
|
|
|
|
.MAKEFLAGS: VAR=initial UNBALANCED='
|
|
|
|
.if ${VAR} != "previous"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
all:
|
|
|
|
@:;
|