directive-include.mk revision 1.7 1 1.7 rillig # $NetBSD: directive-include.mk,v 1.7 2021/12/03 22:48:07 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # Tests for the .include directive, which includes another file.
4 1.1 rillig
5 1.1 rillig # TODO: Implementation
6 1.1 rillig
7 1.2 rillig .MAKEFLAGS: -dc
8 1.2 rillig
9 1.2 rillig # All included files are recorded in the variable .MAKE.MAKEFILES.
10 1.2 rillig # In this test, only the basenames of the files are compared since
11 1.2 rillig # the directories can differ.
12 1.2 rillig .include "/dev/null"
13 1.2 rillig .if ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
14 1.2 rillig . error
15 1.2 rillig .endif
16 1.2 rillig
17 1.2 rillig # Each file is recorded only once in the variable .MAKE.MAKEFILES.
18 1.3 rillig # Between 2015-11-26 and 2020-10-31, the very last file could be repeated,
19 1.3 rillig # due to an off-by-one bug in ParseTrackInput.
20 1.2 rillig .include "/dev/null"
21 1.3 rillig .if ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
22 1.2 rillig . error
23 1.2 rillig .endif
24 1.2 rillig
25 1.4 rillig .include "nonexistent.mk"
26 1.4 rillig .include "/dev/null" # size 0
27 1.4 rillig # including a directory technically succeeds, but shouldn't.
28 1.4 rillig #.include "." # directory
29 1.4 rillig
30 1.5 rillig # As of 2020-11-21, anything after the delimiter '"' is ignored.
31 1.5 rillig .include "/dev/null" and ignore anything in the rest of the line.
32 1.5 rillig
33 1.6 rillig # The filename to be included can contain expressions.
34 1.6 rillig DEV= null
35 1.6 rillig .include "/dev/${DEV}"
36 1.6 rillig
37 1.6 rillig # Expressions in double quotes or angle quotes are first parsed naively, to
38 1.6 rillig # find the closing '"'. In a second step, the expressions are expanded. This
39 1.6 rillig # means that the expressions cannot include the characters '"' or '>'. This
40 1.6 rillig # restriction is not practically relevant since the expressions inside
41 1.6 rillig # '.include' directives are typically kept as simple as possible.
42 1.6 rillig #
43 1.6 rillig # If the whole line were expanded before parsing, the filename to be included
44 1.6 rillig # would be empty, and the closing '"' would be in the trailing part of the
45 1.6 rillig # line, which is ignored as of 2021-12-03.
46 1.6 rillig DQUOT= "
47 1.6 rillig .include "${DQUOT}"
48 1.6 rillig
49 1.7 rillig # When the expression in a filename cannot be evaluated, the failing
50 1.7 rillig # expression is skipped and the file is included nevertheless.
51 1.7 rillig # FIXME: Add proper error handling, no file must be included here.
52 1.7 rillig .include "nonexistent${:U123:Z}.mk"
53 1.7 rillig
54 1.1 rillig all:
55