xref: /freebsd-src/contrib/bmake/unit-tests/cond-func-make-main.mk (revision b0c40a00a67f611868fc0f10bde6b28eb75931be)
1*b0c40a00SSimon J. Gerraty# $NetBSD: cond-func-make-main.mk,v 1.2 2021/04/04 10:13:09 rillig Exp $
206b9b3e0SSimon J. Gerraty#
306b9b3e0SSimon J. Gerraty# Test how accurately the make() function in .if conditions reflects
406b9b3e0SSimon J. Gerraty# what is actually made.
506b9b3e0SSimon J. Gerraty#
606b9b3e0SSimon J. Gerraty# There are several ways to specify what is being made:
706b9b3e0SSimon J. Gerraty#
806b9b3e0SSimon J. Gerraty# 1. The default main target is the first target in the given makefiles that
906b9b3e0SSimon J. Gerraty#    is not one of the special targets.  For example, .PHONY is special when
1006b9b3e0SSimon J. Gerraty#    it appears on the left-hand side of the ':'.  It is not special on the
1106b9b3e0SSimon J. Gerraty#    right-hand side though.
1206b9b3e0SSimon J. Gerraty#
1306b9b3e0SSimon J. Gerraty# 2. Command line arguments that are neither options (-ds or -k) nor variable
1406b9b3e0SSimon J. Gerraty#    assignments (VAR=value) are interpreted as targets to be made.  These
1506b9b3e0SSimon J. Gerraty#    override the default main target from above.
1606b9b3e0SSimon J. Gerraty#
1706b9b3e0SSimon J. Gerraty# 3. All sources of the first '.MAIN: sources' line.  Any further .MAIN line
1806b9b3e0SSimon J. Gerraty#    is treated as if .MAIN were a regular name.
1906b9b3e0SSimon J. Gerraty#
2006b9b3e0SSimon J. Gerraty# This test only covers items 1 and 3.  For item 2, see cond-func-make.mk.
2106b9b3e0SSimon J. Gerraty
2206b9b3e0SSimon J. Gerratyfirst-main-target:
2306b9b3e0SSimon J. Gerraty	: Making ${.TARGET}.
2406b9b3e0SSimon J. Gerraty
2506b9b3e0SSimon J. Gerraty# Even though the main-target would actually be made at this point, it is
2606b9b3e0SSimon J. Gerraty# ignored by the make() function.
2706b9b3e0SSimon J. Gerraty.if make(first-main-target)
2806b9b3e0SSimon J. Gerraty.  error
2906b9b3e0SSimon J. Gerraty.endif
3006b9b3e0SSimon J. Gerraty
3106b9b3e0SSimon J. Gerraty# Declaring a target via the .MAIN dependency adds it to the targets to be
3206b9b3e0SSimon J. Gerraty# created (opts.create), but only that list was empty at the beginning of
3306b9b3e0SSimon J. Gerraty# the line.  This implies that several main targets can be set at the name
3406b9b3e0SSimon J. Gerraty# time, but they have to be in the same dependency group.
3506b9b3e0SSimon J. Gerraty#
36*b0c40a00SSimon J. Gerraty# See ParseDependencyTargetSpecial, branch SP_MAIN.
3706b9b3e0SSimon J. Gerraty.MAIN: dot-main-target-1a dot-main-target-1b
3806b9b3e0SSimon J. Gerraty
3906b9b3e0SSimon J. Gerraty.if !make(dot-main-target-1a)
4006b9b3e0SSimon J. Gerraty.  error
4106b9b3e0SSimon J. Gerraty.endif
4206b9b3e0SSimon J. Gerraty.if !make(dot-main-target-1b)
4306b9b3e0SSimon J. Gerraty.  error
4406b9b3e0SSimon J. Gerraty.endif
4506b9b3e0SSimon J. Gerraty
4606b9b3e0SSimon J. Gerratydot-main-target-{1,2}{a,b}:
4706b9b3e0SSimon J. Gerraty	: Making ${.TARGET}.
4806b9b3e0SSimon J. Gerraty
4906b9b3e0SSimon J. Gerraty# At this point, the list of targets to be made (opts.create) is not empty
50*b0c40a00SSimon J. Gerraty# anymore.  ParseDependencyTargetSpecial therefore treats the .MAIN as if
5106b9b3e0SSimon J. Gerraty# it were an ordinary target.  Since .MAIN is not listed as a dependency
5206b9b3e0SSimon J. Gerraty# anywhere, it is not made.
5306b9b3e0SSimon J. Gerraty.if target(.MAIN)
5406b9b3e0SSimon J. Gerraty.  error
5506b9b3e0SSimon J. Gerraty.endif
5606b9b3e0SSimon J. Gerraty.MAIN: dot-main-target-2a dot-main-target-2b
5706b9b3e0SSimon J. Gerraty.if !target(.MAIN)
5806b9b3e0SSimon J. Gerraty.  error
5906b9b3e0SSimon J. Gerraty.endif
6006b9b3e0SSimon J. Gerraty.if make(dot-main-target-2a)
6106b9b3e0SSimon J. Gerraty.  error
6206b9b3e0SSimon J. Gerraty.endif
63