1 # $Id: gendirdeps.mk,v 1.10 2012/06/30 00:37:50 sjg Exp $
3 # Copyright (c) 2010, Juniper Networks, Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 # This makefile [re]generates ${.MAKE.DEPENDFILE}
30 .include <install-new.mk>
33 # RELDIR is the relative path from ${SRCTOP} to ${_CURDIR}
34 # (SRCTOP is ${SB}/src)
35 # _CURDIR is the absolute version of ${.CURDIR}
36 # _OBJDIR is the absolute version of ${.OBJDIR}
37 # _objroot is realpath of ${_OBJTOP} without ${MACHINE}
38 # this may be different from _OBJROOT if $SB/obj is a
39 # symlink to another filesystem.
40 # _objroot must be a prefix match for _objtop
52 _OBJROOT ?= ${OBJROOT:U${_OBJTOP}}
53 _objroot ?= ${_OBJROOT:tA}
55 _this = ${.PARSEDIR}/${.PARSEFILE}
57 # remember what to make
58 _DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T}
60 # We do _not_ want to read our own output!
61 .MAKE.DEPENDFILE = /dev/null
63 # caller should have set this
64 META_FILES ?= ${.MAKE.META.FILES}
66 .if !empty(META_FILES)
68 .if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER)
69 # so we can compare below
70 .-include <${_DEPENDFILE}>
71 # yes, I mean :U with no value
72 _DIRDEPS := ${DIRDEPS:U:O:u}
75 META_FILES := ${META_FILES:T:O:u}
78 # pickup customizations
79 .-include "local.gendirdeps.mk"
81 # these are actually prefixes that we'll skip
82 # they should all be absolute paths
84 .if !empty(SKIP_GENDIRDEPS)
85 _skip_gendirdeps = egrep -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' |
90 # this (*should* be set in meta.sys.mk)
91 # is the script that extracts what we want.
92 META2DEPS ?= ${.PARSEDIR}/meta2deps.sh
93 META2DEPS := ${META2DEPS}
95 .if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" && ${DEBUG_GENDIRDEPS:Uno:Mmeta2d*} != ""
105 .if ${META2DEPS:E} == "py"
106 # we can afford to do this all the time.
108 META2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d} \
109 -R ${RELDIR} -H ${HOST_TARGET} -O ${M2D_OBJROOT}
110 .if ${DPDEPS:tl} != "no"
111 META2DEPS_CMD += -D ${DPDEPS}
113 .if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == ""
114 # meta2deps.py only groks objroot
115 # so we need to give it what it expects
116 M2D_OBJROOT = ${OBJTOP}/
117 # and tell it not to add machine qualifiers
118 META2DEPS_ARGS += MACHINE=none
120 .if defined(SB_OBJROOT)
121 M2D_OBJROOT ?= ${SB_OBJROOT}
123 M2D_OBJROOT = ${OBJTOP}/
126 .if defined(SB_BACKING_SB)
127 META2DEPS_CMD += -S ${SB_BACKING_SB}/src -O ${SB_BACKING_SB}/${SB_OBJPREFIX}
129 META2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' |
130 .elif ${META2DEPS:E} == "sh"
131 META2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} \
132 OBJTOP=${_objtop} SB_OBJROOT=${_objroot}
134 META2DEPS_CMD ?= ${META2DEPS}
137 # we are only interested in the dirs
138 # sepecifically those we read something from.
139 # we canonicalize them to keep things simple
140 # if we are using a split-fs sandbox, it gets a little messier.
141 _objtop := ${_OBJTOP:tA}
142 dir_list != cd ${_OBJDIR} && \
143 ${META2DEPS_CMD} MACHINE=${MACHINE} \
144 SRCTOP=${SRCTOP} RELDIR=${RELDIR} CURDIR=${_CURDIR} \
146 ${META_FILES:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \
147 sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,'
149 .if ${dir_list:M*ERROR\:*} != ""
150 .warning ${dir_list:tW:C,.*(ERROR),\1,}
151 .warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,}
152 # we are not going to update anything
156 _nonlibs := ${DPADD:T:Nlib*:N*include}
158 dir_list += ${_nonlibs:@x@${DPADD:M*/$x}@:H:tA}
162 # DIRDEPS represent things that had to have been built first
163 # so they should all be undir OBJTOP.
164 # Note that ${_OBJTOP}/bsd/include/machine will get reported
165 # to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we
166 # will want to visit bsd/include
168 # ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:}
169 # to GENDIRDEPS_DIR_LIST_XTRAS
171 ${dir_list:M${_objtop}*/*:C,${_objtop}[^/]*/,,} \
172 ${GENDIRDEPS_DIR_LIST_XTRAS}
174 # anything we use from an object dir other than ours
175 # needs to be qualified with its .<machine> suffix
176 # (we used the pseudo machine "host" for the HOST_TARGET).
178 ${dir_list:M${_objroot}*/*/*:N${SRCTOP}*:N${_objtop}*:C,${_objroot}([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,}
180 .if ${_OBJROOT} != ${_objroot}
182 ${dir_list:M${_OBJTOP}*/*:C,${_OBJTOP}[^/]*/,,}
185 ${dir_list:M${_OBJROOT}*/*/*:N${SRCTOP}*:N${_OBJTOP}*:C,${_OBJROOT}([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,}
188 dirdep_list := ${dirdep_list:O:u}
189 qualdir_list := ${qualdir_list:O:u}
192 ${dirdep_list:N${RELDIR}:N${RELDIR}/*} \
193 ${qualdir_list:N${RELDIR}.*:N${RELDIR}/*}
195 # We only consider things below $RELDIR/ if they have a makefile.
196 # This is the same test that _DIRDEPS_USE applies.
197 # We have do a double test with dirdep_list as it _may_ contain
198 # qualified dirs - if we got anything from a stage dir.
199 # qualdir_list we know are all qualified.
200 # It would be nice do peform this check for all of DIRDEPS,
201 # but we cannot assume that all of the tree is present,
202 # in fact we can only assume that RELDIR is.
204 ${dirdep_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/$d/$m):?$d:${exists(${SRCTOP}/${d:R}/$m):?$d:}}@}@} \
205 ${qualdir_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/${d:R}/$m):?$d:}@}@}
207 DIRDEPS := ${DIRDEPS:${GENDIRDEPS_FILTER:UNno:ts:}:O:u}
209 .if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
210 .info ${RELDIR}: dir_list='${dir_list}'
211 .info ${RELDIR}: dirdep_list='${dirdep_list}'
212 .info ${RELDIR}: qualdir_list='${qualdir_list}'
213 .info ${RELDIR}: SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS}'
214 .info ${RELDIR}: GENDIRDEPS_FILTER='${GENDIRDEPS_FILTER}'
215 .info ${RELDIR}: FORCE_DPADD='${DPADD}'
216 .info ${RELDIR}: DIRDEPS='${DIRDEPS}'
219 # SRC_DIRDEPS is for checkout logic
221 ${dir_list:M${SRCTOP}/*:S,${SRCTOP}/,,}
224 ${src_dirdep_list:N${RELDIR}:N${RELDIR}/*:C,(/h)/.*,,}
226 SRC_DIRDEPS := ${SRC_DIRDEPS:${GENDIRDEPS_SRC_FILTER:UN/*:ts:}:O:u}
228 # if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put
229 # SRC_DIRDEPS_FILE = ${_DEPENDFILE}
230 # in local.gendirdeps.mk
231 .if ${SRC_DIRDEPS_FILE:Uno:tl} != "no"
232 ECHO_SRC_DIRDEPS = echo 'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS:@d@ $d \\${.newline}@}'; echo;
234 .if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T}
235 _include_src_dirdeps = ${ECHO_SRC_DIRDEPS}
237 all: ${SRC_DIRDEPS_FILE}
238 .if !target(${SRC_DIRDEPS_FILE})
239 ${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS}
240 @(${ECHO_SRC_DIRDEPS}) > $@
244 _include_src_dirdeps ?=
248 # if this is going to exist it would be there by now
250 CAT_DEPEND = /dev/null
252 CAT_DEPEND ?= .depend
254 .if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS}
255 # we may have changed a filter
256 .PHONY: ${_DEPENDFILE}
259 # 'cat .depend' should suffice, but if we are mixing build modes
260 # .depend may contain things we don't want.
261 # The sed command at the end of the stream, allows for the filters
262 # to output _{VAR} tokens which we will turn into proper ${VAR} references.
263 ${_DEPENDFILE}: ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS}
264 @(echo '# Autogenerated - do NOT edit!'; echo; \
265 echo 'DEP_RELDIR := $${_PARSEDIR:S,$${SRCTOP}/,,}'; echo; \
266 echo 'DEP_MACHINE := $${.PARSEFILE:E}'; echo; \
267 echo 'DIRDEPS = \'; \
268 echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \
269 ${_include_src_dirdeps} \
270 echo '.include <dirdeps.mk>'; \
272 echo '.if $${DEP_RELDIR} == $${_DEP_RELDIR}'; \
273 echo '# local dependencies - needed for -jN in clean tree'; \
274 [ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \
275 echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID}
276 @${InstallNew}; InstallNew -s $@.new${.MAKE.PID}
278 .endif # meta2deps failed
281 DIRDEPS := ${SUBDIR:S,^,${RELDIR}/,:O:u}
285 ${_DEPENDFILE}: ${MAKEFILE} ${_this}
286 @(echo '# Autogenerated - do NOT edit!'; echo; \
287 echo 'DEP_RELDIR := $${_PARSEDIR:S,$${SRCTOP}/,,}'; echo; \
288 echo 'DEP_MACHINE := $${.PARSEFILE:E}'; echo; \
289 echo 'DIRDEPS = \'; \
290 echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \
291 echo '.include <dirdeps.mk>'; \
292 echo ) | sed 's,_\([{(]\),$$\1,g' > $@.new
293 @${InstallNew}; InstallNew $@.new
301 ${_DEPENDFILE}: .PRECIOUS