2 # $Id: dirdeps-targets.mk,v 1.22 2020/08/15 18:00:11 sjg Exp $
4 # @(#) Copyright (c) 2019-2020 Simon J. Gerraty
6 # This file is provided in the hope that it will
7 # be of use. There is absolutely NO WARRANTY.
8 # Permission to copy, redistribute or otherwise
9 # use this file is hereby granted provided that
10 # the above copyright notice and this notice are
13 # Please send copies of changes and bug-fixes to:
18 # This makefile is used to set initial DIRDEPS for top-level build
21 # The basic idea is that we have a list of directories in
22 # DIRDEPS_TARGETS_DIRS which are relative to SRCTOP.
23 # When asked to make 'foo' we look for any directory named 'foo'
24 # under DIRDEPS_TARGETS_DIRS.
25 # We then search those dirs for any Makefile.depend*
26 # Finally we select any that match conditions like REQUESTED_MACHINE
27 # or TARGET_SPEC and initialize DIRDEPS accordingly.
29 # We will check each of the initial DIRDEPS for Makefile.dirdeps.options
30 # and include any found.
31 # This makes it feasible to tweak options like MK_DIRDEPS_CACHE
32 # for a specific target.
34 # If MK_STATIC_DIRDEPS_CACHE is defined we will check if the
35 # initial DIRDEPS has a static cache (Makefile.dirdeps.cache).
36 # This only makes sense for seriously expensive targets.
39 .if ${.MAKE.LEVEL} == 0
40 # pickup customizations
41 .-include <local.dirdeps-targets.mk>
43 # for DIRDEPS_BUILD this is how we prime the pump
44 DIRDEPS_TARGETS_DIRS ?= targets targets/pseudo
45 # these prefixes can modify how we behave
46 # they need to be stripped when looking for target dirs
47 DIRDEPS_TARGETS_PREFIX_LIST ?= pkg- build-
49 # some .TARGETS need filtering
50 DIRDEPS_TARGETS_FILTER += Nall
52 # matching target dirs if any
53 tdirs := ${.TARGETS:${DIRDEPS_TARGETS_FILTER:ts:}:${DIRDEPS_TARGETS_PREFIX_LIST:@p@S,^$p,,@:ts:}:@t@${DIRDEPS_TARGETS_DIRS:@d@$d/$t@}@:@d@${exists(${SRCTOP}/$d):?$d:}@}
55 .if !empty(DEBUG_DIRDEPS_TARGETS)
60 # some things we know we want to ignore
61 DIRDEPS_TARGETS_SKIP_LIST += \
70 # the list of MACHINEs we consider
71 DIRDEPS_TARGETS_MACHINE_LIST += \
72 ${ALL_MACHINE_LIST:U} \
73 ${PSEUDO_MACHINE_LIST:Ucommon host host32} \
74 ${TARGET_MACHINE_LIST}
76 DIRDEPS_TARGETS_MACHINE_LIST := ${DIRDEPS_TARGETS_MACHINE_LIST:O:u}
78 # raw Makefile.depend* list
79 tdeps != 'cd' ${SRCTOP} && 'ls' -1 ${tdirs:O:u:@d@$d/${.MAKE.DEPENDFILE_PREFIX}*@} 2> /dev/null; echo
80 .if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != ""
83 # remove things we know we don't want
84 tdeps := ${tdeps:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}}
85 .if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != ""
89 # plain entries (no qualifiers) these apply to any TARGET_SPEC
90 ptdeps := ${tdeps:M*${.MAKE.DEPENDFILE_PREFIX}:S,/${.MAKE.DEPENDFILE_PREFIX},,}
92 # MACHINE qualified entries
93 mqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
96 .if ${TARGET_SPEC_VARS:[#]} > 1
97 # TARGET_SPEC qualified entries
98 .if !empty(TARGET_SPEC_LIST)
99 # we have a list of valid TARGET_SPECS; use it
100 tqtdeps := ${TARGET_SPEC_LIST:U:O:u:@t@${tdeps:M*.$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
102 # do we have a list of valid tuple members for at least
103 # the last tupple element? if so match on that
104 TARGET_SPEC_LAST_LIST ?= ${${TARGET_SPEC_VARS:[-1]}_LIST}
105 .if !empty(TARGET_SPEC_LAST_LIST)
106 tqtdeps := ${TARGET_SPEC_LAST_LIST:U:O:u:@t@${tdeps:M*,$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
108 # this is sub-optimal match MACHINE,
109 tqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m,*}@:S,/${.MAKE.DEPENDFILE_PREFIX},,}
114 # now work out what we want in DIRDEPS
115 .if empty(REQUESTED_MACHINE)
116 # we want them all just as found
117 DIRDEPS = ${ptdeps} ${mqtdeps} ${tqtdeps}
119 # we only want those that match REQUESTED_MACHINE/REQUESTED_TARGET_SPEC
120 # or REQUESTED_TARGET_SPEC (TARGET_SPEC)
122 ${ptdeps:@d@$d.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC:U${REQUESTED_MACHINE}}}@} \
123 ${mqtdeps:M*.${REQUESTED_MACHINE}} \
124 ${tqtdeps:M*.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC}}}
127 DIRDEPS := ${DIRDEPS:O:u}
129 .if !empty(DEBUG_DIRDEPS_TARGETS)
130 .for x in tdeps ptdeps mqtdeps tqtdeps DIRDEPS
135 # if we got DIRDEPS get to work
137 DIRDEPS.dirs := ${DIRDEPS:S,^,${SRCTOP}/,:@d@${exists($d):?$d:${d:R}}@}
138 # some targets what to tweak options we might want to process now
139 .for m in ${DIRDEPS.dirs:S,$,/Makefile.dirdeps.options,}
142 .if defined(MK_STATIC_DIRDEPS_CACHE)
143 # some targets are very expensive to compute dirdeps for
144 # so we may have a static cache
145 .for c in ${DIRDEPS.dirs:S,$,/Makefile.dirdeps.cache,}
147 STATIC_DIRDEPS_CACHE ?= $c
148 .if ${MK_STATIC_DIRDEPS_CACHE} == "yes"
150 MK_DIRDEPS_CACHE = yes
154 .if defined(STATIC_DIRDEPS_CACHE)
155 .export STATIC_DIRDEPS_CACHE
159 # allow a top-level makefile to do other stuff
160 # before including dirdeps.mk
161 .if ${MK_DIRDEPS_TARGETS_INCLUDE_DIRDEPS:Uyes} == "yes"
162 .include <dirdeps.mk>
165 DIRDEPS_TARGETS_SKIP += all clean* destroy*
167 .for t in ${.TARGETS:${DIRDEPS_TARGETS_SKIP:${M_ListToSkip}}}