aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2022-04-23 21:44:17 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2022-04-23 21:44:17 +0000
commit525d1e204bbc1779c4094384a417004591c3610f (patch)
tree6f5ed810eeef4f14fd0ecbc5fe12037e51d02e4c
parent835ee05f3c754d905099a3500f421dc01fab028f (diff)
downloadsrc-525d1e204bbc1779c4094384a417004591c3610f.tar.gz
src-525d1e204bbc1779c4094384a417004591c3610f.zip
Update dirdeps.mk
Latest dirdeps.mk is far more efficient when generating DIRDEPS_CACHE. Update dirdeps-options.mk to allow DEP_RELDIR to factor into option processing. This is not very interesting if all options are global.
-rw-r--r--share/mk/dirdeps-options.mk10
-rw-r--r--share/mk/dirdeps.mk102
2 files changed, 64 insertions, 48 deletions
diff --git a/share/mk/dirdeps-options.mk b/share/mk/dirdeps-options.mk
index bf5bb964ab47..b31d2033ae98 100644
--- a/share/mk/dirdeps-options.mk
+++ b/share/mk/dirdeps-options.mk
@@ -1,7 +1,6 @@
-# $FreeBSD$
-# $Id: dirdeps-options.mk,v 1.18 2020/12/22 18:10:34 sjg Exp $
+# $Id: dirdeps-options.mk,v 1.20 2022/03/17 20:11:36 sjg Exp $
#
-# @(#) Copyright (c) 2018-2020, Simon J. Gerraty
+# @(#) Copyright (c) 2018-2022, Simon J. Gerraty
#
# This file is provided in the hope that it will
# be of use. There is absolutely NO WARRANTY.
@@ -55,6 +54,7 @@ DIRDEPS_OPTIONS ?=
# :U below avoids potential errors when we :=
# some options can depend on TARGET_SPEC!
DIRDEPS_OPTIONS_QUALIFIER_LIST ?= \
+ ${DEP_RELDIR} \
${DEP_TARGET_SPEC:U${TARGET_SPEC}} \
${TARGET_SPEC_VARSr:U${TARGET_SPEC_VARS}:@v@${DEP_$v:U${$v}}@}
# note that we need to include $o in the variable _o$o
@@ -62,7 +62,9 @@ DIRDEPS_OPTIONS_QUALIFIER_LIST ?= \
.for o in ${DIRDEPS_OPTIONS}
.undef _o$o
.undef _v$o
-.for x in ${DIRDEPS_OPTIONS_QUALIFIER_LIST}
+.for x in ${DIRDEPS_OPTIONS_QUALIFIER_LIST:S,^,${DEP_RELDIR}.,} \
+ ${DIRDEPS_OPTIONS_QUALIFIER_LIST}
+#.info MK_$o.$x=${MK_$o.$x:Uundefined}
.if defined(MK_$o.$x)
_o$o ?= MK_$o.$x
_v$o ?= ${MK_$o.$x}
diff --git a/share/mk/dirdeps.mk b/share/mk/dirdeps.mk
index b0d4a761281e..ee31e47c76c5 100644
--- a/share/mk/dirdeps.mk
+++ b/share/mk/dirdeps.mk
@@ -1,7 +1,6 @@
-# $FreeBSD$
-# $Id: dirdeps.mk,v 1.147 2021/12/14 02:09:53 sjg Exp $
+# $Id: dirdeps.mk,v 1.151 2022/01/28 01:13:14 sjg Exp $
-# Copyright (c) 2010-2021, Simon J. Gerraty
+# Copyright (c) 2010-2022, Simon J. Gerraty
# Copyright (c) 2010-2018, Juniper Networks, Inc.
# All rights reserved.
#
@@ -135,6 +134,16 @@
# A list of MACHINEs the current directory should not be
# built for.
#
+# DIRDEPS_EXPORT_VARS (DEP_EXPORT_VARS)
+# It is discouraged, but sometimes necessary for a
+# Makefile.depend file to influence the environment.
+# Doing this is correctly (especially if using DIRDEPS_CACHE) is
+# tricky so a Makefile.depend file can set DIRDEPS_EXPORT_VARS
+# and dirdeps.mk will do the deed:
+#
+# MK_UEFI = yes
+# DIRDEPS_EXPORT_VARS = MK_UEFI
+#
# _build_xtra_dirs
# local.dirdeps.mk can add targets to this variable.
# They will be hooked into the build, but independent of
@@ -162,6 +171,8 @@ _DIRDEP_USE_LEVEL?= 0
.if ${.MAKE.LEVEL} == ${_DIRDEP_USE_LEVEL}
# only the first instance is interested in all this
+# the first time we are included the _DIRDEP_USE target will not be defined
+# we can use this as a clue to do initialization and other one time things.
.if !target(_DIRDEP_USE)
# do some setup we only need once
@@ -185,6 +196,8 @@ TARGET_MACHINE := ${MACHINE}
.endif
# disable DIRDEPS_CACHE as it does not like this trick
MK_DIRDEPS_CACHE = no
+# incase anyone needs to know
+_dirdeps_cmdline:
.endif
# make sure we get the behavior we expect
@@ -258,12 +271,36 @@ _machine_dependfiles := ${.MAKE.DEPENDFILE_PREFERENCE:T:M*${MACHINE}*}
.endif
.endif
-
# this is how we identify non-machine specific dependfiles
N_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N*${MACHINE}*:${M_ListToSkip}}
+# this gets reset for each dirdep we check
+DEP_RELDIR ?= ${RELDIR}
+
+# remember the initial value of DEP_RELDIR - we test for it below.
+_DEP_RELDIR := ${DEP_RELDIR}
+
+# this can cause lots of output!
+# set to a set of glob expressions that might match RELDIR
+DEBUG_DIRDEPS ?= no
+
+# make sure this target exists
+dirdeps: beforedirdeps .WAIT
+beforedirdeps:
+
.endif # !target(_DIRDEP_USE)
+.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} != ""
+_debug_reldir = 1
+.else
+_debug_reldir = 0
+.endif
+.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend depend:L:M$x}@} != ""
+_debug_search = 1
+.else
+_debug_search = 0
+.endif
+
# First off, we want to know what ${MACHINE} to build for.
# This can be complicated if we are using a mixture of ${MACHINE} specific
# and non-specific Makefile.depend*
@@ -298,26 +335,6 @@ DEP_MACHINE := ${_DEP_TARGET_SPEC}
_build_all_dirs =
_build_xtra_dirs =
-# the first time we are included the _DIRDEP_USE target will not be defined
-# we can use this as a clue to do initialization and other one time things.
-.if !target(_DIRDEP_USE)
-# make sure this target exists
-dirdeps: beforedirdeps .WAIT
-beforedirdeps:
-
-# We normally expect to be included by Makefile.depend.*
-# which sets the DEP_* macros below.
-DEP_RELDIR ?= ${RELDIR}
-
-# this can cause lots of output!
-# set to a set of glob expressions that might match RELDIR
-DEBUG_DIRDEPS ?= no
-
-# remember the initial value of DEP_RELDIR - we test for it below.
-_DEP_RELDIR := ${DEP_RELDIR}
-
-.endif
-
# DIRDEPS_CACHE can be very handy for debugging.
# Also if repeatedly building the same target,
# we can avoid the overhead of re-computing the tree dependencies.
@@ -330,16 +347,6 @@ BUILD_DIRDEPS ?= yes
DIRDEPS_CACHE ?= ${_OBJDIR:tA}/dirdeps.cache${_TARGETS:U${.TARGETS}:Nall:O:u:ts-:S,/,_,g:S,^,.,:N.}
.endif
-.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} != ""
-_debug_reldir = 1
-.else
-_debug_reldir = 0
-.endif
-.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend:L:M$x}@} != ""
-_debug_search = 1
-.else
-_debug_search = 0
-.endif
# pickup customizations
# as below you can use !target(_DIRDEP_USE) to protect things
@@ -533,7 +540,10 @@ BUILD_DIRDEPS = no
dirdeps: dirdeps-cached
dirdeps-cached: ${DIRDEPS_CACHE} .MAKE
@echo "${TRACER}Using ${DIRDEPS_CACHE}"
- @MAKELEVEL=${.MAKE.LEVEL} ${.MAKE} -C ${_CURDIR} -f ${DIRDEPS_CACHE} \
+ @MAKELEVEL=${.MAKE.LEVEL} \
+ TARGET_SPEC=${TARGET_SPEC} \
+ ${TARGET_SPEC_VARS:@v@$v=${$v}@} \
+ ${.MAKE} -C ${_CURDIR} -f ${DIRDEPS_CACHE} \
dirdeps MK_DIRDEPS_CACHE=no BUILD_DIRDEPS=no
# leaf makefiles rarely work for building DIRDEPS_CACHE
@@ -702,15 +712,18 @@ _build_all_dirs := ${_build_all_dirs:O:u}
.if ${.MAKEFLAGS:M-V${_V_READ_DIRDEPS:U}} == ""
.if !empty(_build_all_dirs)
.if ${BUILD_DIRDEPS_CACHE} == "yes"
-x!= echo; { echo; echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}'; } >&3
+# we use _cache_script to minimize the number of times we fork the shell
+_cache_script = echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}';
# guard against _new_dirdeps being too big for a single command line
_new_dirdeps := ${_build_all_dirs:@x@${target($x):?:$x}@:S,^${SRCTOP}/,,}
_cache_xtra_deps := ${_build_xtra_dirs:S,^${SRCTOP}/,,}
.export _cache_xtra_deps _new_dirdeps
-.if !empty(DEP_EXPORT_VARS)
+.if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS)
# Discouraged, but there are always exceptions.
# Handle it here rather than explain how.
-x!= echo; { echo; ${DEP_EXPORT_VARS:@v@echo '$v=${$v}';@} echo '.export ${DEP_EXPORT_VARS}'; echo; } >&3
+DIRDEPS_EXPORT_VARS ?= ${DEP_EXPORT_VARS}
+_cache_xvars := echo; ${DIRDEPS_EXPORT_VARS:@v@echo '$v = ${$v}';@} echo '.export ${DIRDEPS_EXPORT_VARS}'; echo;
+_cache_script += ${_cache_xvars}
.endif
.else
# this makes it all happen
@@ -722,16 +735,17 @@ ${_build_all_dirs}: _DIRDEP_USE
.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs:S,^${SRCTOP}/,,}
.endif
-.if !empty(DEP_EXPORT_VARS)
-.export ${DEP_EXPORT_VARS}
-DEP_EXPORT_VARS=
+.if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS)
+.export ${DIRDEPS_EXPORT_VARS} ${DEP_EXPORT_VARS}
+DIRDEPS_EXPORT_VARS =
+DEP_EXPORT_VARS =
.endif
# this builds the dependency graph
.for m in ${_machines}
.if ${BUILD_DIRDEPS_CACHE} == "yes" && !empty(_build_dirs)
_cache_deps =
-x!= echo; { echo; echo 'DIRDEPS.${_this_dir}.$m = \'; } >&3
+_cache_script += echo; echo 'DIRDEPS.${_this_dir}.$m = \';
.endif
# it would be nice to do :N${.TARGET}
.if !empty(__qual_depdirs)
@@ -754,10 +768,10 @@ ${_this_dir}.$m: ${_build_dirs:M*.$q}
_cache_deps += ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,}
.if !empty(_cache_deps)
.export _cache_deps
-x!= echo; for x in $$_cache_deps; do echo " _{SRCTOP}/$$x \\"; done >&3
+_cache_script += for x in $$_cache_deps; do echo " _{SRCTOP}/$$x \\"; done;
.endif
# anything in _{build,env}_xtra_dirs is hooked to dirdeps: only
-x!= echo; { echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \
+x!= echo; { echo; ${_cache_script} echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \
echo; echo 'dirdeps: ${_this_dir}.$m \'; \
for x in $$_cache_xtra_deps; do echo " _{SRCTOP}/$$x \\"; done; \
echo; for x in $$_new_dirdeps; do echo "_{SRCTOP}/$$x: _DIRDEP_USE"; done; } >&3