Home | History | Annotate | Line # | Download | only in unit-tests
deptgt-begin.mk revision 1.4
      1  1.4  rillig # $NetBSD: deptgt-begin.mk,v 1.4 2020/11/15 20:47:01 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.4  rillig # This way, its commands are appended to the commands of the .BEGIN target
     28  1.4  rillig # just before the .BEGIN target is made.
     29  1.4  rillig #
     30  1.4  rillig # XXX: For some reason, the commands from the .USE target are not run.
     31  1.4  rillig # XXX: .USE nodes should not be candidates for the .MAIN node.
     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.4  rillig # XXX: For some reason, the commands from the .USEBEFORE target are not run.
     40  1.4  rillig # XXX: .USEBEFORE nodes should not be candidates for the .MAIN node.
     41  1.4  rillig .BEGIN: use-before
     42  1.4  rillig use-before: .USEBEFORE .NOTMAIN
     43  1.4  rillig 	: Making $@ from a .USEBEFORE dependency.
     44  1.4  rillig 
     45  1.1  rillig all:
     46  1.3  rillig 	: $@
     47  1.3  rillig 
     48  1.3  rillig _!=	echo : parse time 1>&2
     49