1 # $Id: gendirdeps.mk,v 1.23 2013/09/04 17:49:20 sjg Exp $
3 # Copyright (c) 2010-2013, Juniper Networks, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 # This makefile [re]generates ${.MAKE.DEPENDFILE}
31 .
include <install-new.mk
>
34 # RELDIR is the relative path from ${SRCTOP} to ${_CURDIR}
35 # (SRCTOP is ${SB}/src)
36 # _CURDIR is the absolute version of ${.CURDIR}
37 # _OBJDIR is the absolute version of ${.OBJDIR}
38 # _objroot is realpath of ${_OBJTOP} without ${MACHINE}
39 # this may be different from _OBJROOT if $SB/obj is a
40 # symlink to another filesystem.
41 # _objroot must be a prefix match for _objtop
53 _OBJROOT ?
= ${OBJROOT
:U
${_OBJTOP}}
59 _objroot ?
= ${_OBJROOT
:tA
}${_slash}
61 _this
= ${.PARSEDIR
}/${.PARSEFILE
}
63 # remember what to make
64 _DEPENDFILE
:= ${_CURDIR}/${.MAKE.DEPENDFILE
:T
}
66 # We do _not_ want to read our own output!
67 .MAKE.DEPENDFILE
= /dev
/null
69 # caller should have set this
70 META_FILES ?
= ${.MAKE.META.FILES
}
72 .if
!empty
(META_FILES
)
74 .if
${.MAKE.LEVEL
} > 0 && !empty
(GENDIRDEPS_FILTER
)
75 # so we can compare below
76 .
-include <${_DEPENDFILE}>
77 # yes, I mean :U with no value
78 _DIRDEPS
:= ${DIRDEPS
:U
:O
:u
}
81 META_FILES
:= ${META_FILES
:T
:O
:u
}
84 # pickup customizations
85 .
-include "local.gendirdeps.mk"
87 # these are actually prefixes that we'll skip
88 # they should all be absolute paths
90 .if
!empty
(SKIP_GENDIRDEPS
)
91 _skip_gendirdeps
= egrep
-v
'^(${SKIP_GENDIRDEPS:O:u:ts|})' |
96 # this (*should* be set in meta.sys.mk)
97 # is the script that extracts what we want.
98 META2DEPS ?
= ${.PARSEDIR
}/meta2deps.sh
99 META2DEPS
:= ${META2DEPS}
101 .if
${DEBUG_GENDIRDEPS
:Uno
:@x@
${RELDIR
:M
$x}@
} != "" && ${DEBUG_GENDIRDEPS
:Uno
:Mmeta2d
*} != ""
111 .if
${META2DEPS
:E
} == "py"
112 # we can afford to do this all the time.
114 META2DEPS_CMD
= ${_time} ${PYTHON} ${META2DEPS} ${_py_d}
115 .if
${DPDEPS
:tl
} != "no"
116 META2DEPS_CMD
+= -D
${DPDEPS}
118 META2DEPS_FILTER
= sed
's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' |
119 .elif
${META2DEPS
:E
} == "sh"
120 META2DEPS_CMD
= ${_time} ${_sh_x} ${META2DEPS} OBJTOP
=${_OBJTOP}
122 META2DEPS_CMD ?
= ${META2DEPS}
125 .if
${TARGET_OBJ_SPEC
:U
${MACHINE}} != ${MACHINE}
126 META2DEPS_CMD
+= -T
${TARGET_OBJ_SPEC}
129 -R
${RELDIR} -H
${HOST_TARGET} \
130 ${M2D_OBJROOTS
:O
:u
:@o@
-O
$o@
}
133 M2D_OBJROOTS
+= ${OBJTOP} ${_OBJROOT} ${_objroot}
134 .if defined
(SB_OBJROOT
)
135 M2D_OBJROOTS
+= ${SB_OBJROOT}
137 .if
${.MAKE.DEPENDFILE_PREFERENCE
:U
${.MAKE.DEPENDFILE
}:M
*.
${MACHINE}} == ""
138 # meta2deps.py only groks objroot
139 # so we need to give it what it expects
140 # and tell it not to add machine qualifiers
141 META2DEPS_ARGS
+= MACHINE
=none
143 .if defined
(SB_BACKING_SB
)
144 META2DEPS_CMD
+= -S
${SB_BACKING_SB}/src
145 M2D_OBJROOTS
+= ${SB_BACKING_SB}/${SB_OBJPREFIX}
148 # we are only interested in the dirs
149 # sepecifically those we read something from.
150 # we canonicalize them to keep things simple
151 # if we are using a split-fs sandbox, it gets a little messier.
152 _objtop
:= ${_OBJTOP
:tA
}
153 dir_list
!= cd
${_OBJDIR} && \
154 ${META2DEPS_CMD} MACHINE
=${MACHINE} \
155 SRCTOP
=${SRCTOP} RELDIR
=${RELDIR} CURDIR
=${_CURDIR} \
157 ${META_FILES
:O
:u
} |
${META2DEPS_FILTER} ${_skip_gendirdeps} \
158 sed
's,//*$$,,;s,\.${HOST_TARGET}$$,.host,'
160 .if
${dir_list
:M
*ERROR\
:*} != ""
161 .warning
${dir_list
:tW
:C
,.
*(ERROR
),\
1,}
162 .warning Skipping
${_DEPENDFILE
:S
,${SRCTOP}/,,}
163 # we are not going to update anything
167 _nonlibs
:= ${DPADD
:T
:Nlib
*:N
*include}
170 .for f in
${_nonlibs
:@x@
${DPADD
:M
*/$x}@
}
171 .if exists
($f.dirdep
)
172 ddep_list
+= $f.dirdep
173 .elif exists
(${f
:H
}.dirdep
)
174 ddep_list
+= ${f
:H
}.dirdep
176 dir_list
+= ${f
:H
:tA
}
177 dpadd_dir_list
+= ${f
:H
:tA
}
180 .if
!empty
(ddep_list
)
181 ddeps
!= cat
${ddep_list
:O
:u
} |
${META2DEPS_FILTER} ${_skip_gendirdeps} \
182 sed
's,//*$$,,;s,\.${HOST_TARGET}$$,.host,;s,\.${MACHINE}$$,,'
184 .if
${DEBUG_GENDIRDEPS
:Uno
:@x@
${RELDIR
:M
$x}@
} != ""
185 .
info ${RELDIR}: raw_dir_list
='${dir_list}'
186 .
info ${RELDIR}: ddeps
='${ddeps}'
193 # DIRDEPS represent things that had to have been built first
194 # so they should all be undir OBJTOP.
195 # Note that ${_OBJTOP}/bsd/include/machine will get reported
196 # to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we
197 # will want to visit bsd/include
199 # ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:}
200 # to GENDIRDEPS_DIR_LIST_XTRAS
201 _objtops
= ${OBJTOP} ${_OBJTOP} ${_objtop}
202 _objtops
:= ${_objtops
:O
:u
}
204 ${_objtops
:@o@
${dir_list
:M
$o*/*:C
,$o[^
/]*/,,}@
} \
205 ${GENDIRDEPS_DIR_LIST_XTRAS}
208 M2D_OBJROOTS
:= ${M2D_OBJROOTS
:O
:u
:[-1.
.1]}
210 # anything we use from an object dir other than ours
211 # needs to be qualified with its .<machine> suffix
212 # (we used the pseudo machine "host" for the HOST_TARGET).
213 skip_ql
= ${SRCTOP}* ${_objtops
:@o@
$o*@
}
214 .for o in
${M2D_OBJROOTS
:${skip_ql
:${M_ListToSkip}}}
215 # we need := so only skip_ql to this point applies
216 ql.
$o := ${dir_list
:${skip_ql
:${M_ListToSkip}}:M
$o*/*/*:C
,$o([^
/]+)/(.
*),\
2.\
1,:S
,.
${HOST_TARGET},.host
,}
217 qualdir_list
+= ${ql.
$o}
218 .if
${DEBUG_GENDIRDEPS
:Uno
:@x@
${RELDIR
:M
$x}@
} != ""
219 .
info ${RELDIR}: o
=$o ${ql.
$o qualdir_list
:L
:@v@
$v=${$v}@
}
224 dirdep_list
:= ${dirdep_list
:O
:u
}
225 qualdir_list
:= ${qualdir_list
:N
*.
${MACHINE}:O
:u
}
228 ${dirdep_list
:N
${RELDIR}:N
${RELDIR}/*} \
229 ${qualdir_list
:N
${RELDIR}.
*:N
${RELDIR}/*}
231 # We only consider things below $RELDIR/ if they have a makefile.
232 # This is the same test that _DIRDEPS_USE applies.
233 # We have do a double test with dirdep_list as it _may_ contain
234 # qualified dirs - if we got anything from a stage dir.
235 # qualdir_list we know are all qualified.
236 # It would be nice do peform this check for all of DIRDEPS,
237 # but we cannot assume that all of the tree is present,
238 # in fact we can only assume that RELDIR is.
240 ${dirdep_list
:M
${RELDIR}/*:@d@
${.MAKE.MAKEFILE_PREFERENCE
:@m@
${exists
(${SRCTOP}/$d/$m):?
$d:${exists
(${SRCTOP}/${d
:R
}/$m):?
$d:}}@
}@
} \
241 ${qualdir_list
:M
${RELDIR}/*:@d@
${.MAKE.MAKEFILE_PREFERENCE
:@m@
${exists
(${SRCTOP}/${d
:R
}/$m):?
$d:}@
}@
}
243 DIRDEPS
:= ${DIRDEPS
:${GENDIRDEPS_FILTER
:UNno
:ts
:}:O
:u
}
245 .if
${DEBUG_GENDIRDEPS
:Uno
:@x@
${RELDIR
:M
$x}@
} != ""
246 .
info ${RELDIR}: M2D_OBJROOTS
=${M2D_OBJROOTS}
247 .
info ${RELDIR}: dir_list
='${dir_list}'
248 .
info ${RELDIR}: dpadd_dir_list
='${dpadd_dir_list}'
249 .
info ${RELDIR}: dirdep_list
='${dirdep_list}'
250 .
info ${RELDIR}: qualdir_list
='${qualdir_list}'
251 .
info ${RELDIR}: SKIP_GENDIRDEPS
='${SKIP_GENDIRDEPS}'
252 .
info ${RELDIR}: GENDIRDEPS_FILTER
='${GENDIRDEPS_FILTER}'
253 .
info ${RELDIR}: FORCE_DPADD
='${DPADD}'
254 .
info ${RELDIR}: DIRDEPS
='${DIRDEPS}'
257 # SRC_DIRDEPS is for checkout logic
259 ${dir_list
:M
${SRCTOP}/*:S
,${SRCTOP}/,,}
262 ${src_dirdep_list
:N
${RELDIR}:N
${RELDIR}/*:C
,(/h
)/.
*,,}
264 SRC_DIRDEPS
:= ${SRC_DIRDEPS
:${GENDIRDEPS_SRC_FILTER
:UN
/*:ts
:}:O
:u
}
266 # if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put
267 # SRC_DIRDEPS_FILE = ${_DEPENDFILE}
268 # in local.gendirdeps.mk
269 .if
${SRC_DIRDEPS_FILE
:Uno
:tl
} != "no"
270 ECHO_SRC_DIRDEPS
= echo
'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS
:@d@
$d \\${.newline
}@
}'; echo;
272 .if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T}
273 _include_src_dirdeps = ${ECHO_SRC_DIRDEPS}
275 all: ${SRC_DIRDEPS_FILE}
276 .if !target(${SRC_DIRDEPS_FILE})
277 ${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS}
278 @(${ECHO_SRC_DIRDEPS}) > $@
282 _include_src_dirdeps ?=
286 # if this is going to exist it would be there by now
288 CAT_DEPEND = /dev/null
290 CAT_DEPEND ?= .depend
292 .if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS}
293 # we may have changed a filter
294 .PHONY: ${_DEPENDFILE}
297 # 'cat .depend
' should suffice, but if we are mixing build modes
298 # .depend may contain things we don't want.
299 # The sed command at the end of the stream, allows for the filters
300 # to output _{VAR} tokens which we will turn into proper ${VAR} references.
301 ${_DEPENDFILE}: ${CAT_DEPEND
:M.depend
} ${META_FILES
:O
:u
:@m@
${exists
($m):?
$m:}@
} ${_this} ${META2DEPS}
302 @
(echo
'# Autogenerated - do NOT edit!'; echo
; \
303 echo
'DEP_RELDIR := $${_PARSEDIR:S,$${SRCTOP}/,,}'; echo
; \
304 echo
'DIRDEPS = \'; \
305 echo '${DIRDEPS
:@d@
$d \\${.newline
}@
}'; echo; \
306 ${_include_src_dirdeps} \
307 echo '.
include <dirdeps.mk
>'; \
309 echo '.if
$${DEP_RELDIR} == $${_DEP_RELDIR}'; \
310 echo '# local dependencies - needed for -jN in clean tree'; \
311 [ -s
${CAT_DEPEND} ] && { grep
: ${CAT_DEPEND} | grep
-v
'[/\\]'; }; \
312 echo
'.endif' ) | sed
's,_\([{(]\),$$\1,g' > $@.new
${.MAKE.PID
}
313 @
${InstallNew}; InstallNew
-s
$@.new
${.MAKE.PID
}
315 .
endif # meta2deps failed
318 DIRDEPS
:= ${SUBDIR
:S
,^
,${RELDIR}/,:O
:u
}
322 ${_DEPENDFILE}: ${MAKEFILE} ${_this}
323 @
(echo
'# Autogenerated - do NOT edit!'; echo
; \
324 echo
'DEP_RELDIR := $${_PARSEDIR:S,$${SRCTOP}/,,}'; echo
; \
325 echo
'DIRDEPS = \'; \
326 echo '${DIRDEPS
:@d@
$d \\${.newline
}@
}'; echo; \
327 echo '.
include <dirdeps.mk
>'; \
328 echo ) | sed 's
,_\
([{(]\
),$$\
1,g
' > $@.new
329 @${InstallNew}; InstallNew $@.new
337 ${_DEPENDFILE}: .PRECIOUS