xref: /freebsd/contrib/bmake/unit-tests/dep-colon-bug-cross-file.mk (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1# $NetBSD: dep-colon-bug-cross-file.mk,v 1.5 2023/06/01 20:56:35 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# expect+1: warning: duplicate script for target "all" ignored
32	: pass 2
33.endif
34
35.if ${PASS} == 1
36
37PASS=	2
38.MAKEFLAGS: -f ${.PARSEDIR:q}/${.PARSEFILE:q}
39
40all:
41# expect+1: warning: using previous script for "all" defined here
42	: pass 1
43.endif
44