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