xref: /freebsd/contrib/bmake/unit-tests/deptgt-main.mk (revision a90b9d0159070121c221b966469c3e36d912bf82)
1# $NetBSD: deptgt-main.mk,v 1.4 2022/01/23 21:48:59 rillig Exp $
2#
3# Tests for the special target .MAIN in dependency declarations, which defines
4# the main target.  This main target is built if no target has been specified
5# on the command line or via MAKEFLAGS.
6
7# The first target becomes the main target by default.  It can be overridden
8# though.
9all: .PHONY
10	@echo 'This target is not made.'
11
12# This target is not the first to be defined, but it lists '.MAIN' as one of
13# its sources.  The word '.MAIN' only has a special meaning when it appears as
14# a _target_ in a dependency declaration, not as a _source_.  It is thus
15# ignored.
16depsrc-main: .PHONY .MAIN
17	@echo 'This target is not made either.'
18
19# This target is the first to be marked with '.MAIN', so it replaces the
20# previous main target, which was 'all'.
21.MAIN: real-main
22real-main: .PHONY
23	@echo 'This target ${.TARGET} is the one that is made.'
24
25# This target is marked with '.MAIN' but there already is a main target.  The
26# attribute '.MAIN' is thus ignored.
27.MAIN: too-late
28too-late: .PHONY
29	@echo 'This target comes too late, there is already a .MAIN target.'
30