xref: /freebsd/contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk (revision d4eeb02986980bf33dd56c41ceb9fc5f180c0d47)
1# $NetBSD: dep-colon-bug-cross-file.mk,v 1.4 2020/09/27 09:53:41 rillig Exp $
2#
3# Until 2020-09-25, the very last dependency group of a top-level makefile
4# was not finished properly.  This made it possible to add further commands
5# to that target.
6#
7# In pass 1, there is a dependency group at the bottom of the file.
8# This dependency group is not finished properly.  Finishing the dependency
9# group would add the OP_HAS_COMMANDS flag to the "all" target, thereby
10# preventing any commands from being added later.
11#
12# After the file has been parsed completely, it is parsed again in pass 2.
13# In this pass, another command is added to the "current dependency group",
14# which was still the one from pass 1, which means it was possible to later
15# add commands to an existing target, even across file boundaries.
16#
17# Oops, even worse.  Running this test in a make from 2020-09-25 or earlier
18# on NetBSD 8.0 x86_64 with MALLOC_OPTIONS=JA produces this or a similar
19# output:
20#
21#	make: cannot open ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ.
22#
23# The 'Z' means access to already freed memory; see jemalloc(3).  The cause
24# for this is that in MainParseArgs, the command line arguments were not
25# properly copied before storing them in global variables.
26
27PASS?=	1
28
29.if ${PASS} == 2
30all:
31	: pass 2
32.endif
33
34.if ${PASS} == 1
35
36PASS=	2
37.MAKEFLAGS: -f ${.PARSEDIR:q}/${.PARSEFILE:q}
38
39all:
40	: pass 1
41.endif
42