From d7173250be0de51823a6d67876e18001bd133d58 Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Sun, 13 Nov 2016 00:11:02 +0000 Subject: [PATCH] Consolidate the "don't build" optimizations into _SKIP_BUILD. _SKIP_BUILD will be set when nothing is expected to be built. This can be used to optimize some tree-walks and operations which don't need to load dependency files or generate dependencies via beforebuild-style hacks. MFC after: 2 weeks Sponsored by: Dell EMC Isilon --- share/mk/bsd.dep.mk | 6 ++---- share/mk/bsd.init.mk | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/share/mk/bsd.dep.mk b/share/mk/bsd.dep.mk index c5d242f166e..9d975dac617 100644 --- a/share/mk/bsd.dep.mk +++ b/share/mk/bsd.dep.mk @@ -77,12 +77,10 @@ _meta_filemon= 1 .endif # Skip reading .depend when not needed to speed up tree-walks and simple -# lookups. For install, only do this if no other targets are specified. +# lookups. See _SKIP_BUILD logic in bsd.init.mk for more details. # Also skip generating or including .depend.* files if in meta+filemon mode # since it will track dependencies itself. OBJS_DEPEND_GUESS is still used. -.if !empty(.MAKEFLAGS:M-V${_V_READ_DEPEND}) || make(obj) || make(clean*) || \ - ${.TARGETS:M*install*} == ${.TARGETS} || \ - make(analyze) || defined(_meta_filemon) || make(print-dir) +.if defined(_SKIP_BUILD) || defined(_meta_filemon) _SKIP_READ_DEPEND= 1 .if ${MK_DIRDEPS_BUILD} == "no" || make(analyze) || make(print-dir) .MAKE.DEPENDFILE= /dev/null diff --git a/share/mk/bsd.init.mk b/share/mk/bsd.init.mk index 35cd3b1a90d..5e8951a6e60 100644 --- a/share/mk/bsd.init.mk +++ b/share/mk/bsd.init.mk @@ -16,11 +16,27 @@ ____: .include .MAIN: all -.if ${.MAKE.LEVEL:U1} == 0 && ${BUILD_AT_LEVEL0:Uyes:tl} == "no" && !make(clean*) -# this tells lib.mk and prog.mk to not actually build anything -_SKIP_BUILD = not building at level 0 +# Some targets need to know when something may build. This is used to +# optimize targets that are only needed when building something, such as +# (not) reading in depend files. For DIRDEPS_BUILD, it will only calculate +# the dependency graph at .MAKE.LEVEL==0, so nothing should be built there. +# Skip "build" logic if: +# - DIRDEPS_BUILD at MAKELEVEL 0 +# - make -V is used without an override +# - make install is used without other targets. This is to avoid breaking +# things like 'make all install' or 'make foo install'. +# - non-build targets are called +.if ${MK_DIRDEPS_BUILD} == "yes" && ${.MAKE.LEVEL:U1} == 0 && \ + ${BUILD_AT_LEVEL0:Uyes:tl} == "no" && !make(clean*) +_SKIP_BUILD= not building at level 0 +.elseif !empty(.MAKEFLAGS:M-V${_V_DO_BUILD}) || \ + ${.TARGETS:M*install*} == ${.TARGETS} || \ + make(clean*) || make(obj) || make(analyze) || make(print-dir) || \ + make(destroy*) +# Skip building, but don't show a warning. +_SKIP_BUILD= .endif -.if ${.MAKE.LEVEL} > 0 && !empty(_SKIP_BUILD) +.if ${MK_DIRDEPS_BUILD} == "yes" && ${.MAKE.LEVEL} > 0 && !empty(_SKIP_BUILD) .warning ${_SKIP_BUILD} .endif