]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - unit-tests/deptgt-begin.mk
Import bmake-20230622
[FreeBSD/FreeBSD.git] / unit-tests / deptgt-begin.mk
1 # $NetBSD: deptgt-begin.mk,v 1.7 2023/06/01 20:56:35 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 # expect+2: warning: using previous script for ".BEGIN" defined here
8 .BEGIN:
9         : $@
10
11 # To register a custom action to be run at the beginning, the simplest way is
12 # to directly place some commands on the '.BEGIN' target.  This doesn't scale
13 # though, since the ':' dependency operator prevents that any other place may
14 # add its commands after this.
15 #
16 # There are several ways to resolve this situation, which are detailed below.
17 # expect+2: warning: duplicate script for target ".BEGIN" ignored
18 .BEGIN:
19         : Making another $@.
20
21 # One way to run commands at the beginning is to define a custom target and
22 # make the .BEGIN depend on that target.  This way, the commands from the
23 # custom target are run even before the .BEGIN target.
24 .BEGIN: before-begin
25 before-begin: .PHONY .NOTMAIN
26         : Making $@ before .BEGIN.
27
28 # Another way is to define a custom target and make that a .USE dependency.
29 # For the .BEGIN target, .USE dependencies do not work though, since in
30 # Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the
31 # .BEGIN target has been made, which is too late.
32 .BEGIN: use
33 use: .USE .NOTMAIN
34         : Making $@ from a .USE dependency.
35
36 # Same as with .USE, but run the commands before the main commands from the
37 # .BEGIN target.
38 #
39 # For the .BEGIN target, .USEBEFORE dependencies do not work though, since in
40 # Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the
41 # .BEGIN target has been made, which is too late.
42 .BEGIN: use-before
43 use-before: .USEBEFORE .NOTMAIN
44         : Making $@ from a .USEBEFORE dependency.
45
46 all:
47         : $@
48
49 _!=     echo : parse time 1>&2