xref: /freebsd/contrib/bmake/unit-tests/deptgt-begin.mk (revision 5956d97f4b3204318ceb6aa9c77bd0bc6ea87a41)
1# $NetBSD: deptgt-begin.mk,v 1.6 2022/05/07 08:01:20 rillig Exp $
2#
3# Tests for the special target .BEGIN in dependency declarations,
4# which is a container for commands that are run before any other
5# commands from the shell lines.
6
7.BEGIN:
8	: $@
9
10# To register a custom action to be run at the beginning, the simplest way is
11# to directly place some commands on the '.BEGIN' target.  This doesn't scale
12# though, since the ':' dependency operator prevents that any other place may
13# add its commands after this.
14#
15# There are several ways to resolve this situation, which are detailed below.
16.BEGIN:
17	: Making another $@.
18
19# One way to run commands at the beginning is to define a custom target and
20# make the .BEGIN depend on that target.  This way, the commands from the
21# custom target are run even before the .BEGIN target.
22.BEGIN: before-begin
23before-begin: .PHONY .NOTMAIN
24	: Making $@ before .BEGIN.
25
26# Another way is to define a custom target and make that a .USE dependency.
27# For the .BEGIN target, .USE dependencies do not work though, since in
28# Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the
29# .BEGIN target has been made, which is too late.
30.BEGIN: use
31use: .USE .NOTMAIN
32	: Making $@ from a .USE dependency.
33
34# Same as with .USE, but run the commands before the main commands from the
35# .BEGIN target.
36#
37# For the .BEGIN target, .USEBEFORE dependencies do not work though, since in
38# Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the
39# .BEGIN target has been made, which is too late.
40.BEGIN: use-before
41use-before: .USEBEFORE .NOTMAIN
42	: Making $@ from a .USEBEFORE dependency.
43
44all:
45	: $@
46
47_!=	echo : parse time 1>&2
48