opt-debug-lint.mk revision 1.6 1 1.6 rillig # $NetBSD: opt-debug-lint.mk,v 1.6 2020/09/14 21:52:49 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.4 rillig # Since 2020-09-13, the "Malformed conditional" error message is not printed
15 1.4 rillig # anymore.
16 1.4 rillig #
17 1.4 rillig # See also:
18 1.4 rillig # cond-undef-lint.mk
19 1.2 rillig .if $X
20 1.2 rillig . error
21 1.2 rillig .endif
22 1.2 rillig
23 1.2 rillig # The dynamic variables like .TARGET are treated specially. It does not make
24 1.2 rillig # sense to expand them in the global scope since they will never be defined
25 1.2 rillig # there under normal circumstances. Therefore they expand to a string that
26 1.2 rillig # will later be expanded correctly, when the variable is evaluated again in
27 1.2 rillig # the scope of an actual target.
28 1.2 rillig #
29 1.2 rillig # Even though the "@" variable is not defined at this point, this is not an
30 1.2 rillig # error. In all practical cases, this is no problem. This particular test
31 1.2 rillig # case is made up and unrealistic.
32 1.2 rillig .if $@ != "\$(.TARGET)"
33 1.2 rillig . error
34 1.2 rillig .endif
35 1.1 rillig
36 1.3 rillig # Since 2020-09-13, Var_Parse properly reports errors for undefined variables,
37 1.3 rillig # but only in lint mode. Before, it had only silently returned var_Error,
38 1.3 rillig # hoping for the caller to print an error message. This resulted in the
39 1.3 rillig # well-known "Malformed conditional" error message, even though the
40 1.3 rillig # conditional was well-formed and the only error was an undefined variable.
41 1.3 rillig .if ${UNDEF}
42 1.3 rillig . error
43 1.3 rillig .endif
44 1.3 rillig
45 1.5 rillig # Since 2020-09-14, dependency lines may contain undefined variables.
46 1.5 rillig # Before, undefined variables were forbidden, but this distinction was not
47 1.5 rillig # observable from the outside of the function Var_Parse.
48 1.5 rillig ${UNDEF}: ${UNDEF}
49 1.5 rillig
50 1.6 rillig # In a condition that has a defined(UNDEF) guard, all guarded conditions
51 1.6 rillig # may assume that the variable is defined since they will only be evaluated
52 1.6 rillig # if the variable is indeed defined. Otherwise they are only parsed, and
53 1.6 rillig # for parsing it doesn't make a difference whether the variable is defined
54 1.6 rillig # or not.
55 1.6 rillig #
56 1.6 rillig # FIXME: As of 2020-09-14, the following line prints an error message saying
57 1.6 rillig # that UNDEF is undefined.
58 1.6 rillig .if defined(UNDEF) && exists(${UNDEF})
59 1.6 rillig . error
60 1.6 rillig .endif
61 1.6 rillig
62 1.1 rillig all:
63 1.1 rillig @:;
64