Skip to content

Commit

Permalink
Makefile: Fix several issues with bmake upgrade
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jrtc27 committed Jan 29, 2025
1 parent b8529e7 commit 697fd84
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

#
Expand Down Expand Up @@ -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

#
Expand Down

0 comments on commit 697fd84

Please sign in to comment.