The branch main has been updated by jrtc27:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=697fd8476ea7025e3c79d57669d04ff3274a6e38

commit 697fd8476ea7025e3c79d57669d04ff3274a6e38
Author:     Jessica Clarke <jrt...@freebsd.org>
AuthorDate: 2025-01-29 19:17:09 +0000
Commit:     Jessica Clarke <jrt...@freebsd.org>
CommitDate: 2025-01-29 19:17:09 +0000

    Makefile: Fix several issues with bmake upgrade
    
    Firstly, if NEED_MAKE_UPGRADE isn't set, we shouldn't use whatever
    bootstrapped bmake happens to be lying around. We're not going to re-run
    the bmake target, so won't make sure it's up-to-date, and thus it could
    be some ancient unsupported version. We can still, however, optimise
    setting SUB_MAKE when the file exists, so long as it's guarded by
    NEED_MAKE_UPGRADE.
    
    Secondly, make kernel-toolchain should also bootstrap bmake if needed,
    since it's supposed to be the subset of buildworld needed for building a
    kernel.
    
    Finally, if there is a stale bootstrapped bmake lying around that isn't
    needed, delete it, since it will only cause confusion, and as far as I
    can tell nothing else will clean it up, not even cleandir twice. So as
    to ensure nobody's doing anything crazy with MYMAKE that would cause us
    to delete something unexpected, or that would change behaviour by no
    longer checking exists(${MYMAKE}) and using that regardless of version
    checks, emit an error if the definition in use is not our own.
    
    Reviewed by:    emaste, sjg, imp
    Differential Revision:  https://reviews.freebsd.org/D48708
---
 Makefile | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 1970cc736829..b094a7ff8149 100644
--- a/Makefile
+++ b/Makefile
@@ -258,17 +258,22 @@ WANT_MAKE_VERSION= 20160604
 # 20160220 - support .dinclude for FAST_DEPEND.
 WANT_MAKE_VERSION= 20160220
 .endif
+.if defined(MYMAKE)
+.error MYMAKE cannot be overridden, use as command name instead
+.endif
 MYMAKE=                ${OBJROOT}make.${MACHINE}/bmake
 .if defined(ALWAYS_BOOTSTRAP_MAKE) || \
     (defined(WANT_MAKE_VERSION) && ${MAKE_VERSION} < ${WANT_MAKE_VERSION})
 NEED_MAKE_UPGRADE= t
 .endif
-.if exists(${MYMAKE})
+.if defined(NEED_MAKE_UPGRADE)
+. if exists(${MYMAKE})
 SUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
-.elif defined(NEED_MAKE_UPGRADE)
+. else
 # It may not exist yet but we may cause it to.
 SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
        -m ${.CURDIR}/share/mk
+. endif
 .else
 SUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
 .endif
@@ -359,15 +364,16 @@ _assert_target: .PHONY .MAKE
 .endfor
 
 #
-# Make sure we have an up-to-date make(1). Only world and buildworld
-# should do this as those are the initial targets used for upgrades.
-# The user can define ALWAYS_CHECK_MAKE to have this check performed
-# for all targets.
+# Make sure we have an up-to-date make(1). Only world, buildworld and
+# kernel-toolchain should do this as those are the initial targets used
+# for upgrades. The user can define ALWAYS_CHECK_MAKE to have this check
+# performed for all targets.
 #
 .if defined(ALWAYS_CHECK_MAKE)
 ${TGTS}: upgrade_checks
 .else
 buildworld: upgrade_checks
+kernel-toolchain: upgrade_checks
 .endif
 
 #
@@ -457,6 +463,9 @@ kernel: buildkernel installkernel .PHONY
 upgrade_checks: .PHONY
 .if defined(NEED_MAKE_UPGRADE)
        @${_+_}(cd ${.CURDIR} && ${MAKE} bmake)
+.elif exists(${MYMAKE:H})
+       @echo "Removing stale bmake(1)"
+       rm -r ${MYMAKE:H}
 .endif
 
 #

Reply via email to