1 1.20 rillig # $NetBSD: directive-include.mk,v 1.20 2025/06/28 22:39:28 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.12 rillig # expect+1: Could not find nonexistent.mk 26 1.4 rillig .include "nonexistent.mk" 27 1.4 rillig .include "/dev/null" # size 0 28 1.4 rillig # including a directory technically succeeds, but shouldn't. 29 1.4 rillig #.include "." # directory 30 1.4 rillig 31 1.5 rillig # As of 2020-11-21, anything after the delimiter '"' is ignored. 32 1.5 rillig .include "/dev/null" and ignore anything in the rest of the line. 33 1.5 rillig 34 1.6 rillig # The filename to be included can contain expressions. 35 1.6 rillig DEV= null 36 1.6 rillig .include "/dev/${DEV}" 37 1.6 rillig 38 1.6 rillig # Expressions in double quotes or angle quotes are first parsed naively, to 39 1.6 rillig # find the closing '"'. In a second step, the expressions are expanded. This 40 1.6 rillig # means that the expressions cannot include the characters '"' or '>'. This 41 1.6 rillig # restriction is not practically relevant since the expressions inside 42 1.6 rillig # '.include' directives are typically kept as simple as possible. 43 1.6 rillig # 44 1.6 rillig # If the whole line were expanded before parsing, the filename to be included 45 1.6 rillig # would be empty, and the closing '"' would be in the trailing part of the 46 1.6 rillig # line, which is ignored as of 2021-12-03. 47 1.6 rillig DQUOT= " 48 1.12 rillig # expect+1: Could not find " 49 1.6 rillig .include "${DQUOT}" 50 1.6 rillig 51 1.7 rillig # When the expression in a filename cannot be evaluated, the failing 52 1.7 rillig # expression is skipped and the file is included nevertheless. 53 1.7 rillig # FIXME: Add proper error handling, no file must be included here. 54 1.18 rillig # expect+2: Unknown modifier ":Z" 55 1.17 rillig # expect+1: Could not find nonexistent.mk 56 1.7 rillig .include "nonexistent${:U123:Z}.mk" 57 1.7 rillig 58 1.8 rillig # The traditional include directive is seldom used. 59 1.8 rillig include /dev/null # comment 60 1.8 rillig # expect+1: Cannot open /nonexistent 61 1.8 rillig include /nonexistent # comment 62 1.8 rillig sinclude /nonexistent # comment 63 1.8 rillig include ${:U/dev/null} # comment 64 1.8 rillig include /dev/null /dev/null 65 1.20 rillig # expect+1: Invalid line "include" 66 1.8 rillig include 67 1.9 rillig 68 1.8 rillig # XXX: trailing whitespace in diagnostic, missing quotes around filename 69 1.11 rillig ### TODO: expect+1: Could not find 70 1.9 rillig # The following include directive behaves differently, depending on whether 71 1.9 rillig # the current file has a slash or is a relative filename. In the first case, 72 1.9 rillig # make opens the directory of the current file and tries to read from it, 73 1.19 rillig # resulting in the error message ":1: Zero byte read from file". 74 1.9 rillig # In the second case, the error message is "Could not find ", without quotes 75 1.9 rillig # or any other indicator for the empty filename at the end of the line. 76 1.9 rillig #include ${:U} 77 1.8 rillig 78 1.10 rillig 79 1.10 rillig # Since parse.c 1.612 from 2022-01-01 and before parse.c 1.620 from 80 1.10 rillig # 2022-01-07, including an empty regular file called bmake_malloc(0), which 81 1.10 rillig # may return a null pointer. On OpenBSD, this led to a segmentation fault in 82 1.10 rillig # Buf_InitSize, which assumes that bmake_malloc never returns NULL, just like 83 1.10 rillig # all other places in the code. 84 1.10 rillig _!= > directive-include-empty 85 1.10 rillig .include "${.CURDIR}/directive-include-empty" 86 1.10 rillig _!= rm directive-include-empty 87 1.10 rillig 88 1.10 rillig 89 1.1 rillig all: 90