1*6eef5f0cSAntonio Huete Jimenez# $Id: dirdeps.mk,v 1.152 2022/08/01 23:09:19 sjg Exp $ 25f1e34d9SAlexandre Perrin 3*6eef5f0cSAntonio Huete Jimenez# Copyright (c) 2010-2022, Simon J. Gerraty 4ca58f742SDaniel Fojt# Copyright (c) 2010-2018, Juniper Networks, Inc. 55f1e34d9SAlexandre Perrin# All rights reserved. 65f1e34d9SAlexandre Perrin# 75f1e34d9SAlexandre Perrin# Redistribution and use in source and binary forms, with or without 85f1e34d9SAlexandre Perrin# modification, are permitted provided that the following conditions 95f1e34d9SAlexandre Perrin# are met: 105f1e34d9SAlexandre Perrin# 1. Redistributions of source code must retain the above copyright 115f1e34d9SAlexandre Perrin# notice, this list of conditions and the following disclaimer. 125f1e34d9SAlexandre Perrin# 2. Redistributions in binary form must reproduce the above copyright 135f1e34d9SAlexandre Perrin# notice, this list of conditions and the following disclaimer in the 145f1e34d9SAlexandre Perrin# documentation and/or other materials provided with the distribution. 155f1e34d9SAlexandre Perrin# 165f1e34d9SAlexandre Perrin# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175f1e34d9SAlexandre Perrin# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185f1e34d9SAlexandre Perrin# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195f1e34d9SAlexandre Perrin# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205f1e34d9SAlexandre Perrin# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215f1e34d9SAlexandre Perrin# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225f1e34d9SAlexandre Perrin# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235f1e34d9SAlexandre Perrin# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245f1e34d9SAlexandre Perrin# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255f1e34d9SAlexandre Perrin# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265f1e34d9SAlexandre Perrin# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275f1e34d9SAlexandre Perrin 285f1e34d9SAlexandre Perrin# Much of the complexity here is for supporting cross-building. 295f1e34d9SAlexandre Perrin# If a tree does not support that, simply using plain Makefile.depend 305f1e34d9SAlexandre Perrin# should provide sufficient clue. 315f1e34d9SAlexandre Perrin# Otherwise the recommendation is to use Makefile.depend.${MACHINE} 325f1e34d9SAlexandre Perrin# as expected below. 335f1e34d9SAlexandre Perrin 345f1e34d9SAlexandre Perrin# Note: this file gets multiply included. 355f1e34d9SAlexandre Perrin# This is what we do with DIRDEPS 365f1e34d9SAlexandre Perrin 375f1e34d9SAlexandre Perrin# DIRDEPS: 385f1e34d9SAlexandre Perrin# This is a list of directories - relative to SRCTOP, it is 395f1e34d9SAlexandre Perrin# normally only of interest to .MAKE.LEVEL 0. 405f1e34d9SAlexandre Perrin# In some cases the entry may be qualified with a .<machine> 415f1e34d9SAlexandre Perrin# or .<target_spec> suffix (see TARGET_SPEC_VARS below), 425f1e34d9SAlexandre Perrin# for example to force building something for the pseudo 435f1e34d9SAlexandre Perrin# machines "host" or "common" regardless of current ${MACHINE}. 445f1e34d9SAlexandre Perrin# 455f1e34d9SAlexandre Perrin# All unqualified entries end up being qualified with .${TARGET_SPEC} 465f1e34d9SAlexandre Perrin# and partially qualified (if TARGET_SPEC_VARS has multiple 475f1e34d9SAlexandre Perrin# entries) are also expanded to a full .<target_spec>. 486a91b982SJohn Marino# The _DIRDEP_USE target uses the suffix to set TARGET_SPEC 495f1e34d9SAlexandre Perrin# correctly when visiting each entry. 505f1e34d9SAlexandre Perrin# 515f1e34d9SAlexandre Perrin# The fully qualified directory entries are used to construct a 525f1e34d9SAlexandre Perrin# dependency graph that will drive the build later. 535f1e34d9SAlexandre Perrin# 545f1e34d9SAlexandre Perrin# Also, for each fully qualified directory target, we will search 555f1e34d9SAlexandre Perrin# using ${.MAKE.DEPENDFILE_PREFERENCE} to find additional 565f1e34d9SAlexandre Perrin# dependencies. We use Makefile.depend (default value for 575f1e34d9SAlexandre Perrin# .MAKE.DEPENDFILE_PREFIX) to refer to these makefiles to 585f1e34d9SAlexandre Perrin# distinguish them from others. 595f1e34d9SAlexandre Perrin# 60ca58f742SDaniel Fojt# Before each Makefile.depend file is read, we set 61ca58f742SDaniel Fojt# DEP_RELDIR to be the RELDIR (path relative to SRCTOP) for 62ca58f742SDaniel Fojt# its directory, and DEP_MACHINE etc according to the .<target_spec> 63ca58f742SDaniel Fojt# represented by the suffix of the corresponding target. 64ca58f742SDaniel Fojt# 65ca58f742SDaniel Fojt# Since each Makefile.depend file includes dirdeps.mk, this 665f1e34d9SAlexandre Perrin# processing is recursive and results in .MAKE.LEVEL 0 learning the 675f1e34d9SAlexandre Perrin# dependencies of the tree wrt the initial directory (_DEP_RELDIR). 685f1e34d9SAlexandre Perrin# 69*6eef5f0cSAntonio Huete Jimenez# NOTE: given the extent of processing that DIRDEPS undergoes it 70*6eef5f0cSAntonio Huete Jimenez# is important that any variables in entries use :U to guard 71*6eef5f0cSAntonio Huete Jimenez# against surprises when undefined. 72*6eef5f0cSAntonio Huete Jimenez# 735f1e34d9SAlexandre Perrin# TARGET_SPEC_VARS 745f1e34d9SAlexandre Perrin# The default value is just MACHINE, and for most environments 756a91b982SJohn Marino# this is sufficient. The _DIRDEP_USE target actually sets 765f1e34d9SAlexandre Perrin# both MACHINE and TARGET_SPEC to the suffix of the current 775f1e34d9SAlexandre Perrin# target so that in the general case TARGET_SPEC can be ignored. 785f1e34d9SAlexandre Perrin# 795f1e34d9SAlexandre Perrin# If more than MACHINE is needed then sys.mk needs to decompose 805f1e34d9SAlexandre Perrin# TARGET_SPEC and set the relevant variables accordingly. 815f1e34d9SAlexandre Perrin# It is important that MACHINE be included in and actually be 825f1e34d9SAlexandre Perrin# the first member of TARGET_SPEC_VARS. This allows other 835f1e34d9SAlexandre Perrin# variables to be considered optional, and some of the treatment 845f1e34d9SAlexandre Perrin# below relies on MACHINE being the first entry. 855f1e34d9SAlexandre Perrin# Note: TARGET_SPEC cannot contain any '.'s so the target 865f1e34d9SAlexandre Perrin# triple used by compiler folk won't work (directly anyway). 875f1e34d9SAlexandre Perrin# 885f1e34d9SAlexandre Perrin# For example: 895f1e34d9SAlexandre Perrin# 905f1e34d9SAlexandre Perrin# # Always list MACHINE first, 915f1e34d9SAlexandre Perrin# # other variables might be optional. 925f1e34d9SAlexandre Perrin# TARGET_SPEC_VARS = MACHINE TARGET_OS 935f1e34d9SAlexandre Perrin# .if ${TARGET_SPEC:Uno:M*,*} != "" 945f1e34d9SAlexandre Perrin# _tspec := ${TARGET_SPEC:S/,/ /g} 955f1e34d9SAlexandre Perrin# MACHINE := ${_tspec:[1]} 965f1e34d9SAlexandre Perrin# TARGET_OS := ${_tspec:[2]} 975f1e34d9SAlexandre Perrin# # etc. 985f1e34d9SAlexandre Perrin# # We need to stop that TARGET_SPEC affecting any submakes 995f1e34d9SAlexandre Perrin# # and deal with MACHINE=${TARGET_SPEC} in the environment. 1005f1e34d9SAlexandre Perrin# TARGET_SPEC = 1015f1e34d9SAlexandre Perrin# # export but do not track 1025f1e34d9SAlexandre Perrin# .export-env TARGET_SPEC 1035f1e34d9SAlexandre Perrin# .export ${TARGET_SPEC_VARS} 1045f1e34d9SAlexandre Perrin# .for v in ${TARGET_SPEC_VARS:O:u} 1055f1e34d9SAlexandre Perrin# .if empty($v) 1065f1e34d9SAlexandre Perrin# .undef $v 1075f1e34d9SAlexandre Perrin# .endif 1085f1e34d9SAlexandre Perrin# .endfor 1095f1e34d9SAlexandre Perrin# .endif 1105f1e34d9SAlexandre Perrin# # make sure we know what TARGET_SPEC is 1115f1e34d9SAlexandre Perrin# # as we may need it to find Makefile.depend* 1125f1e34d9SAlexandre Perrin# TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} 1135f1e34d9SAlexandre Perrin# 114ca58f742SDaniel Fojt# The following variables can influence the initial DIRDEPS 115ca58f742SDaniel Fojt# computation with regard to the TARGET_SPECs that will be 116ca58f742SDaniel Fojt# built. 117ca58f742SDaniel Fojt# Most should also be considered by init.mk 118ca58f742SDaniel Fojt# 119ca58f742SDaniel Fojt# ONLY_TARGET_SPEC_LIST 120ca58f742SDaniel Fojt# Defines a list of TARGET_SPECs for which the current 121ca58f742SDaniel Fojt# directory can be built. 122ca58f742SDaniel Fojt# If ALL_MACHINES is defined, we build for all the 123ca58f742SDaniel Fojt# TARGET_SPECs listed. 124ca58f742SDaniel Fojt# 125ca58f742SDaniel Fojt# ONLY_MACHINE_LIST 126ca58f742SDaniel Fojt# As for ONLY_TARGET_SPEC_LIST but only specifies 127ca58f742SDaniel Fojt# MACHINEs. 128ca58f742SDaniel Fojt# 129ca58f742SDaniel Fojt# NOT_TARGET_SPEC_LIST 130ca58f742SDaniel Fojt# A list of TARGET_SPECs for which the current 131ca58f742SDaniel Fojt# directory should not be built. 132ca58f742SDaniel Fojt# 133ca58f742SDaniel Fojt# NOT_MACHINE_LIST 134ca58f742SDaniel Fojt# A list of MACHINEs the current directory should not be 135ca58f742SDaniel Fojt# built for. 136ca58f742SDaniel Fojt# 137*6eef5f0cSAntonio Huete Jimenez# DIRDEPS_EXPORT_VARS (DEP_EXPORT_VARS) 138*6eef5f0cSAntonio Huete Jimenez# It is discouraged, but sometimes necessary for a 139*6eef5f0cSAntonio Huete Jimenez# Makefile.depend file to influence the environment. 140*6eef5f0cSAntonio Huete Jimenez# Doing this is correctly (especially if using DIRDEPS_CACHE) is 141*6eef5f0cSAntonio Huete Jimenez# tricky so a Makefile.depend file can set DIRDEPS_EXPORT_VARS 142*6eef5f0cSAntonio Huete Jimenez# and dirdeps.mk will do the deed: 143*6eef5f0cSAntonio Huete Jimenez# 144*6eef5f0cSAntonio Huete Jimenez# MK_UEFI = yes 145*6eef5f0cSAntonio Huete Jimenez# DIRDEPS_EXPORT_VARS = MK_UEFI 146*6eef5f0cSAntonio Huete Jimenez# 147a34d5fb1SAntonio Huete Jimenez# _build_xtra_dirs 148a34d5fb1SAntonio Huete Jimenez# local.dirdeps.mk can add targets to this variable. 149a34d5fb1SAntonio Huete Jimenez# They will be hooked into the build, but independent of 150a34d5fb1SAntonio Huete Jimenez# any other DIRDEP. 151a34d5fb1SAntonio Huete Jimenez# 152a34d5fb1SAntonio Huete Jimenez# This allows for adding TESTS to the build, such that the build 153a34d5fb1SAntonio Huete Jimenez# if any test fails, but without the risk of introducing 154a34d5fb1SAntonio Huete Jimenez# circular dependencies. 155a34d5fb1SAntonio Huete Jimenez 156a34d5fb1SAntonio Huete Jimeneznow_utc ?= ${%s:L:gmtime} 157a34d5fb1SAntonio Huete Jimenez.if !defined(start_utc) 158a34d5fb1SAntonio Huete Jimenezstart_utc := ${now_utc} 159a34d5fb1SAntonio Huete Jimenez.endif 160ca58f742SDaniel Fojt 161ca58f742SDaniel Fojt.if !target(bootstrap) && (make(bootstrap) || \ 162ca58f742SDaniel Fojt make(bootstrap-this) || \ 163ca58f742SDaniel Fojt make(bootstrap-recurse) || \ 164ca58f742SDaniel Fojt make(bootstrap-empty)) 165ca58f742SDaniel Fojt# disable most of below 166ca58f742SDaniel Fojt.MAKE.LEVEL = 1 167ca58f742SDaniel Fojt.endif 1685f1e34d9SAlexandre Perrin 169f445c897SJohn Marino# touch this at your peril 170f445c897SJohn Marino_DIRDEP_USE_LEVEL?= 0 171f445c897SJohn Marino.if ${.MAKE.LEVEL} == ${_DIRDEP_USE_LEVEL} 1725f1e34d9SAlexandre Perrin# only the first instance is interested in all this 1735f1e34d9SAlexandre Perrin 174*6eef5f0cSAntonio Huete Jimenez# the first time we are included the _DIRDEP_USE target will not be defined 175*6eef5f0cSAntonio Huete Jimenez# we can use this as a clue to do initialization and other one time things. 1765f1e34d9SAlexandre Perrin.if !target(_DIRDEP_USE) 177f445c897SJohn Marino 1785f1e34d9SAlexandre Perrin# do some setup we only need once 1795f1e34d9SAlexandre Perrin_CURDIR ?= ${.CURDIR} 180f445c897SJohn Marino_OBJDIR ?= ${.OBJDIR} 181f445c897SJohn Marino 182f445c897SJohn Marino.if ${MAKEFILE:T} == ${.PARSEFILE} && empty(DIRDEPS) && ${.TARGETS:Uall:M*/*} != "" 183f445c897SJohn Marino# This little trick let's us do 184f445c897SJohn Marino# 185f445c897SJohn Marino# mk -f dirdeps.mk some/dir.${TARGET_SPEC} 186f445c897SJohn Marino# 187f445c897SJohn Marinoall: 188f445c897SJohn Marino${.TARGETS:Nall}: all 189f445c897SJohn MarinoDIRDEPS := ${.TARGETS:M*[/.]*} 190f445c897SJohn Marino# so that -DNO_DIRDEPS works 191f445c897SJohn MarinoDEP_RELDIR := ${DIRDEPS:[1]:R} 192f445c897SJohn Marino# this will become DEP_MACHINE below 193f445c897SJohn MarinoTARGET_MACHINE := ${DIRDEPS:[1]:E:C/,.*//} 194f445c897SJohn Marino.if ${TARGET_MACHINE:N*/*} == "" 195f445c897SJohn MarinoTARGET_MACHINE := ${MACHINE} 196f445c897SJohn Marino.endif 197f445c897SJohn Marino# disable DIRDEPS_CACHE as it does not like this trick 198f445c897SJohn MarinoMK_DIRDEPS_CACHE = no 199*6eef5f0cSAntonio Huete Jimenez# incase anyone needs to know 200*6eef5f0cSAntonio Huete Jimenez_dirdeps_cmdline: 201f445c897SJohn Marino.endif 202f445c897SJohn Marino 203f445c897SJohn Marino# make sure we get the behavior we expect 204f445c897SJohn Marino.MAKE.SAVE_DOLLARS = no 2055f1e34d9SAlexandre Perrin 2065f1e34d9SAlexandre Perrin# make sure these are empty to start with 2075f1e34d9SAlexandre Perrin_DEP_TARGET_SPEC = 2085f1e34d9SAlexandre Perrin 2095f1e34d9SAlexandre Perrin# If TARGET_SPEC_VARS is other than just MACHINE 2105f1e34d9SAlexandre Perrin# it should be set by sys.mk or similar by now. 2115f1e34d9SAlexandre Perrin# TARGET_SPEC must not contain any '.'s. 2125f1e34d9SAlexandre PerrinTARGET_SPEC_VARS ?= MACHINE 2135f1e34d9SAlexandre Perrin# this is what we started with 2145f1e34d9SAlexandre PerrinTARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} 2155f1e34d9SAlexandre Perrin# this is what we mostly use below 2165f1e34d9SAlexandre PerrinDEP_TARGET_SPEC = ${TARGET_SPEC_VARS:S,^,DEP_,:@v@${$v:U}@:ts,} 2175f1e34d9SAlexandre Perrin# make sure we have defaults 2185f1e34d9SAlexandre Perrin.for v in ${TARGET_SPEC_VARS} 2195f1e34d9SAlexandre PerrinDEP_$v ?= ${$v} 2205f1e34d9SAlexandre Perrin.endfor 2215f1e34d9SAlexandre Perrin 2225f1e34d9SAlexandre Perrin.if ${TARGET_SPEC_VARS:[#]} > 1 2235f1e34d9SAlexandre Perrin# Ok, this gets more complex (putting it mildly). 2245f1e34d9SAlexandre Perrin# In order to stay sane, we need to ensure that all the build_dirs 2255f1e34d9SAlexandre Perrin# we compute below are fully qualified wrt DEP_TARGET_SPEC. 2265f1e34d9SAlexandre Perrin# The makefiles may only partially specify (eg. MACHINE only), 2275f1e34d9SAlexandre Perrin# so we need to construct a set of modifiers to fill in the gaps. 228ca58f742SDaniel Fojt.if ${MAKE_VERSION} >= 20170130 229ca58f742SDaniel Fojt_tspec_x := ${TARGET_SPEC_VARS:range} 230ca58f742SDaniel Fojt.else 231a34d5fb1SAntonio Huete Jimenez# do it the hard way 232a34d5fb1SAntonio Huete Jimenez_tspec_x := ${TARGET_SPEC_VARS:[#]:@x@i=1;while [ $$i -le $x ]; do echo $$i; i=$$((i + 1)); done;@:sh} 233ca58f742SDaniel Fojt.endif 2345f1e34d9SAlexandre Perrin# this handles unqualified entries 2356a91b982SJohn MarinoM_dep_qual_fixes = C;(/[^/.,]+)$$;\1.$${DEP_TARGET_SPEC}; 2365f1e34d9SAlexandre Perrin# there needs to be at least one item missing for these to make sense 2375f1e34d9SAlexandre Perrin.for i in ${_tspec_x:[2..-1]} 2385f1e34d9SAlexandre Perrin_tspec_m$i := ${TARGET_SPEC_VARS:[2..$i]:@w@[^,]+@:ts,} 2396a91b982SJohn Marino_tspec_a$i := ,${TARGET_SPEC_VARS:[$i..-1]:@v@$$$${DEP_$v}@:ts,} 2405f1e34d9SAlexandre PerrinM_dep_qual_fixes += C;(\.${_tspec_m$i})$$;\1${_tspec_a$i}; 2415f1e34d9SAlexandre Perrin.endfor 242a34d5fb1SAntonio Huete JimenezTARGET_SPEC_VARSr := ${TARGET_SPEC_VARS:[-1..1]} 2435f1e34d9SAlexandre Perrin.else 2445f1e34d9SAlexandre Perrin# A harmless? default. 2455f1e34d9SAlexandre PerrinM_dep_qual_fixes = U 2465f1e34d9SAlexandre Perrin.endif 2475f1e34d9SAlexandre Perrin 2485f1e34d9SAlexandre Perrin.if !defined(.MAKE.DEPENDFILE_PREFERENCE) 2495f1e34d9SAlexandre Perrin# .MAKE.DEPENDFILE_PREFERENCE makes the logic below neater? 2505f1e34d9SAlexandre Perrin# you really want this set by sys.mk or similar 2515f1e34d9SAlexandre Perrin.MAKE.DEPENDFILE_PREFERENCE = ${_CURDIR}/${.MAKE.DEPENDFILE:T} 2525f1e34d9SAlexandre Perrin.if ${.MAKE.DEPENDFILE:E} == "${TARGET_SPEC}" 2535f1e34d9SAlexandre Perrin.if ${TARGET_SPEC} != ${MACHINE} 2545f1e34d9SAlexandre Perrin.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}.$${MACHINE} 2555f1e34d9SAlexandre Perrin.endif 2565f1e34d9SAlexandre Perrin.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R} 2575f1e34d9SAlexandre Perrin.endif 2585f1e34d9SAlexandre Perrin.endif 2595f1e34d9SAlexandre Perrin 2605f1e34d9SAlexandre Perrin_default_dependfile := ${.MAKE.DEPENDFILE_PREFERENCE:[1]:T} 2615f1e34d9SAlexandre Perrin_machine_dependfiles := ${.MAKE.DEPENDFILE_PREFERENCE:T:M*${MACHINE}*} 2625f1e34d9SAlexandre Perrin 2635f1e34d9SAlexandre Perrin# for machine specific dependfiles we require ${MACHINE} to be at the end 2645f1e34d9SAlexandre Perrin# also for the sake of sanity we require a common prefix 2655f1e34d9SAlexandre Perrin.if !defined(.MAKE.DEPENDFILE_PREFIX) 2665f1e34d9SAlexandre Perrin# knowing .MAKE.DEPENDFILE_PREFIX helps 2675f1e34d9SAlexandre Perrin.if !empty(_machine_dependfiles) 2685f1e34d9SAlexandre Perrin.MAKE.DEPENDFILE_PREFIX := ${_machine_dependfiles:[1]:T:R} 2695f1e34d9SAlexandre Perrin.else 2705f1e34d9SAlexandre Perrin.MAKE.DEPENDFILE_PREFIX := ${_default_dependfile:T} 2715f1e34d9SAlexandre Perrin.endif 2725f1e34d9SAlexandre Perrin.endif 2735f1e34d9SAlexandre Perrin 2745f1e34d9SAlexandre Perrin# this is how we identify non-machine specific dependfiles 2755f1e34d9SAlexandre PerrinN_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N*${MACHINE}*:${M_ListToSkip}} 2765f1e34d9SAlexandre Perrin 277*6eef5f0cSAntonio Huete Jimenez# this gets reset for each dirdep we check 278*6eef5f0cSAntonio Huete JimenezDEP_RELDIR ?= ${RELDIR} 279*6eef5f0cSAntonio Huete Jimenez 280*6eef5f0cSAntonio Huete Jimenez# remember the initial value of DEP_RELDIR - we test for it below. 281*6eef5f0cSAntonio Huete Jimenez_DEP_RELDIR := ${DEP_RELDIR} 282*6eef5f0cSAntonio Huete Jimenez 283*6eef5f0cSAntonio Huete Jimenez# this can cause lots of output! 284*6eef5f0cSAntonio Huete Jimenez# set to a set of glob expressions that might match RELDIR 285*6eef5f0cSAntonio Huete JimenezDEBUG_DIRDEPS ?= no 286*6eef5f0cSAntonio Huete Jimenez 287*6eef5f0cSAntonio Huete Jimenez# make sure this target exists 288*6eef5f0cSAntonio Huete Jimenezdirdeps: beforedirdeps .WAIT 289*6eef5f0cSAntonio Huete Jimenezbeforedirdeps: 290*6eef5f0cSAntonio Huete Jimenez 2915f1e34d9SAlexandre Perrin.endif # !target(_DIRDEP_USE) 2925f1e34d9SAlexandre Perrin 293*6eef5f0cSAntonio Huete Jimenez.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} != "" 294*6eef5f0cSAntonio Huete Jimenez_debug_reldir = 1 295*6eef5f0cSAntonio Huete Jimenez.else 296*6eef5f0cSAntonio Huete Jimenez_debug_reldir = 0 297*6eef5f0cSAntonio Huete Jimenez.endif 298*6eef5f0cSAntonio Huete Jimenez.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend depend:L:M$x}@} != "" 299*6eef5f0cSAntonio Huete Jimenez_debug_search = 1 300*6eef5f0cSAntonio Huete Jimenez.else 301*6eef5f0cSAntonio Huete Jimenez_debug_search = 0 302*6eef5f0cSAntonio Huete Jimenez.endif 303*6eef5f0cSAntonio Huete Jimenez 304f445c897SJohn Marino# First off, we want to know what ${MACHINE} to build for. 305f445c897SJohn Marino# This can be complicated if we are using a mixture of ${MACHINE} specific 306f445c897SJohn Marino# and non-specific Makefile.depend* 307f445c897SJohn Marino 3085f1e34d9SAlexandre Perrin# if we were included recursively _DEP_TARGET_SPEC should be valid. 3095f1e34d9SAlexandre Perrin.if empty(_DEP_TARGET_SPEC) 3105f1e34d9SAlexandre PerrinDEP_MACHINE = ${TARGET_MACHINE:U${MACHINE}} 3115f1e34d9SAlexandre Perrin_DEP_TARGET_SPEC := ${DEP_TARGET_SPEC} 312a34d5fb1SAntonio Huete Jimenez.if ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}*} != "" 3135f1e34d9SAlexandre Perrin# record that we've read dependfile for this 314f445c897SJohn Marino_dirdeps_checked.${_CURDIR}.${TARGET_SPEC}: 3155f1e34d9SAlexandre Perrin.endif 3165f1e34d9SAlexandre Perrin.endif 3175f1e34d9SAlexandre Perrin 3185f1e34d9SAlexandre Perrin# by now _DEP_TARGET_SPEC should be set, parse it. 3195f1e34d9SAlexandre Perrin.if ${TARGET_SPEC_VARS:[#]} > 1 3205f1e34d9SAlexandre Perrin# we need to parse DEP_MACHINE may or may not contain more info 3215f1e34d9SAlexandre Perrin_tspec := ${_DEP_TARGET_SPEC:S/,/ /g} 3225f1e34d9SAlexandre Perrin.for i in ${_tspec_x} 3235f1e34d9SAlexandre PerrinDEP_${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} 3245f1e34d9SAlexandre Perrin.endfor 3255f1e34d9SAlexandre Perrin.for v in ${TARGET_SPEC_VARS:O:u} 3265f1e34d9SAlexandre Perrin.if empty(DEP_$v) 3275f1e34d9SAlexandre Perrin.undef DEP_$v 3285f1e34d9SAlexandre Perrin.endif 3295f1e34d9SAlexandre Perrin.endfor 3305f1e34d9SAlexandre Perrin.else 3315f1e34d9SAlexandre PerrinDEP_MACHINE := ${_DEP_TARGET_SPEC} 3325f1e34d9SAlexandre Perrin.endif 3335f1e34d9SAlexandre Perrin 334f445c897SJohn Marino# reset each time through 335f445c897SJohn Marino_build_all_dirs = 336a34d5fb1SAntonio Huete Jimenez_build_xtra_dirs = 3375f1e34d9SAlexandre Perrin 338ca58f742SDaniel Fojt# DIRDEPS_CACHE can be very handy for debugging. 339ca58f742SDaniel Fojt# Also if repeatedly building the same target, 340ca58f742SDaniel Fojt# we can avoid the overhead of re-computing the tree dependencies. 341ca58f742SDaniel FojtMK_DIRDEPS_CACHE ?= no 342ca58f742SDaniel FojtBUILD_DIRDEPS_CACHE ?= no 343ca58f742SDaniel FojtBUILD_DIRDEPS ?= yes 344ca58f742SDaniel Fojt 345ca58f742SDaniel Fojt.if ${MK_DIRDEPS_CACHE} == "yes" 346ca58f742SDaniel Fojt# this is where we will cache all our work 347a34d5fb1SAntonio Huete JimenezDIRDEPS_CACHE ?= ${_OBJDIR:tA}/dirdeps.cache${_TARGETS:U${.TARGETS}:Nall:O:u:ts-:S,/,_,g:S,^,.,:N.} 348ca58f742SDaniel Fojt.endif 349ca58f742SDaniel Fojt 350ca58f742SDaniel Fojt 351f445c897SJohn Marino# pickup customizations 352f445c897SJohn Marino# as below you can use !target(_DIRDEP_USE) to protect things 353f445c897SJohn Marino# which should only be done once. 354f445c897SJohn Marino.-include <local.dirdeps.mk> 355f445c897SJohn Marino 356f445c897SJohn Marino.if !target(_DIRDEP_USE) 3575f1e34d9SAlexandre Perrin# things we skip for host tools 3585f1e34d9SAlexandre PerrinSKIP_HOSTDIR ?= 3595f1e34d9SAlexandre Perrin 3606a91b982SJohn MarinoNSkipHostDir = ${SKIP_HOSTDIR:N*.host*:S,$,.host*,:N.host*:S,^,${SRCTOP}/,:${M_ListToSkip}} 3615f1e34d9SAlexandre Perrin 3625f1e34d9SAlexandre Perrin# things we always skip 3635f1e34d9SAlexandre Perrin# SKIP_DIRDEPS allows for adding entries on command line. 3645f1e34d9SAlexandre PerrinSKIP_DIR += .host *.WAIT ${SKIP_DIRDEPS} 3655f1e34d9SAlexandre PerrinSKIP_DIR.host += ${SKIP_HOSTDIR} 3665f1e34d9SAlexandre Perrin 3675f1e34d9SAlexandre PerrinDEP_SKIP_DIR = ${SKIP_DIR} \ 3685f1e34d9SAlexandre Perrin ${SKIP_DIR.${DEP_TARGET_SPEC}:U} \ 369ca58f742SDaniel Fojt ${TARGET_SPEC_VARS:@v@${SKIP_DIR.${DEP_$v}:U}@} \ 370ca58f742SDaniel Fojt ${SKIP_DIRDEPS.${DEP_TARGET_SPEC}:U} \ 371ca58f742SDaniel Fojt ${TARGET_SPEC_VARS:@v@${SKIP_DIRDEPS.${DEP_$v}:U}@} 372ca58f742SDaniel Fojt 3735f1e34d9SAlexandre Perrin 3745f1e34d9SAlexandre PerrinNSkipDir = ${DEP_SKIP_DIR:${M_ListToSkip}} 3755f1e34d9SAlexandre Perrin 376f445c897SJohn Marino.if defined(NODIRDEPS) || defined(WITHOUT_DIRDEPS) 377f445c897SJohn MarinoNO_DIRDEPS = 378f445c897SJohn Marino.elif defined(WITHOUT_DIRDEPS_BELOW) 379f445c897SJohn MarinoNO_DIRDEPS_BELOW = 380f445c897SJohn Marino.endif 381f445c897SJohn Marino 382f445c897SJohn Marino.if defined(NO_DIRDEPS) 383f445c897SJohn Marino# confine ourselves to the original dir and below. 3845f1e34d9SAlexandre PerrinDIRDEPS_FILTER += M${_DEP_RELDIR}* 385f445c897SJohn Marino.elif defined(NO_DIRDEPS_BELOW) 386f445c897SJohn MarinoDIRDEPS_FILTER += M${_DEP_RELDIR} 3875f1e34d9SAlexandre Perrin.endif 3885f1e34d9SAlexandre Perrin 3896a91b982SJohn Marino# this is what we run below 3906a91b982SJohn MarinoDIRDEP_MAKE ?= ${.MAKE} 391ca58f742SDaniel FojtDIRDEP_DIR ?= ${.TARGET:R} 3926a91b982SJohn Marino 393a34d5fb1SAntonio Huete Jimenez# if you want us to report load averages during build 394a34d5fb1SAntonio Huete Jimenez# DIRDEP_USE_PRELUDE += ${DIRDEP_LOADAVG_REPORT}; 395a34d5fb1SAntonio Huete Jimenez 396a34d5fb1SAntonio Huete JimenezDIRDEP_LOADAVG_CMD ?= ${UPTIME:Uuptime} | sed 's,.*\(load\),\1,' 397a34d5fb1SAntonio Huete JimenezDIRDEP_LOADAVG_LAST = 0 398a34d5fb1SAntonio Huete Jimenez# yes the expression here is a bit complicated, 399a34d5fb1SAntonio Huete Jimenez# the trick is to only eval ${DIRDEP_LOADAVG_LAST::=${now_utc}} 400a34d5fb1SAntonio Huete Jimenez# when we want to report. 401a34d5fb1SAntonio Huete Jimenez# Note: expr(1) will exit 1 if the expression evaluates to 0 402a34d5fb1SAntonio Huete Jimenez# hence the || true 403a34d5fb1SAntonio Huete JimenezDIRDEP_LOADAVG_REPORT = \ 404*6eef5f0cSAntonio Huete Jimenez test -z "${"${expr ${now_utc} - ${DIRDEP_LOADAVG_INTERVAL:U60} - ${DIRDEP_LOADAVG_LAST} || true:L:sh:N-*}":?yes${DIRDEP_LOADAVG_LAST::=${now_utc}}:}" || \ 405a34d5fb1SAntonio Huete Jimenez echo "${TRACER}`${DIRDEP_LOADAVG_CMD}`" 406a34d5fb1SAntonio Huete Jimenez 4076a91b982SJohn Marino# we suppress SUBDIR when visiting the leaves 4085f1e34d9SAlexandre Perrin# we assume sys.mk will set MACHINE_ARCH 4095f1e34d9SAlexandre Perrin# you can add extras to DIRDEP_USE_ENV 4105f1e34d9SAlexandre Perrin# if there is no makefile in the target directory, we skip it. 4115f1e34d9SAlexandre Perrin_DIRDEP_USE: .USE .MAKE 4125f1e34d9SAlexandre Perrin @for m in ${.MAKE.MAKEFILE_PREFERENCE}; do \ 4135f1e34d9SAlexandre Perrin test -s ${.TARGET:R}/$$m || continue; \ 414*6eef5f0cSAntonio Huete Jimenez echo "${TRACER}Checking ${.TARGET:S,^${SRCTOP}/,,} for ${.TARGET:E} ..."; \ 415ca58f742SDaniel Fojt ${DIRDEP_USE_PRELUDE} \ 4165f1e34d9SAlexandre Perrin MACHINE_ARCH= NO_SUBDIR=1 ${DIRDEP_USE_ENV} \ 4175f1e34d9SAlexandre Perrin TARGET_SPEC=${.TARGET:E} \ 4185f1e34d9SAlexandre Perrin MACHINE=${.TARGET:E} \ 419ca58f742SDaniel Fojt ${DIRDEP_MAKE} -C ${DIRDEP_DIR} || exit 1; \ 4205f1e34d9SAlexandre Perrin break; \ 4215f1e34d9SAlexandre Perrin done 4225f1e34d9SAlexandre Perrin 4235f1e34d9SAlexandre Perrin.ifdef ALL_MACHINES 424ca58f742SDaniel Fojt.if empty(ONLY_TARGET_SPEC_LIST) && empty(ONLY_MACHINE_LIST) 425*6eef5f0cSAntonio Huete Jimenez# we start with everything 426*6eef5f0cSAntonio Huete Jimenez_machine_list != echo; 'ls' -1 ${_CURDIR}/${.MAKE.DEPENDFILE_PREFIX}* 2> /dev/null 427*6eef5f0cSAntonio Huete Jimenez 428*6eef5f0cSAntonio Huete Jimenez# some things we know we want to ignore 429*6eef5f0cSAntonio Huete JimenezDIRDEPS_TARGETS_SKIP_LIST += \ 430*6eef5f0cSAntonio Huete Jimenez *~ \ 431*6eef5f0cSAntonio Huete Jimenez *.bak \ 432*6eef5f0cSAntonio Huete Jimenez *.inc \ 433*6eef5f0cSAntonio Huete Jimenez *.old \ 434*6eef5f0cSAntonio Huete Jimenez *.options \ 435*6eef5f0cSAntonio Huete Jimenez *.orig \ 436*6eef5f0cSAntonio Huete Jimenez *.rej \ 437*6eef5f0cSAntonio Huete Jimenez 438*6eef5f0cSAntonio Huete Jimenez# first trim things we know we want to skip 439*6eef5f0cSAntonio Huete Jimenez# and provide canonical form 440*6eef5f0cSAntonio Huete Jimenez_machine_list := ${_machine_list:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}:T:E} 441*6eef5f0cSAntonio Huete Jimenez 442*6eef5f0cSAntonio Huete Jimenez# cater for local complexities 443*6eef5f0cSAntonio Huete Jimenez# local.dirdeps.mk can set 444*6eef5f0cSAntonio Huete Jimenez# DIRDEPS_ALL_MACHINES_FILTER and 445*6eef5f0cSAntonio Huete Jimenez# DIRDEPS_ALL_MACHINES_FILTER_XTRAS for final tweaks 446*6eef5f0cSAntonio Huete Jimenez 447*6eef5f0cSAntonio Huete Jimenez.if !empty(ALL_TARGET_SPEC_LIST) 448*6eef5f0cSAntonio Huete Jimenez.if ${_debug_reldir} 449*6eef5f0cSAntonio Huete Jimenez.info ALL_TARGET_SPEC_LIST=${ALL_TARGET_SPEC_LIST} 4505f1e34d9SAlexandre Perrin.endif 451*6eef5f0cSAntonio Huete JimenezDIRDEPS_ALL_MACHINES_FILTER += \ 452*6eef5f0cSAntonio Huete Jimenez @x@$${ALL_TARGET_SPEC_LIST:@s@$${x:M$$s}@}@ 453*6eef5f0cSAntonio Huete Jimenez.elif !empty(ALL_MACHINE_LIST) 454*6eef5f0cSAntonio Huete Jimenez.if ${_debug_reldir} 455*6eef5f0cSAntonio Huete Jimenez.info ALL_MACHINE_LIST=${ALL_MACHINE_LIST} 456*6eef5f0cSAntonio Huete Jimenez.endif 457*6eef5f0cSAntonio Huete Jimenez.if ${TARGET_SPEC_VARS:[#]} > 1 458*6eef5f0cSAntonio Huete Jimenez# the space below can result in extraneous ':' 459*6eef5f0cSAntonio Huete JimenezDIRDEPS_ALL_MACHINES_FILTER += \ 460*6eef5f0cSAntonio Huete Jimenez @x@$${ALL_MACHINE_LIST:@m@$${x:M$$m,*} $${x:M$$m}@}@ 461*6eef5f0cSAntonio Huete Jimenez.else 462*6eef5f0cSAntonio Huete JimenezDIRDEPS_ALL_MACHINES_FILTER += \ 463*6eef5f0cSAntonio Huete Jimenez @x@$${ALL_MACHINE_LIST:@m@$${x:M$$m}@}@ 464*6eef5f0cSAntonio Huete Jimenez.endif 465*6eef5f0cSAntonio Huete Jimenez.endif 466*6eef5f0cSAntonio Huete Jimenez# add local XTRAS - default to something benign 467*6eef5f0cSAntonio Huete JimenezDIRDEPS_ALL_MACHINES_FILTER += \ 468*6eef5f0cSAntonio Huete Jimenez ${DIRDEPS_ALL_MACHINES_FILTER_XTRAS:UNbak} 469*6eef5f0cSAntonio Huete Jimenez 470*6eef5f0cSAntonio Huete Jimenez.if ${_debug_reldir} 471*6eef5f0cSAntonio Huete Jimenez.info _machine_list=${_machine_list} 472*6eef5f0cSAntonio Huete Jimenez.info DIRDEPS_ALL_MACHINES_FILTER=${DIRDEPS_ALL_MACHINES_FILTER} 473*6eef5f0cSAntonio Huete Jimenez.endif 474*6eef5f0cSAntonio Huete Jimenez 475*6eef5f0cSAntonio Huete Jimenez_only_machines := ${_machine_list:${DIRDEPS_ALL_MACHINES_FILTER:ts:}:S,:, ,g} 4765f1e34d9SAlexandre Perrin.else 477ca58f742SDaniel Fojt_only_machines := ${ONLY_TARGET_SPEC_LIST:U} ${ONLY_MACHINE_LIST:U} 4785f1e34d9SAlexandre Perrin.endif 4795f1e34d9SAlexandre Perrin 4805f1e34d9SAlexandre Perrin.if empty(_only_machines) 4815f1e34d9SAlexandre Perrin# we must be boot-strapping 482*6eef5f0cSAntonio Huete Jimenez_only_machines := ${TARGET_MACHINE:U${ALL_TARGET_SPEC_LIST:U${ALL_MACHINE_LIST:U${DEP_MACHINE}}}} 483*6eef5f0cSAntonio Huete Jimenez.endif 484*6eef5f0cSAntonio Huete Jimenez 485*6eef5f0cSAntonio Huete Jimenez# cleanup the result 486*6eef5f0cSAntonio Huete Jimenez_only_machines := ${_only_machines:O:u} 487*6eef5f0cSAntonio Huete Jimenez 488*6eef5f0cSAntonio Huete Jimenez.if ${_debug_reldir} 489*6eef5f0cSAntonio Huete Jimenez.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: ALL_MACHINES _only_machines=${_only_machines} 4905f1e34d9SAlexandre Perrin.endif 4915f1e34d9SAlexandre Perrin 4925f1e34d9SAlexandre Perrin.else # ! ALL_MACHINES 493ca58f742SDaniel Fojt# if ONLY_TARGET_SPEC_LIST or ONLY_MACHINE_LIST is set, we are limited to that. 494ca58f742SDaniel Fojt# Note that ONLY_TARGET_SPEC_LIST should be fully qualified. 4955f1e34d9SAlexandre Perrin# if TARGET_MACHINE is set - it is really the same as ONLY_MACHINE_LIST 4965f1e34d9SAlexandre Perrin# otherwise DEP_MACHINE is it - so DEP_MACHINE will match. 497ca58f742SDaniel Fojt_only_machines := ${ONLY_TARGET_SPEC_LIST:U:M${DEP_MACHINE},*} 498ca58f742SDaniel Fojt.if empty(_only_machines) 4995f1e34d9SAlexandre Perrin_only_machines := ${ONLY_MACHINE_LIST:U${TARGET_MACHINE:U${DEP_MACHINE}}:M${DEP_MACHINE}} 5005f1e34d9SAlexandre Perrin.endif 501ca58f742SDaniel Fojt.endif 5025f1e34d9SAlexandre Perrin 5035f1e34d9SAlexandre Perrin.if !empty(NOT_MACHINE_LIST) 5045f1e34d9SAlexandre Perrin_only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}} 5055f1e34d9SAlexandre Perrin.endif 506ca58f742SDaniel Fojt.if !empty(NOT_TARGET_SPEC_LIST) 507ca58f742SDaniel Fojt# we must first qualify 508ca58f742SDaniel Fojt_dm := ${DEP_MACHINE} 509ca58f742SDaniel Fojt_only_machines := ${_only_machines:M*,*} ${_only_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,} 510ca58f742SDaniel FojtDEP_MACHINE := ${_dm} 511ca58f742SDaniel Fojt_only_machines := ${_only_machines:${NOT_TARGET_SPEC_LIST:${M_ListToSkip}}} 512ca58f742SDaniel Fojt.endif 513ca58f742SDaniel Fojt# clean up 514ca58f742SDaniel Fojt_only_machines := ${_only_machines:O:u} 5155f1e34d9SAlexandre Perrin 516*6eef5f0cSAntonio Huete Jimenez.if ${_debug_reldir} 517*6eef5f0cSAntonio Huete Jimenez.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _only_machines=${_only_machines} 518*6eef5f0cSAntonio Huete Jimenez.endif 519*6eef5f0cSAntonio Huete Jimenez 5205f1e34d9SAlexandre Perrin# make sure we have a starting place? 5215f1e34d9SAlexandre PerrinDIRDEPS ?= ${RELDIR} 5225f1e34d9SAlexandre Perrin.endif # target 5235f1e34d9SAlexandre Perrin 524f445c897SJohn Marino.if !defined(NO_DIRDEPS) && !defined(NO_DIRDEPS_BELOW) 525f445c897SJohn Marino.if ${MK_DIRDEPS_CACHE} == "yes" 526f445c897SJohn Marino 527f445c897SJohn Marino# just ensure this exists 528f445c897SJohn Marinobuild-dirdeps: 529f445c897SJohn Marino 530f445c897SJohn MarinoM_oneperline = @x@\\${.newline} $$x@ 531f445c897SJohn Marino 532f445c897SJohn Marino.if ${BUILD_DIRDEPS_CACHE} == "no" 533f445c897SJohn Marino.if !target(dirdeps-cached) 534f445c897SJohn Marino# we do this via sub-make 535f445c897SJohn MarinoBUILD_DIRDEPS = no 536f445c897SJohn Marino 537f445c897SJohn Marino# ignore anything but these 538f445c897SJohn Marino.MAKE.META.IGNORE_FILTER = M*/${.MAKE.DEPENDFILE_PREFIX}* 539f445c897SJohn Marino 540f445c897SJohn Marinodirdeps: dirdeps-cached 541f445c897SJohn Marinodirdeps-cached: ${DIRDEPS_CACHE} .MAKE 542f445c897SJohn Marino @echo "${TRACER}Using ${DIRDEPS_CACHE}" 543*6eef5f0cSAntonio Huete Jimenez @MAKELEVEL=${.MAKE.LEVEL} \ 544*6eef5f0cSAntonio Huete Jimenez TARGET_SPEC=${TARGET_SPEC} \ 545*6eef5f0cSAntonio Huete Jimenez ${TARGET_SPEC_VARS:@v@$v=${$v}@} \ 546*6eef5f0cSAntonio Huete Jimenez ${.MAKE} -C ${_CURDIR} -f ${DIRDEPS_CACHE} \ 547f445c897SJohn Marino dirdeps MK_DIRDEPS_CACHE=no BUILD_DIRDEPS=no 548f445c897SJohn Marino 549a34d5fb1SAntonio Huete Jimenez# leaf makefiles rarely work for building DIRDEPS_CACHE 550a34d5fb1SAntonio Huete Jimenez.if ${RELDIR} != "." 551a34d5fb1SAntonio Huete JimenezBUILD_DIRDEPS_MAKEFILE ?= -f dirdeps.mk 552a34d5fb1SAntonio Huete Jimenez.endif 553a34d5fb1SAntonio Huete Jimenez 554f445c897SJohn Marino# these should generally do 555a34d5fb1SAntonio Huete JimenezBUILD_DIRDEPS_MAKEFILE ?= 556f445c897SJohn MarinoBUILD_DIRDEPS_TARGETS ?= ${.TARGETS} 557f445c897SJohn Marino 558a34d5fb1SAntonio Huete Jimenez.if ${DIRDEPS_CACHE} != ${STATIC_DIRDEPS_CACHE:Uno} && ${DIRDEPS_CACHE:M${SRCTOP}/*} == "" 559a34d5fb1SAntonio Huete Jimenez# export this for dirdeps-cache-update.mk 560a34d5fb1SAntonio Huete JimenezDYNAMIC_DIRDEPS_CACHE := ${DIRDEPS_CACHE} 561a34d5fb1SAntonio Huete Jimenez.export DYNAMIC_DIRDEPS_CACHE 562f445c897SJohn Marino# we need the .meta file to ensure we update if 563f445c897SJohn Marino# any of the Makefile.depend* changed. 564f445c897SJohn Marino# We do not want to compare the command line though. 565f445c897SJohn Marino${DIRDEPS_CACHE}: .META .NOMETA_CMP 566f445c897SJohn Marino +@{ echo '# Autogenerated - do NOT edit!'; echo; \ 567f445c897SJohn Marino echo 'BUILD_DIRDEPS=no'; echo; \ 568ca58f742SDaniel Fojt echo '.include <dirdeps.mk>'; echo; \ 569f445c897SJohn Marino } > ${.TARGET}.new 570f445c897SJohn Marino +@MAKELEVEL=${.MAKE.LEVEL} DIRDEPS_CACHE=${DIRDEPS_CACHE} \ 571f445c897SJohn Marino DIRDEPS="${DIRDEPS}" \ 572ca58f742SDaniel Fojt TARGET_SPEC=${TARGET_SPEC} \ 573a34d5fb1SAntonio Huete Jimenez MAKEFLAGS= ${DIRDEP_CACHE_MAKE:U${.MAKE}} -C ${_CURDIR} \ 574a34d5fb1SAntonio Huete Jimenez ${BUILD_DIRDEPS_MAKEFILE} \ 575f445c897SJohn Marino ${BUILD_DIRDEPS_TARGETS} BUILD_DIRDEPS_CACHE=yes \ 576f445c897SJohn Marino .MAKE.DEPENDFILE=.none \ 577a34d5fb1SAntonio Huete Jimenez ${"${DEBUG_DIRDEPS:Nno}":?DEBUG_DIRDEPS='${DEBUG_DIRDEPS}':} \ 578f445c897SJohn Marino ${.MAKEFLAGS:tW:S,-D ,-D,g:tw:M*WITH*} \ 579ca58f742SDaniel Fojt ${.MAKEFLAGS:tW:S,-d ,-d,g:tw:M-d*} \ 580*6eef5f0cSAntonio Huete Jimenez 3>&1 1>&2 | sed 's,${SRCTOP},_{SRCTOP},g;s,_{,$${,g' >> ${.TARGET}.new && \ 581f445c897SJohn Marino mv ${.TARGET}.new ${.TARGET} 582f445c897SJohn Marino 583f445c897SJohn Marino.endif 584a34d5fb1SAntonio Huete Jimenez.endif 585f445c897SJohn Marino.elif !target(_count_dirdeps) 586f445c897SJohn Marino# we want to capture the dirdeps count in the cache 587f445c897SJohn Marino.END: _count_dirdeps 588f445c897SJohn Marino_count_dirdeps: .NOMETA 589a34d5fb1SAntonio Huete Jimenez @{ echo; echo '.info $${.newline}$${TRACER}Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${DIRDEP_INFO_XTRAS}'; } >&3 590f445c897SJohn Marino 591f445c897SJohn Marino.endif 592f445c897SJohn Marino.elif !make(dirdeps) && !target(_count_dirdeps) 593f445c897SJohn Marinobeforedirdeps: _count_dirdeps 594f445c897SJohn Marino_count_dirdeps: .NOMETA 595a34d5fb1SAntonio Huete Jimenez @echo "${TRACER}Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${DIRDEP_INFO_XTRAS} seconds=`expr ${now_utc} - ${start_utc}`" 596f445c897SJohn Marino 597f445c897SJohn Marino.endif 598f445c897SJohn Marino.endif 599f445c897SJohn Marino 600f445c897SJohn Marino.if ${BUILD_DIRDEPS} == "yes" 6015f1e34d9SAlexandre Perrin 6025f1e34d9SAlexandre Perrin# the rest is done repeatedly for every Makefile.depend we read. 6035f1e34d9SAlexandre Perrin# if we are anything but the original dir we care only about the 6045f1e34d9SAlexandre Perrin# machine type we were included for.. 6055f1e34d9SAlexandre Perrin 6065f1e34d9SAlexandre Perrin.if ${DEP_RELDIR} == "." 6075f1e34d9SAlexandre Perrin_this_dir := ${SRCTOP} 6085f1e34d9SAlexandre Perrin.else 6095f1e34d9SAlexandre Perrin_this_dir := ${SRCTOP}/${DEP_RELDIR} 6105f1e34d9SAlexandre Perrin.endif 6115f1e34d9SAlexandre Perrin 6125f1e34d9SAlexandre Perrin# on rare occasions, there can be a need for extra help 6135f1e34d9SAlexandre Perrin_dep_hack := ${_this_dir}/${.MAKE.DEPENDFILE_PREFIX}.inc 614f445c897SJohn Marino.-include <${_dep_hack}> 615ca58f742SDaniel Fojt.-include <${_dep_hack:R}.options> 6165f1e34d9SAlexandre Perrin 6175f1e34d9SAlexandre Perrin.if ${DEP_RELDIR} != ${_DEP_RELDIR} || ${DEP_TARGET_SPEC} != ${TARGET_SPEC} 6185f1e34d9SAlexandre Perrin# this should be all 6195f1e34d9SAlexandre Perrin_machines := ${DEP_MACHINE} 6205f1e34d9SAlexandre Perrin.else 6215f1e34d9SAlexandre Perrin# this is the machine list we actually use below 6225f1e34d9SAlexandre Perrin_machines := ${_only_machines} 6235f1e34d9SAlexandre Perrin 624ca58f742SDaniel Fojt.if defined(HOSTPROG) || ${DEP_MACHINE:Nhost*} == "" 6255f1e34d9SAlexandre Perrin# we need to build this guy's dependencies for host as well. 626ca58f742SDaniel Fojt.if ${DEP_MACHINE:Nhost*} == "" 627ca58f742SDaniel Fojt_machines += ${DEP_MACHINE} 628ca58f742SDaniel Fojt.else 6295f1e34d9SAlexandre Perrin_machines += host 6305f1e34d9SAlexandre Perrin.endif 631ca58f742SDaniel Fojt.endif 6325f1e34d9SAlexandre Perrin 6335f1e34d9SAlexandre Perrin_machines := ${_machines:O:u} 6345f1e34d9SAlexandre Perrin.endif 6355f1e34d9SAlexandre Perrin 6365f1e34d9SAlexandre Perrin.if ${TARGET_SPEC_VARS:[#]} > 1 6375f1e34d9SAlexandre Perrin# we need to tweak _machines 6385f1e34d9SAlexandre Perrin_dm := ${DEP_MACHINE} 6396a91b982SJohn Marino# apply the same filtering that we do when qualifying DIRDEPS. 6406a91b982SJohn Marino# M_dep_qual_fixes expects .${MACHINE}* so add (and remove) '.' 641ca58f742SDaniel Fojt# Again we expect that any already qualified machines are fully qualified. 642ca58f742SDaniel Fojt_machines := ${_machines:M*,*} ${_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,} 6435f1e34d9SAlexandre PerrinDEP_MACHINE := ${_dm} 644ca58f742SDaniel Fojt_machines := ${_machines:O:u} 6455f1e34d9SAlexandre Perrin.endif 6465f1e34d9SAlexandre Perrin 6475f1e34d9SAlexandre Perrin# reset each time through 6485f1e34d9SAlexandre Perrin_build_dirs = 6495f1e34d9SAlexandre Perrin 6505f1e34d9SAlexandre Perrin.if ${DEP_RELDIR} == ${_DEP_RELDIR} 6515f1e34d9SAlexandre Perrin# pickup other machines for this dir if necessary 6525f1e34d9SAlexandre Perrin_build_dirs += ${_machines:@m@${_CURDIR}.$m@} 6535f1e34d9SAlexandre Perrin.endif 6545f1e34d9SAlexandre Perrin 6556a91b982SJohn Marino.if ${_debug_reldir} 656*6eef5f0cSAntonio Huete Jimenez.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: nDIRDEPS=${DIRDEPS:[#]} 6575f1e34d9SAlexandre Perrin.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS='${DIRDEPS}' 6585f1e34d9SAlexandre Perrin.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _machines='${_machines}' 6595f1e34d9SAlexandre Perrin.endif 6605f1e34d9SAlexandre Perrin 6615f1e34d9SAlexandre Perrin.if !empty(DIRDEPS) 6625f1e34d9SAlexandre Perrin# these we reset each time through as they can depend on DEP_MACHINE 6635f1e34d9SAlexandre PerrinDEP_DIRDEPS_FILTER = \ 6645f1e34d9SAlexandre Perrin ${DIRDEPS_FILTER.${DEP_TARGET_SPEC}:U} \ 665ca58f742SDaniel Fojt ${TARGET_SPEC_VARS:@v@${DIRDEPS_FILTER.${DEP_$v}:U}@} \ 6665f1e34d9SAlexandre Perrin ${DIRDEPS_FILTER:U} 6675f1e34d9SAlexandre Perrin.if empty(DEP_DIRDEPS_FILTER) 6685f1e34d9SAlexandre Perrin# something harmless 6695f1e34d9SAlexandre PerrinDEP_DIRDEPS_FILTER = U 6705f1e34d9SAlexandre Perrin.endif 6715f1e34d9SAlexandre Perrin 6725f1e34d9SAlexandre Perrin# this is what we start with 6736a91b982SJohn Marino__depdirs := ${DIRDEPS:${NSkipDir}:${DEP_DIRDEPS_FILTER:ts:}:C,//+,/,g:O:u:@d@${SRCTOP}/$d@} 6745f1e34d9SAlexandre Perrin 675*6eef5f0cSAntonio Huete Jimenez# some entries may be qualified with .<machine> or .<target_spec> 676*6eef5f0cSAntonio Huete Jimenez# we can tell the unqualified ones easily - because they exist 677*6eef5f0cSAntonio Huete Jimenez__unqual_depdirs := ${__depdirs:@d@${exists($d):?$d:}@} 678*6eef5f0cSAntonio Huete Jimenez__qual_depdirs := ${__depdirs:${__unqual_depdirs:Uno:${M_ListToSkip}}} 6795f1e34d9SAlexandre Perrin 6805f1e34d9SAlexandre Perrin.if ${DEP_RELDIR} == ${_DEP_RELDIR} 6815f1e34d9SAlexandre Perrin# if it was called out - we likely need it. 682ca58f742SDaniel Fojt__hostdpadd := ${DPADD:U.:M${HOST_OBJTOP}/*:S,${HOST_OBJTOP}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host,:N.*:@d@${SRCTOP}/$d@} \ 683ca58f742SDaniel Fojt ${DPADD:U.:M${HOST_OBJTOP32:Uno}/*:S,${HOST_OBJTOP32:Uno}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host32,:N.*:@d@${SRCTOP}/$d@} 6845f1e34d9SAlexandre Perrin__qual_depdirs += ${__hostdpadd} 6855f1e34d9SAlexandre Perrin.endif 6865f1e34d9SAlexandre Perrin 6876a91b982SJohn Marino.if ${_debug_reldir} 688a34d5fb1SAntonio Huete Jimenez.info DEP_DIRDEPS_FILTER=${DEP_DIRDEPS_FILTER:ts:} 689*6eef5f0cSAntonio Huete Jimenez.info depdirs=${__depdirs:S,^${SRCTOP}/,,} 690*6eef5f0cSAntonio Huete Jimenez.info qualified=${__qual_depdirs:S,^${SRCTOP}/,,} 691*6eef5f0cSAntonio Huete Jimenez.info unqualified=${__unqual_depdirs:S,^${SRCTOP}/,,} 6925f1e34d9SAlexandre Perrin.endif 6935f1e34d9SAlexandre Perrin 6945f1e34d9SAlexandre Perrin# _build_dirs is what we will feed to _DIRDEP_USE 6955f1e34d9SAlexandre Perrin_build_dirs += \ 6965f1e34d9SAlexandre Perrin ${__qual_depdirs:M*.host:${NSkipHostDir}:N.host} \ 6975f1e34d9SAlexandre Perrin ${__qual_depdirs:N*.host} \ 6986a91b982SJohn Marino ${_machines:Mhost*:@m@${__unqual_depdirs:@d@$d.$m@}@:${NSkipHostDir}:N.host} \ 6996a91b982SJohn Marino ${_machines:Nhost*:@m@${__unqual_depdirs:@d@$d.$m@}@} 7005f1e34d9SAlexandre Perrin 7015f1e34d9SAlexandre Perrin# qualify everything now 7025f1e34d9SAlexandre Perrin_build_dirs := ${_build_dirs:${M_dep_qual_fixes:ts:}:O:u} 7035f1e34d9SAlexandre Perrin 704ca58f742SDaniel Fojt.endif # empty DIRDEPS 705ca58f742SDaniel Fojt 706a34d5fb1SAntonio Huete Jimenez_build_all_dirs += ${_build_dirs} ${_build_xtra_dirs} 707f445c897SJohn Marino_build_all_dirs := ${_build_all_dirs:O:u} 708f445c897SJohn Marino 7095f1e34d9SAlexandre Perrin# Normally if doing make -V something, 7105f1e34d9SAlexandre Perrin# we do not want to waste time chasing DIRDEPS 7115f1e34d9SAlexandre Perrin# but if we want to count the number of Makefile.depend* read, we do. 712*6eef5f0cSAntonio Huete Jimenez.if ${.MAKEFLAGS:M-V${_V_READ_DIRDEPS:U}} == "" 713f445c897SJohn Marino.if !empty(_build_all_dirs) 714f445c897SJohn Marino.if ${BUILD_DIRDEPS_CACHE} == "yes" 715*6eef5f0cSAntonio Huete Jimenez# we use _cache_script to minimize the number of times we fork the shell 716*6eef5f0cSAntonio Huete Jimenez_cache_script = echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}'; 717ca58f742SDaniel Fojt# guard against _new_dirdeps being too big for a single command line 718*6eef5f0cSAntonio Huete Jimenez_new_dirdeps := ${_build_all_dirs:@x@${target($x):?:$x}@:S,^${SRCTOP}/,,} 719*6eef5f0cSAntonio Huete Jimenez_cache_xtra_deps := ${_build_xtra_dirs:S,^${SRCTOP}/,,} 720*6eef5f0cSAntonio Huete Jimenez.export _cache_xtra_deps _new_dirdeps 721*6eef5f0cSAntonio Huete Jimenez.if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS) 722ca58f742SDaniel Fojt# Discouraged, but there are always exceptions. 723ca58f742SDaniel Fojt# Handle it here rather than explain how. 724*6eef5f0cSAntonio Huete JimenezDIRDEPS_EXPORT_VARS ?= ${DEP_EXPORT_VARS} 725*6eef5f0cSAntonio Huete Jimenez_cache_xvars := echo; ${DIRDEPS_EXPORT_VARS:@v@echo '$v = ${$v}';@} echo '.export ${DIRDEPS_EXPORT_VARS}'; echo; 726*6eef5f0cSAntonio Huete Jimenez_cache_script += ${_cache_xvars} 727ec533708SSascha Wildner.endif 728f445c897SJohn Marino.else 7295f1e34d9SAlexandre Perrin# this makes it all happen 730f445c897SJohn Marinodirdeps: ${_build_all_dirs} 731f445c897SJohn Marino.endif 732f445c897SJohn Marino${_build_all_dirs}: _DIRDEP_USE 7335f1e34d9SAlexandre Perrin 7346a91b982SJohn Marino.if ${_debug_reldir} 735*6eef5f0cSAntonio Huete Jimenez.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs:S,^${SRCTOP}/,,} 7365f1e34d9SAlexandre Perrin.endif 7375f1e34d9SAlexandre Perrin 738*6eef5f0cSAntonio Huete Jimenez.if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS) 739*6eef5f0cSAntonio Huete Jimenez.export ${DIRDEPS_EXPORT_VARS} ${DEP_EXPORT_VARS} 740*6eef5f0cSAntonio Huete JimenezDIRDEPS_EXPORT_VARS = 741ca58f742SDaniel FojtDEP_EXPORT_VARS = 742ca58f742SDaniel Fojt.endif 743ca58f742SDaniel Fojt 7445f1e34d9SAlexandre Perrin# this builds the dependency graph 7455f1e34d9SAlexandre Perrin.for m in ${_machines} 746ca58f742SDaniel Fojt.if ${BUILD_DIRDEPS_CACHE} == "yes" && !empty(_build_dirs) 747a34d5fb1SAntonio Huete Jimenez_cache_deps = 748*6eef5f0cSAntonio Huete Jimenez_cache_script += echo; echo 'DIRDEPS.${_this_dir}.$m = \'; 749ca58f742SDaniel Fojt.endif 7505f1e34d9SAlexandre Perrin# it would be nice to do :N${.TARGET} 7515f1e34d9SAlexandre Perrin.if !empty(__qual_depdirs) 7525f1e34d9SAlexandre Perrin.for q in ${__qual_depdirs:${M_dep_qual_fixes:ts:}:E:O:u:N$m} 7536a91b982SJohn Marino.if ${_debug_reldir} || ${DEBUG_DIRDEPS:@x@${${DEP_RELDIR}.$m:L:M$x}${${DEP_RELDIR}.$q:L:M$x}@} != "" 754*6eef5f0cSAntonio Huete Jimenez.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$q:S,^${SRCTOP}/,,} 7555f1e34d9SAlexandre Perrin.endif 756f445c897SJohn Marino.if ${BUILD_DIRDEPS_CACHE} == "yes" 757*6eef5f0cSAntonio Huete Jimenez_cache_deps += ${_build_dirs:M*.$q:S,^${SRCTOP}/,,} 758f445c897SJohn Marino.else 7595f1e34d9SAlexandre Perrin${_this_dir}.$m: ${_build_dirs:M*.$q} 760f445c897SJohn Marino.endif 7615f1e34d9SAlexandre Perrin.endfor 7625f1e34d9SAlexandre Perrin.endif 7636a91b982SJohn Marino.if ${_debug_reldir} 764*6eef5f0cSAntonio Huete Jimenez.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,} 7655f1e34d9SAlexandre Perrin.endif 766f445c897SJohn Marino.if ${BUILD_DIRDEPS_CACHE} == "yes" 767a34d5fb1SAntonio Huete Jimenez.if !empty(_build_dirs) 768*6eef5f0cSAntonio Huete Jimenez_cache_deps += ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,} 769ca58f742SDaniel Fojt.if !empty(_cache_deps) 770ca58f742SDaniel Fojt.export _cache_deps 771*6eef5f0cSAntonio Huete Jimenez_cache_script += for x in $$_cache_deps; do echo " _{SRCTOP}/$$x \\"; done; 772ca58f742SDaniel Fojt.endif 773*6eef5f0cSAntonio Huete Jimenez# anything in _{build,env}_xtra_dirs is hooked to dirdeps: only 774*6eef5f0cSAntonio Huete Jimenezx!= echo; { echo; ${_cache_script} echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \ 775*6eef5f0cSAntonio Huete Jimenez echo; echo 'dirdeps: ${_this_dir}.$m \'; \ 776*6eef5f0cSAntonio Huete Jimenez for x in $$_cache_xtra_deps; do echo " _{SRCTOP}/$$x \\"; done; \ 777*6eef5f0cSAntonio Huete Jimenez echo; for x in $$_new_dirdeps; do echo "_{SRCTOP}/$$x: _DIRDEP_USE"; done; } >&3 778a34d5fb1SAntonio Huete Jimenez.endif 779f445c897SJohn Marino.else 7805f1e34d9SAlexandre Perrin${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m} 781f445c897SJohn Marino.endif 7825f1e34d9SAlexandre Perrin.endfor 7835f1e34d9SAlexandre Perrin 7845f1e34d9SAlexandre Perrin.endif 7855f1e34d9SAlexandre Perrin 7865f1e34d9SAlexandre Perrin# Now find more dependencies - and recurse. 787f445c897SJohn Marino.for d in ${_build_all_dirs} 788f445c897SJohn Marino.if !target(_dirdeps_checked.$d) 7895f1e34d9SAlexandre Perrin# once only 790f445c897SJohn Marino_dirdeps_checked.$d: 7916a91b982SJohn Marino.if ${_debug_search} 792*6eef5f0cSAntonio Huete Jimenez.info checking ${d:S,^${SRCTOP}/,,} 7936a91b982SJohn Marino.endif 794f445c897SJohn Marino# Note: _build_all_dirs is fully qualifed so d:R is always the directory 7955f1e34d9SAlexandre Perrin.if exists(${d:R}) 796ca58f742SDaniel Fojt# we pass _DEP_TARGET_SPEC to tell the next step what we want 797ca58f742SDaniel Fojt_DEP_TARGET_SPEC := ${d:E} 798ca58f742SDaniel Fojt# some makefiles may still look at this 799ca58f742SDaniel Fojt_DEP_MACHINE := ${d:E:C/,.*//} 800ca58f742SDaniel Fojt# set these too in case Makefile.depend* uses them 801ca58f742SDaniel Fojt.if ${TARGET_SPEC_VARS:[#]} > 1 802ca58f742SDaniel Fojt_dtspec := ${_DEP_TARGET_SPEC:S/,/ /g} 803ca58f742SDaniel Fojt.for i in ${_tspec_x} 804ca58f742SDaniel FojtDEP_${TARGET_SPEC_VARS:[$i]} := ${_dtspec:[$i]} 805ca58f742SDaniel Fojt.endfor 806ca58f742SDaniel Fojt.else 807ca58f742SDaniel FojtDEP_MACHINE := ${_DEP_MACHINE} 808ca58f742SDaniel Fojt.endif 8095f1e34d9SAlexandre Perrin# Warning: there is an assumption here that MACHINE is always 8105f1e34d9SAlexandre Perrin# the first entry in TARGET_SPEC_VARS. 8115f1e34d9SAlexandre Perrin# If TARGET_SPEC and MACHINE are insufficient, you have a problem. 812*6eef5f0cSAntonio Huete Jimenez_m := ${.MAKE.DEPENDFILE_PREFERENCE:T:S;${TARGET_SPEC}$;${d:E};:C;${MACHINE}((,.+)?)$;${d:E:C/,.*//}\1;:@m@${exists(${d:R}/$m):?${d:R}/$m:}@:[1]} 8135f1e34d9SAlexandre Perrin.if !empty(_m) 8146a91b982SJohn Marino# M_dep_qual_fixes isn't geared to Makefile.depend 8156a91b982SJohn Marino_qm := ${_m:C;(\.depend)$;\1.${d:E};:${M_dep_qual_fixes:ts:}} 8166a91b982SJohn Marino.if ${_debug_search} 8175f1e34d9SAlexandre Perrin.info Looking for ${_qm} 8185f1e34d9SAlexandre Perrin.endif 819f445c897SJohn Marino# set this "just in case" 820f445c897SJohn Marino# we can skip :tA since we computed the path above 821*6eef5f0cSAntonio Huete JimenezDEP_RELDIR := ${_m:H:S,^${SRCTOP}/,,} 822f445c897SJohn Marino# and reset this 823f445c897SJohn MarinoDIRDEPS = 8246a91b982SJohn Marino.if ${_debug_reldir} && ${_qm} != ${_m} 8255f1e34d9SAlexandre Perrin.info loading ${_m} for ${d:E} 8265f1e34d9SAlexandre Perrin.endif 8275f1e34d9SAlexandre Perrin.include <${_m}> 828ca58f742SDaniel Fojt.else 829ca58f742SDaniel Fojt.-include <local.dirdeps-missing.mk> 8305f1e34d9SAlexandre Perrin.endif 8315f1e34d9SAlexandre Perrin.endif 8325f1e34d9SAlexandre Perrin.endif 8335f1e34d9SAlexandre Perrin.endfor 8345f1e34d9SAlexandre Perrin 8355f1e34d9SAlexandre Perrin.endif # -V 836f445c897SJohn Marino.endif # BUILD_DIRDEPS 8375f1e34d9SAlexandre Perrin 8385f1e34d9SAlexandre Perrin.elif ${.MAKE.LEVEL} > 42 8395f1e34d9SAlexandre Perrin.error You should have stopped recursing by now. 8405f1e34d9SAlexandre Perrin.else 841f445c897SJohn Marino# we are building something 842f445c897SJohn MarinoDEP_RELDIR := ${RELDIR} 843f445c897SJohn Marino_DEP_RELDIR := ${RELDIR} 844ca58f742SDaniel Fojt# Since we are/should be included by .MAKE.DEPENDFILE 845ca58f742SDaniel Fojt# This is a final opportunity to add/hook global rules. 846ca58f742SDaniel Fojt.-include <local.dirdeps-build.mk> 847ca58f742SDaniel Fojt 848a34d5fb1SAntonio Huete Jimenez# skip _reldir_{finish,failed} if not included from Makefile.depend* 849a34d5fb1SAntonio Huete Jimenez# or not in meta mode 850a34d5fb1SAntonio Huete Jimenez.if !defined(WITHOUT_META_STATS) && ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}*} != "" && ${.MAKE.MODE:Mmeta} != "" 851a34d5fb1SAntonio Huete Jimenez 852a34d5fb1SAntonio Huete Jimenezmeta_stats= meta=${empty(.MAKE.META.FILES):?0:${.MAKE.META.FILES:[#]}} \ 853a34d5fb1SAntonio Huete Jimenez created=${empty(.MAKE.META.CREATED):?0:${.MAKE.META.CREATED:[#]}} 854a34d5fb1SAntonio Huete Jimenez 855a34d5fb1SAntonio Huete Jimenez.if !target(_reldir_finish) 856a34d5fb1SAntonio Huete Jimenez.END: _reldir_finish 857a34d5fb1SAntonio Huete Jimenez_reldir_finish: .NOMETA 858a34d5fb1SAntonio Huete Jimenez @echo "${TRACER}Finished ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}" 859a34d5fb1SAntonio Huete Jimenez.endif 860a34d5fb1SAntonio Huete Jimenez 861a34d5fb1SAntonio Huete Jimenez.if !target(_reldir_failed) 862a34d5fb1SAntonio Huete Jimenez.ERROR: _reldir_failed 863a34d5fb1SAntonio Huete Jimenez_reldir_failed: .NOMETA 864a34d5fb1SAntonio Huete Jimenez @echo "${TRACER}Failed ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}" 865a34d5fb1SAntonio Huete Jimenez.endif 866a34d5fb1SAntonio Huete Jimenez 867a34d5fb1SAntonio Huete Jimenez.endif 868a34d5fb1SAntonio Huete Jimenez 8695f1e34d9SAlexandre Perrin# pickup local dependencies 870f445c897SJohn Marino.if ${MAKE_VERSION} < 20160220 8715f1e34d9SAlexandre Perrin.-include <.depend> 872f445c897SJohn Marino.else 873f445c897SJohn Marino.dinclude <.depend> 874f445c897SJohn Marino.endif 8755f1e34d9SAlexandre Perrin.endif 8765f1e34d9SAlexandre Perrin 8776a91b982SJohn Marino# bootstrapping new dependencies made easy? 878*6eef5f0cSAntonio Huete Jimenez.if !target(bootstrap-empty) 879f445c897SJohn Marino.if !target(bootstrap) && (make(bootstrap) || \ 880f445c897SJohn Marino make(bootstrap-this) || \ 881f445c897SJohn Marino make(bootstrap-recurse) || \ 882f445c897SJohn Marino make(bootstrap-empty)) 8836a91b982SJohn Marino 884f445c897SJohn Marino# if we are bootstrapping create the default 885f445c897SJohn Marino_want = ${.CURDIR}/${.MAKE.DEPENDFILE_DEFAULT:T} 886f445c897SJohn Marino 887f445c897SJohn Marino.if exists(${_want}) 8886a91b982SJohn Marino# stop here 8896a91b982SJohn Marino${.TARGETS:Mboot*}: 890f445c897SJohn Marino.elif !make(bootstrap-empty) 8916a91b982SJohn Marino# find a Makefile.depend to use as _src 8926a91b982SJohn Marino_src != cd ${.CURDIR} && for m in ${.MAKE.DEPENDFILE_PREFERENCE:T:S,${MACHINE},*,}; do test -s $$m || continue; echo $$m; break; done; echo 8936a91b982SJohn Marino.if empty(_src) 894f445c897SJohn Marino.error cannot find any of ${.MAKE.DEPENDFILE_PREFERENCE:T}${.newline}Use: bootstrap-empty 8956a91b982SJohn Marino.endif 8966a91b982SJohn Marino 897f445c897SJohn Marino_src?= ${.MAKE.DEPENDFILE} 8986a91b982SJohn Marino 899ca58f742SDaniel Fojt.MAKE.DEPENDFILE_BOOTSTRAP_SED+= -e 's/${_src:E:C/,.*//}/${MACHINE}/g' 900f445c897SJohn Marino 901f445c897SJohn Marino# just create Makefile.depend* for this dir 9026a91b982SJohn Marinobootstrap-this: .NOTMAIN 903f445c897SJohn Marino @echo Bootstrapping ${RELDIR}/${_want:T} from ${_src:T}; \ 904f445c897SJohn Marino echo You need to build ${RELDIR} to correctly populate it. 905f445c897SJohn Marino.if ${_src:T} != ${.MAKE.DEPENDFILE_PREFIX:T} 906ca58f742SDaniel Fojt (cd ${.CURDIR} && sed ${.MAKE.DEPENDFILE_BOOTSTRAP_SED} ${_src} > ${_want:T}) 907f445c897SJohn Marino.else 908ca58f742SDaniel Fojt cp ${.CURDIR}/${_src:T} ${_want} 909f445c897SJohn Marino.endif 9106a91b982SJohn Marino 911f445c897SJohn Marino# create Makefile.depend* for this dir and its dependencies 9126a91b982SJohn Marinobootstrap: bootstrap-recurse 9136a91b982SJohn Marinobootstrap-recurse: bootstrap-this 9146a91b982SJohn Marino 9156a91b982SJohn Marino_mf := ${.PARSEFILE} 9166a91b982SJohn Marinobootstrap-recurse: .NOTMAIN .MAKE 9176a91b982SJohn Marino @cd ${SRCTOP} && \ 9186a91b982SJohn Marino for d in `cd ${RELDIR} && ${.MAKE} -B -f ${"${.MAKEFLAGS:M-n}":?${_src}:${.MAKE.DEPENDFILE:T}} -V DIRDEPS`; do \ 9196a91b982SJohn Marino test -d $$d || d=$${d%.*}; \ 9206a91b982SJohn Marino test -d $$d || continue; \ 9216a91b982SJohn Marino echo "Checking $$d for bootstrap ..."; \ 9226a91b982SJohn Marino (cd $$d && ${.MAKE} -f ${_mf} bootstrap-recurse); \ 9236a91b982SJohn Marino done 9246a91b982SJohn Marino 9256a91b982SJohn Marino.endif 926f445c897SJohn Marino 927f445c897SJohn Marino# create an empty Makefile.depend* to get the ball rolling. 928f445c897SJohn Marinobootstrap-empty: .NOTMAIN .NOMETA 929f445c897SJohn Marino @echo Creating empty ${RELDIR}/${_want:T}; \ 930f445c897SJohn Marino echo You need to build ${RELDIR} to correctly populate it. 931f445c897SJohn Marino @{ echo DIRDEPS=; echo ".include <dirdeps.mk>"; } > ${_want} 932f445c897SJohn Marino 9336a91b982SJohn Marino.endif 934*6eef5f0cSAntonio Huete Jimenez.endif 935