1*148ee845SSimon J. Gerraty# $NetBSD: deptgt-begin.mk,v 1.7 2023/06/01 20:56:35 rillig Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Tests for the special target .BEGIN in dependency declarations, 42c3632d1SSimon J. Gerraty# which is a container for commands that are run before any other 52c3632d1SSimon J. Gerraty# commands from the shell lines. 62c3632d1SSimon J. Gerraty 7*148ee845SSimon J. Gerraty# expect+2: warning: using previous script for ".BEGIN" defined here 82c3632d1SSimon J. Gerraty.BEGIN: 92c3632d1SSimon J. Gerraty : $@ 102c3632d1SSimon J. Gerraty 11e2eeea75SSimon J. Gerraty# To register a custom action to be run at the beginning, the simplest way is 12e2eeea75SSimon J. Gerraty# to directly place some commands on the '.BEGIN' target. This doesn't scale 13e2eeea75SSimon J. Gerraty# though, since the ':' dependency operator prevents that any other place may 14e2eeea75SSimon J. Gerraty# add its commands after this. 15e2eeea75SSimon J. Gerraty# 16e2eeea75SSimon J. Gerraty# There are several ways to resolve this situation, which are detailed below. 17*148ee845SSimon J. Gerraty# expect+2: warning: duplicate script for target ".BEGIN" ignored 18e2eeea75SSimon J. Gerraty.BEGIN: 19e2eeea75SSimon J. Gerraty : Making another $@. 20e2eeea75SSimon J. Gerraty 21e2eeea75SSimon J. Gerraty# One way to run commands at the beginning is to define a custom target and 22e2eeea75SSimon J. Gerraty# make the .BEGIN depend on that target. This way, the commands from the 23e2eeea75SSimon J. Gerraty# custom target are run even before the .BEGIN target. 24e2eeea75SSimon J. Gerraty.BEGIN: before-begin 25e2eeea75SSimon J. Gerratybefore-begin: .PHONY .NOTMAIN 26e2eeea75SSimon J. Gerraty : Making $@ before .BEGIN. 27e2eeea75SSimon J. Gerraty 28e2eeea75SSimon J. Gerraty# Another way is to define a custom target and make that a .USE dependency. 29e2eeea75SSimon J. Gerraty# For the .BEGIN target, .USE dependencies do not work though, since in 30954401e6SSimon J. Gerraty# Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the 31954401e6SSimon J. Gerraty# .BEGIN target has been made, which is too late. 32e2eeea75SSimon J. Gerraty.BEGIN: use 33e2eeea75SSimon J. Gerratyuse: .USE .NOTMAIN 34e2eeea75SSimon J. Gerraty : Making $@ from a .USE dependency. 35e2eeea75SSimon J. Gerraty 36e2eeea75SSimon J. Gerraty# Same as with .USE, but run the commands before the main commands from the 37e2eeea75SSimon J. Gerraty# .BEGIN target. 38e2eeea75SSimon J. Gerraty# 39e2eeea75SSimon J. Gerraty# For the .BEGIN target, .USEBEFORE dependencies do not work though, since in 40954401e6SSimon J. Gerraty# Compat_MakeAll, the .USE and .USEBEFORE nodes are expanded right after the 41954401e6SSimon J. Gerraty# .BEGIN target has been made, which is too late. 42e2eeea75SSimon J. Gerraty.BEGIN: use-before 43e2eeea75SSimon J. Gerratyuse-before: .USEBEFORE .NOTMAIN 44e2eeea75SSimon J. Gerraty : Making $@ from a .USEBEFORE dependency. 45e2eeea75SSimon J. Gerraty 462c3632d1SSimon J. Gerratyall: 472c3632d1SSimon J. Gerraty : $@ 482c3632d1SSimon J. Gerraty 492c3632d1SSimon J. Gerraty_!= echo : parse time 1>&2 50