xref: /freebsd/contrib/bmake/unit-tests/deptgt-begin.mk (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1# $NetBSD: deptgt-begin.mk,v 1.5 2020/11/15 22:28:08 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_Run, the .USE and .USEBEFORE nodes are expanded right after the
29# .BEGIN target has been run, 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_Run, the .USE and .USEBEFORE nodes are expanded right after the
39# .BEGIN target has been run, 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