Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): document the selection of t...



details:   https://anonhg.NetBSD.org/src/rev/38fa6b938de1
branches:  trunk
changeset: 957265:38fa6b938de1
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 22 19:37:27 2020 +0000

description:
make(1): document the selection of the main target

diffstat:

 distrib/sets/lists/tests/mi                     |   4 +-
 usr.bin/make/unit-tests/Makefile                |   3 +-
 usr.bin/make/unit-tests/cond-func-make-main.exp |   3 +
 usr.bin/make/unit-tests/cond-func-make-main.mk  |  62 +++++++++++++++++++++++++
 4 files changed, 70 insertions(+), 2 deletions(-)

diffs (108 lines):

diff -r 8835c9b58d7d -r 38fa6b938de1 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Nov 22 19:14:24 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Nov 22 19:37:27 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.971 2020/11/21 10:32:42 rillig Exp $
+# $NetBSD: mi,v 1.972 2020/11/22 19:37:27 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4851,6 +4851,8 @@
 ./usr/tests/usr.bin/make/unit-tests/cond-func-empty.mk                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-func-exists.exp                       tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-func-exists.mk                                tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-func-make-main.exp                    tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-func-make-main.mk                     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-func-make.exp                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-func-make.mk                          tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-func-target.exp                       tests-usr.bin-tests     compattestfile,atf
diff -r 8835c9b58d7d -r 38fa6b938de1 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sun Nov 22 19:14:24 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sun Nov 22 19:37:27 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.216 2020/11/22 18:44:10 rillig Exp $
+# $NetBSD: Makefile,v 1.217 2020/11/22 19:37:27 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -58,6 +58,7 @@
 TESTS+=                cond-func-empty
 TESTS+=                cond-func-exists
 TESTS+=                cond-func-make
+TESTS+=                cond-func-make-main
 TESTS+=                cond-func-target
 TESTS+=                cond-late
 TESTS+=                cond-op
diff -r 8835c9b58d7d -r 38fa6b938de1 usr.bin/make/unit-tests/cond-func-make-main.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-func-make-main.exp   Sun Nov 22 19:37:27 2020 +0000
@@ -0,0 +1,3 @@
+: Making dot-main-target-1a.
+: Making dot-main-target-1b.
+exit status 0
diff -r 8835c9b58d7d -r 38fa6b938de1 usr.bin/make/unit-tests/cond-func-make-main.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-func-make-main.mk    Sun Nov 22 19:37:27 2020 +0000
@@ -0,0 +1,62 @@
+# $NetBSD: cond-func-make-main.mk,v 1.1 2020/11/22 19:37:27 rillig Exp $
+#
+# Test how accurately the make() function in .if conditions reflects
+# what is actually made.
+#
+# There are several ways to specify what is being made:
+#
+# 1. The default main target is the first target in the given makefiles that
+#    is not one of the special targets.  For example, .PHONY is special when
+#    it appears on the left-hand side of the ':'.  It is not special on the
+#    right-hand side though.
+#
+# 2. Command line arguments that are neither options (-ds or -k) nor variable
+#    assignments (VAR=value) are interpreted as targets to be made.  These
+#    override the default main target from above.
+#
+# 3. All sources of the first '.MAIN: sources' line.  Any further .MAIN line
+#    is treated as if .MAIN were a regular name.
+#
+# This test only covers items 1 and 3.  For item 2, see cond-func-make.mk.
+
+first-main-target:
+       : Making ${.TARGET}.
+
+# Even though the main-target would actually be made at this point, it is
+# ignored by the make() function.
+.if make(first-main-target)
+.  error
+.endif
+
+# Declaring a target via the .MAIN dependency adds it to the targets to be
+# created (opts.create), but only that list was empty at the beginning of
+# the line.  This implies that several main targets can be set at the name
+# time, but they have to be in the same dependency group.
+#
+# See ParseDoDependencyTargetSpecial, branch SP_MAIN.
+.MAIN: dot-main-target-1a dot-main-target-1b
+
+.if !make(dot-main-target-1a)
+.  error
+.endif
+.if !make(dot-main-target-1b)
+.  error
+.endif
+
+dot-main-target-{1,2}{a,b}:
+       : Making ${.TARGET}.
+
+# At this point, the list of targets to be made (opts.create) is not empty
+# anymore.  ParseDoDependencyTargetSpecial therefore treats the .MAIN as if
+# it were an ordinary target.  Since .MAIN is not listed as a dependency
+# anywhere, it is not made.
+.if target(.MAIN)
+.  error
+.endif
+.MAIN: dot-main-target-2a dot-main-target-2b
+.if !target(.MAIN)
+.  error
+.endif
+.if make(dot-main-target-2a)
+.  error
+.endif



Home | Main Index | Thread Index | Old Index