2 # $Id: gendirdeps.mk,v 1.30 2016/02/27 00:20:39 sjg Exp $
4 # Copyright (c) 2010-2013, Juniper Networks, Inc.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # This makefile [re]generates ${.MAKE.DEPENDFILE}
32 .include <install-new.mk>
35 # RELDIR is the relative path from ${SRCTOP} to ${_CURDIR}
36 # (SRCTOP is ${SB}/src)
37 # _CURDIR is the absolute version of ${.CURDIR}
38 # _OBJDIR is the absolute version of ${.OBJDIR}
39 # _objroot is realpath of ${_OBJTOP} without ${MACHINE}
40 # this may be different from _OBJROOT if $SB/obj is a
41 # symlink to another filesystem.
42 # _objroot must be a prefix match for _objtop
54 _OBJROOT ?= ${OBJROOT:U${_OBJTOP}}
60 _objroot ?= ${_OBJROOT:tA}${_slash}
62 _this = ${.PARSEDIR}/${.PARSEFILE}
64 # remember what to make
65 _DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T}
67 # We do _not_ want to read our own output!
68 .MAKE.DEPENDFILE = /dev/null
70 # caller should have set this
71 META_FILES ?= ${.MAKE.META.FILES}
73 .if !empty(META_FILES)
75 .if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER)
76 # so we can compare below
77 .-include <${_DEPENDFILE}>
78 # yes, I mean :U with no value
79 _DIRDEPS := ${DIRDEPS:U:O:u}
82 META_FILES := ${META_FILES:T:O:u}
85 # pickup customizations
86 .-include <local.gendirdeps.mk>
88 # these are actually prefixes that we'll skip
89 # they should all be absolute paths
91 .if !empty(SKIP_GENDIRDEPS)
92 _skip_gendirdeps = egrep -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' |
97 # Below we will turn _{VAR} into ${VAR} which keeps this simple
98 # GENDIRDEPS_FILTER_DIR_VARS is a list of dirs to be substiuted for.
99 # GENDIRDEPS_FILTER_VARS is more general.
100 # In each case order matters.
101 .if !empty(GENDIRDEPS_FILTER_DIR_VARS)
102 GENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_DIR_VARS:@v@S,${$v},_{${v}},@}
104 .if !empty(GENDIRDEPS_FILTER_VARS)
105 GENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_VARS:@v@S,/${$v}/,/_{${v}}/,@:NS,//,*:u}
108 # this (*should* be set in meta.sys.mk)
109 # is the script that extracts what we want.
110 META2DEPS ?= ${.PARSEDIR}/meta2deps.sh
111 META2DEPS := ${META2DEPS}
113 .if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" && ${DEBUG_GENDIRDEPS:Uno:Mmeta2d*} != ""
123 .if ${META2DEPS:E} == "py"
124 # we can afford to do this all the time.
126 META2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d}
127 .if ${DPDEPS:tl} != "no"
128 META2DEPS_CMD += -D ${DPDEPS}
130 META2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' |
131 .elif ${META2DEPS:E} == "sh"
132 META2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} OBJTOP=${_OBJTOP}
134 META2DEPS_CMD ?= ${META2DEPS}
137 .if ${TARGET_OBJ_SPEC:U${MACHINE}} != ${MACHINE}
138 META2DEPS_CMD += -T ${TARGET_OBJ_SPEC}
141 -R ${RELDIR} -H ${HOST_TARGET} \
142 ${M2D_OBJROOTS:O:u:@o@-O $o@} \
143 ${M2D_EXCLUDES:O:u:@o@-X $o@} \
146 M2D_OBJROOTS += ${OBJTOP} ${_OBJROOT} ${_objroot}
147 .if defined(SB_OBJROOT)
148 M2D_OBJROOTS += ${SB_OBJROOT}
150 .if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == ""
151 # meta2deps.py only groks objroot
152 # so we need to give it what it expects
153 # and tell it not to add machine qualifiers
154 META2DEPS_ARGS += MACHINE=none
156 .if defined(SB_BACKING_SB)
157 META2DEPS_CMD += -S ${SB_BACKING_SB}/src
158 M2D_OBJROOTS += ${SB_BACKING_SB}/${SB_OBJPREFIX}
161 # we are only interested in the dirs
162 # specifically those we read something from.
163 # we canonicalize them to keep things simple
164 # if we are using a split-fs sandbox, it gets a little messier.
165 _objtop := ${_OBJTOP:tA}
166 dir_list != cd ${_OBJDIR} && \
167 ${META2DEPS_CMD} MACHINE=${MACHINE} \
168 SRCTOP=${SRCTOP} RELDIR=${RELDIR} CURDIR=${_CURDIR} \
170 ${META_FILES:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \
171 sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,'
173 .if ${dir_list:M*ERROR\:*} != ""
174 .warning ${dir_list:tW:C,.*(ERROR),\1,}
175 .warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,}
176 # we are not going to update anything
180 _nonlibs := ${DPADD:T:Nlib*:N*include}
183 .for f in ${_nonlibs:@x@${DPADD:M*/$x}@}
184 .if exists($f.dirdep)
185 ddep_list += $f.dirdep
186 .elif exists(${f:H}.dirdep)
187 ddep_list += ${f:H}.dirdep
189 dir_list += ${f:H:tA}
190 dpadd_dir_list += ${f:H:tA}
193 .if !empty(ddep_list)
194 ddeps != cat ${ddep_list:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \
195 sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,;s,\.${MACHINE}$$,,'
197 .if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
198 .info ${RELDIR}: raw_dir_list='${dir_list}'
199 .info ${RELDIR}: ddeps='${ddeps}'
206 # DIRDEPS represent things that had to have been built first
207 # so they should all be undir OBJTOP.
208 # Note that ${_OBJTOP}/bsd/include/machine will get reported
209 # to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we
210 # will want to visit bsd/include
212 # ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:}
213 # to GENDIRDEPS_DIR_LIST_XTRAS
214 _objtops = ${OBJTOP} ${_OBJTOP} ${_objtop}
215 _objtops := ${_objtops:O:u}
217 ${_objtops:@o@${dir_list:M$o*/*:C,$o[^/]*/,,}@} \
218 ${GENDIRDEPS_DIR_LIST_XTRAS}
221 M2D_OBJROOTS := ${M2D_OBJROOTS:O:u:[-1..1]}
223 # anything we use from an object dir other than ours
224 # needs to be qualified with its .<machine> suffix
225 # (we used the pseudo machine "host" for the HOST_TARGET).
226 skip_ql= ${SRCTOP}* ${_objtops:@o@$o*@}
227 .for o in ${M2D_OBJROOTS:${skip_ql:${M_ListToSkip}}}
228 # we need := so only skip_ql to this point applies
229 ql.$o := ${dir_list:${skip_ql:${M_ListToSkip}}:M$o*/*/*:C,$o([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,}
230 qualdir_list += ${ql.$o}
231 .if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
232 .info ${RELDIR}: o=$o ${ql.$o qualdir_list:L:@v@$v=${$v}@}
237 dirdep_list := ${dirdep_list:O:u}
238 qualdir_list := ${qualdir_list:N*.${MACHINE}:O:u}
241 ${dirdep_list:N${RELDIR}:N${RELDIR}/*} \
242 ${qualdir_list:N${RELDIR}.*:N${RELDIR}/*}
244 # We only consider things below $RELDIR/ if they have a makefile.
245 # This is the same test that _DIRDEP_USE applies.
246 # We have do a double test with dirdep_list as it _may_ contain
247 # qualified dirs - if we got anything from a stage dir.
248 # qualdir_list we know are all qualified.
249 # It would be nice do peform this check for all of DIRDEPS,
250 # but we cannot assume that all of the tree is present,
251 # in fact we can only assume that RELDIR is.
253 ${dirdep_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/$d/$m):?$d:${exists(${SRCTOP}/${d:R}/$m):?$d:}}@}@} \
254 ${qualdir_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/${d:R}/$m):?$d:}@}@}
256 DIRDEPS := ${DIRDEPS:${GENDIRDEPS_FILTER:UNno:ts:}:C,//+,/,g:O:u}
258 .if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
259 .info ${RELDIR}: M2D_OBJROOTS=${M2D_OBJROOTS}
260 .info ${RELDIR}: M2D_EXCLUDES=${M2D_EXCLUDES}
261 .info ${RELDIR}: dir_list='${dir_list}'
262 .info ${RELDIR}: dpadd_dir_list='${dpadd_dir_list}'
263 .info ${RELDIR}: dirdep_list='${dirdep_list}'
264 .info ${RELDIR}: qualdir_list='${qualdir_list}'
265 .info ${RELDIR}: SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS}'
266 .info ${RELDIR}: GENDIRDEPS_FILTER='${GENDIRDEPS_FILTER}'
267 .info ${RELDIR}: FORCE_DPADD='${DPADD}'
268 .info ${RELDIR}: DIRDEPS='${DIRDEPS}'
271 # SRC_DIRDEPS is for checkout logic
273 ${dir_list:M${SRCTOP}/*:S,${SRCTOP}/,,}
276 ${src_dirdep_list:N${RELDIR}:N${RELDIR}/*:C,(/h)/.*,,}
278 SRC_DIRDEPS := ${SRC_DIRDEPS:${GENDIRDEPS_SRC_FILTER:UN/*:ts:}:C,//+,/,g:O:u}
280 # if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put
281 # SRC_DIRDEPS_FILE = ${_DEPENDFILE}
282 # in local.gendirdeps.mk
283 .if ${SRC_DIRDEPS_FILE:Uno:tl} != "no"
284 ECHO_SRC_DIRDEPS = echo 'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS:@d@ $d \\${.newline}@}'; echo;
286 .if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T}
287 _include_src_dirdeps = ${ECHO_SRC_DIRDEPS}
289 all: ${SRC_DIRDEPS_FILE}
290 .if !target(${SRC_DIRDEPS_FILE})
291 ${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS}
292 @(${ECHO_SRC_DIRDEPS}) > $@
296 _include_src_dirdeps ?=
300 # if this is going to exist it would be there by now
302 CAT_DEPEND = /dev/null
304 CAT_DEPEND ?= .depend
306 .if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS}
307 # we may have changed a filter
308 .PHONY: ${_DEPENDFILE}
311 # 'cat .depend' should suffice, but if we are mixing build modes
312 # .depend may contain things we don't want.
313 # The sed command at the end of the stream, allows for the filters
314 # to output _{VAR} tokens which we will turn into proper ${VAR} references.
315 ${_DEPENDFILE}: .NOMETA ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS}
316 @(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \
317 echo 'DIRDEPS = \'; \
318 echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \
319 ${_include_src_dirdeps} \
320 echo '.include <dirdeps.mk>'; \
322 echo '.if $${DEP_RELDIR} == $${_DEP_RELDIR}'; \
323 echo '# local dependencies - needed for -jN in clean tree'; \
324 [ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \
325 echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID}
326 @${InstallNew}; InstallNew -s $@.new${.MAKE.PID}
328 .endif # meta2deps failed
331 DIRDEPS := ${SUBDIR:S,^,${RELDIR}/,:O:u}
335 ${_DEPENDFILE}: .NOMETA ${MAKEFILE} ${_this}
336 @(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \
337 echo 'DIRDEPS = \'; \
338 echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \
339 echo '.include <dirdeps.mk>'; \
340 echo ) | sed 's,_\([{(]\),$$\1,g' > $@.new
341 @${InstallNew}; InstallNew $@.new
349 ${_DEPENDFILE}: .PRECIOUS