opt-debug-lint.mk revision 1.3 1 1.3 rillig # $NetBSD: opt-debug-lint.mk,v 1.3 2020/09/13 20:21:24 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # Tests for the -dL command line option, which runs additional checks
4 1.1 rillig # to catch common mistakes, such as unclosed variable expressions.
5 1.1 rillig
6 1.2 rillig .MAKEFLAGS: -dL
7 1.2 rillig
8 1.2 rillig # Since 2020-09-13, undefined variables that are used on the left-hand side
9 1.2 rillig # of a condition at parse time get a proper error message. Before, the
10 1.2 rillig # error message was "Malformed conditional" only, which was wrong and
11 1.2 rillig # misleading. The form of the condition is totally fine, it's the evaluation
12 1.2 rillig # that fails.
13 1.2 rillig #
14 1.2 rillig # TODO: Get rid of the "Malformed conditional" error message.
15 1.2 rillig # As long as the first error message is only printed in lint mode, it can
16 1.2 rillig # get tricky to keep track of the actually printed error messages and those
17 1.2 rillig # that still need to be printed. That's probably a solvable problem though.
18 1.2 rillig .if $X
19 1.2 rillig . error
20 1.2 rillig .endif
21 1.2 rillig
22 1.2 rillig # The dynamic variables like .TARGET are treated specially. It does not make
23 1.2 rillig # sense to expand them in the global scope since they will never be defined
24 1.2 rillig # there under normal circumstances. Therefore they expand to a string that
25 1.2 rillig # will later be expanded correctly, when the variable is evaluated again in
26 1.2 rillig # the scope of an actual target.
27 1.2 rillig #
28 1.2 rillig # Even though the "@" variable is not defined at this point, this is not an
29 1.2 rillig # error. In all practical cases, this is no problem. This particular test
30 1.2 rillig # case is made up and unrealistic.
31 1.2 rillig .if $@ != "\$(.TARGET)"
32 1.2 rillig . error
33 1.2 rillig .endif
34 1.1 rillig
35 1.3 rillig # Since 2020-09-13, Var_Parse properly reports errors for undefined variables,
36 1.3 rillig # but only in lint mode. Before, it had only silently returned var_Error,
37 1.3 rillig # hoping for the caller to print an error message. This resulted in the
38 1.3 rillig # well-known "Malformed conditional" error message, even though the
39 1.3 rillig # conditional was well-formed and the only error was an undefined variable.
40 1.3 rillig .if ${UNDEF}
41 1.3 rillig . error
42 1.3 rillig .endif
43 1.3 rillig
44 1.1 rillig all:
45 1.1 rillig @:;
46