Home | History | Annotate | Line # | Download | only in unit-tests
deptgt-begin.mk revision 1.6
      1  1.6  rillig # $NetBSD: deptgt-begin.mk,v 1.6 2022/05/07 08:01:20 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.4  rillig .BEGIN:
     17  1.4  rillig 	: Making another $@.
     18  1.4  rillig 
     19  1.4  rillig # One way to run commands at the beginning is to define a custom target and
     20  1.4  rillig # make the .BEGIN depend on that target.  This way, the commands from the
     21  1.4  rillig # custom target are run even before the .BEGIN target.
     22  1.4  rillig .BEGIN: before-begin
     23  1.4  rillig before-begin: .PHONY .NOTMAIN
     24  1.4  rillig 	: Making $@ before .BEGIN.
     25  1.4  rillig 
     26  1.4  rillig # Another way is to define a custom target and make that a .USE dependency.
     27  1.5  rillig # For the .BEGIN target, .USE dependencies do not work though, since in
     28  1.6  rillig # Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the
     29  1.6  rillig # .BEGIN target has been made, which is too late.
     30  1.4  rillig .BEGIN: use
     31  1.4  rillig use: .USE .NOTMAIN
     32  1.4  rillig 	: Making $@ from a .USE dependency.
     33  1.4  rillig 
     34  1.4  rillig # Same as with .USE, but run the commands before the main commands from the
     35  1.4  rillig # .BEGIN target.
     36  1.4  rillig #
     37  1.5  rillig # For the .BEGIN target, .USEBEFORE dependencies do not work though, since in
     38  1.6  rillig # Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the
     39  1.6  rillig # .BEGIN target has been made, which is too late.
     40  1.4  rillig .BEGIN: use-before
     41  1.4  rillig use-before: .USEBEFORE .NOTMAIN
     42  1.4  rillig 	: Making $@ from a .USEBEFORE dependency.
     43  1.4  rillig 
     44  1.1  rillig all:
     45  1.3  rillig 	: $@
     46  1.3  rillig 
     47  1.3  rillig _!=	echo : parse time 1>&2
     48