xref: /freebsd/contrib/bmake/unit-tests/cond-func-make-main.mk (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1# $NetBSD: cond-func-make-main.mk,v 1.2 2021/04/04 10:13:09 rillig Exp $
2#
3# Test how accurately the make() function in .if conditions reflects
4# what is actually made.
5#
6# There are several ways to specify what is being made:
7#
8# 1. The default main target is the first target in the given makefiles that
9#    is not one of the special targets.  For example, .PHONY is special when
10#    it appears on the left-hand side of the ':'.  It is not special on the
11#    right-hand side though.
12#
13# 2. Command line arguments that are neither options (-ds or -k) nor variable
14#    assignments (VAR=value) are interpreted as targets to be made.  These
15#    override the default main target from above.
16#
17# 3. All sources of the first '.MAIN: sources' line.  Any further .MAIN line
18#    is treated as if .MAIN were a regular name.
19#
20# This test only covers items 1 and 3.  For item 2, see cond-func-make.mk.
21
22first-main-target:
23	: Making ${.TARGET}.
24
25# Even though the main-target would actually be made at this point, it is
26# ignored by the make() function.
27.if make(first-main-target)
28.  error
29.endif
30
31# Declaring a target via the .MAIN dependency adds it to the targets to be
32# created (opts.create), but only that list was empty at the beginning of
33# the line.  This implies that several main targets can be set at the name
34# time, but they have to be in the same dependency group.
35#
36# See ParseDependencyTargetSpecial, branch SP_MAIN.
37.MAIN: dot-main-target-1a dot-main-target-1b
38
39.if !make(dot-main-target-1a)
40.  error
41.endif
42.if !make(dot-main-target-1b)
43.  error
44.endif
45
46dot-main-target-{1,2}{a,b}:
47	: Making ${.TARGET}.
48
49# At this point, the list of targets to be made (opts.create) is not empty
50# anymore.  ParseDependencyTargetSpecial therefore treats the .MAIN as if
51# it were an ordinary target.  Since .MAIN is not listed as a dependency
52# anywhere, it is not made.
53.if target(.MAIN)
54.  error
55.endif
56.MAIN: dot-main-target-2a dot-main-target-2b
57.if !target(.MAIN)
58.  error
59.endif
60.if make(dot-main-target-2a)
61.  error
62.endif
63