Home | History | Annotate | Line # | Download | only in unit-tests
deptgt-begin.mk revision 1.8
      1 # $NetBSD: deptgt-begin.mk,v 1.8 2025/06/30 21:44:39 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 # expect+3: warning: duplicate script for target ".BEGIN" ignored
     17 # expect-9: warning: using previous script for ".BEGIN" defined here
     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
     50