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