opt-file.mk revision 1.14 1 1.14 rillig # $NetBSD: opt-file.mk,v 1.14 2021/12/09 20:47:33 rillig Exp $
2 1.1 rillig #
3 1.14 rillig # Tests for the -f command line option, which adds a makefile to the list of
4 1.14 rillig # files that are parsed.
5 1.1 rillig
6 1.1 rillig # TODO: Implementation
7 1.1 rillig
8 1.4 rillig all: .PHONY
9 1.4 rillig all: file-ending-in-backslash
10 1.8 rillig all: file-ending-in-backslash-mmap
11 1.10 rillig all: line-with-trailing-whitespace
12 1.4 rillig all: file-containing-null-byte
13 1.3 rillig
14 1.14 rillig # When the filename is '-', the input comes from stdin. This is unusual but
15 1.14 rillig # possible.
16 1.3 rillig #
17 1.3 rillig # In the unlikely case where a file ends in a backslash instead of a newline,
18 1.3 rillig # that backslash is trimmed. See ParseGetLine.
19 1.7 rillig #
20 1.7 rillig # make-2014.01.01.00.00.00 invoked undefined behavior, reading text from
21 1.7 rillig # outside of the file buffer.
22 1.7 rillig #
23 1.7 rillig # printf '%s' 'VAR=value\' \
24 1.14 rillig # | MALLOC_OPTIONS="JA" \
25 1.14 rillig # MALLOC_CONF="junk:true" \
26 1.14 rillig # make-2014.01.01.00.00.00 -r -f - -V VAR -dA 2>&1 \
27 1.7 rillig # | less
28 1.7 rillig #
29 1.7 rillig # The debug output shows how make happily uses freshly allocated memory (the
30 1.7 rillig # <A5>) and already freed memory ('Z').
31 1.7 rillig #
32 1.7 rillig # ParseReadLine (1): 'VAR=value\<A5><A5><A5><A5><A5><A5>'
33 1.7 rillig # Global:VAR = value\<A5><A5><A5><A5><A5><A5>value\<A5><A5><A5><A5><A5><A5>
34 1.7 rillig # ParseReadLine (2): 'alue\<A5><A5><A5><A5><A5><A5>'
35 1.12 rillig # ParseDependency(alue\<A5><A5><A5><A5><A5><A5>)
36 1.7 rillig # make-2014.01.01.00.00.00: "(stdin)" line 2: Need an operator
37 1.7 rillig # ParseReadLine (3): '<A5><A5><A5>ZZZZZZZZZZZZZZZZ'
38 1.12 rillig # ParseDependency(<A5><A5><A5>ZZZZZZZZZZZZZZZZ)
39 1.7 rillig #
40 1.3 rillig file-ending-in-backslash: .PHONY
41 1.4 rillig @printf '%s' 'VAR=value\' \
42 1.7 rillig | ${MAKE} -r -f - -V VAR
43 1.4 rillig
44 1.8 rillig # Between parse.c 1.170 from 2010-12-25 and parse.c 1.511 from 2020-12-22,
45 1.8 rillig # there was an out-of-bounds write in ParseGetLine, where line_end pointed at
46 1.8 rillig # the end of the allocated buffer, in the special case where loadedfile_mmap
47 1.8 rillig # had not added the final newline character.
48 1.8 rillig file-ending-in-backslash-mmap: .PHONY
49 1.8 rillig @printf '%s' 'VAR=value\' > opt-file-backslash
50 1.8 rillig @${MAKE} -r -f opt-file-backslash -V VAR
51 1.9 rillig @rm opt-file-backslash
52 1.8 rillig
53 1.10 rillig # Since parse.c 1.511 from 2020-12-22, an assertion in ParseGetLine failed
54 1.10 rillig # for lines that contained trailing whitespace. Worked around in parse.c
55 1.10 rillig # 1.513, properly fixed in parse.c 1.514.
56 1.10 rillig line-with-trailing-whitespace: .PHONY
57 1.10 rillig @printf '%s' 'VAR=$@ ' > opt-file-trailing-whitespace
58 1.10 rillig @${MAKE} -r -f opt-file-trailing-whitespace -V VAR
59 1.10 rillig @rm opt-file-trailing-whitespace
60 1.10 rillig
61 1.11 rillig # If a makefile contains null bytes, it is an error. Throughout the history
62 1.11 rillig # of make, the behavior has changed several times, sometimes intentionally,
63 1.11 rillig # sometimes by accident.
64 1.5 rillig #
65 1.5 rillig # echo 'VAR=value' | tr 'l' '\0' > zero-byte.in
66 1.5 rillig # printf '%s\n' 'all:' ': VAR=${VAR:Q}' >> zero-byte.in
67 1.5 rillig #
68 1.5 rillig # for year in $(seq 2003 2020); do
69 1.5 rillig # echo $year:
70 1.5 rillig # make-$year.01.01.00.00.00 -r -f zero-byte.in
71 1.5 rillig # echo "exit status $?"
72 1.5 rillig # echo
73 1.5 rillig # done 2>&1 \
74 1.5 rillig # | sed "s,$PWD/,.,"
75 1.5 rillig #
76 1.5 rillig # This program generated the following output:
77 1.5 rillig #
78 1.5 rillig # 2003 to 2007:
79 1.5 rillig # exit status 0
80 1.5 rillig #
81 1.5 rillig # 2008 to 2010:
82 1.5 rillig # make: "zero-byte.in" line 1: Zero byte read from file
83 1.5 rillig # make: Fatal errors encountered -- cannot continue
84 1.5 rillig #
85 1.5 rillig # make: stopped in .
86 1.5 rillig # exit status 1
87 1.5 rillig #
88 1.5 rillig # 2011 to 2013:
89 1.5 rillig # make: no target to make.
90 1.5 rillig #
91 1.5 rillig # make: stopped in .
92 1.5 rillig # exit status 2
93 1.5 rillig #
94 1.6 rillig # 2014 to 2020-12-06:
95 1.5 rillig # make: "zero-byte.in" line 1: warning: Zero byte read from file, skipping rest of line.
96 1.5 rillig # exit status 0
97 1.4 rillig #
98 1.6 rillig # Since 2020-12-07:
99 1.6 rillig # make: "zero-byte.in" line 1: Zero byte read from file
100 1.6 rillig # make: Fatal errors encountered -- cannot continue
101 1.6 rillig # make: stopped in .
102 1.6 rillig # exit status 1
103 1.4 rillig file-containing-null-byte: .PHONY
104 1.4 rillig @printf '%s\n' 'VAR=value' 'VAR2=VALUE2' \
105 1.4 rillig | tr 'l' '\0' \
106 1.7 rillig | ${MAKE} -r -f - -V VAR -V VAR2
107 1.3 rillig
108 1.1 rillig all:
109 1.6 rillig : Making ${.TARGET}
110