gendirdeps.mk revision 249033
1249033Ssjg# $Id: gendirdeps.mk,v 1.21 2013/03/28 20:01:05 sjg Exp $ 2246149Ssjg 3249033Ssjg# Copyright (c) 2010-2013, Juniper Networks, Inc. 4249033Ssjg# All rights reserved. 5246149Ssjg# 6246149Ssjg# Redistribution and use in source and binary forms, with or without 7246149Ssjg# modification, are permitted provided that the following conditions 8246149Ssjg# are met: 9246149Ssjg# 1. Redistributions of source code must retain the above copyright 10246149Ssjg# notice, this list of conditions and the following disclaimer. 11246149Ssjg# 2. Redistributions in binary form must reproduce the above copyright 12246149Ssjg# notice, this list of conditions and the following disclaimer in the 13246149Ssjg# documentation and/or other materials provided with the distribution. 14246149Ssjg# 15246149Ssjg# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16246149Ssjg# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17246149Ssjg# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18246149Ssjg# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19246149Ssjg# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20246149Ssjg# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21246149Ssjg# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22246149Ssjg# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23246149Ssjg# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24246149Ssjg# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25246149Ssjg# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26246149Ssjg 27246149Ssjg# 28246149Ssjg# This makefile [re]generates ${.MAKE.DEPENDFILE} 29246149Ssjg# 30246149Ssjg 31246149Ssjg.include <install-new.mk> 32246149Ssjg 33246149Ssjg# Assumptions: 34246149Ssjg# RELDIR is the relative path from ${SRCTOP} to ${_CURDIR} 35246149Ssjg# (SRCTOP is ${SB}/src) 36246149Ssjg# _CURDIR is the absolute version of ${.CURDIR} 37246149Ssjg# _OBJDIR is the absolute version of ${.OBJDIR} 38246149Ssjg# _objroot is realpath of ${_OBJTOP} without ${MACHINE} 39246149Ssjg# this may be different from _OBJROOT if $SB/obj is a 40246149Ssjg# symlink to another filesystem. 41246149Ssjg# _objroot must be a prefix match for _objtop 42246149Ssjg 43246149Ssjg.MAIN: all 44246149Ssjg 45246149Ssjg# keep this simple 46246149Ssjg.MAKE.MODE = compat 47246149Ssjg 48246149Ssjgall: 49246149Ssjg 50246149Ssjg_CURDIR ?= ${.CURDIR} 51246149Ssjg_OBJDIR ?= ${.OBJDIR} 52246149Ssjg_OBJTOP ?= ${OBJTOP} 53246149Ssjg_OBJROOT ?= ${OBJROOT:U${_OBJTOP}} 54249033Ssjg.if ${_OBJROOT:M*/} 55249033Ssjg_slash=/ 56249033Ssjg.else 57249033Ssjg_slash= 58249033Ssjg.endif 59249033Ssjg_objroot ?= ${_OBJROOT:tA}${_slash} 60246149Ssjg 61246149Ssjg_this = ${.PARSEDIR}/${.PARSEFILE} 62246149Ssjg 63246149Ssjg# remember what to make 64246149Ssjg_DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T} 65246149Ssjg 66246149Ssjg# We do _not_ want to read our own output! 67246149Ssjg.MAKE.DEPENDFILE = /dev/null 68246149Ssjg 69246149Ssjg# caller should have set this 70246149SsjgMETA_FILES ?= ${.MAKE.META.FILES} 71246149Ssjg 72246149Ssjg.if !empty(META_FILES) 73246149Ssjg 74246149Ssjg.if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER) 75246149Ssjg# so we can compare below 76246149Ssjg.-include <${_DEPENDFILE}> 77246149Ssjg# yes, I mean :U with no value 78246149Ssjg_DIRDEPS := ${DIRDEPS:U:O:u} 79246149Ssjg.endif 80246149Ssjg 81246149SsjgMETA_FILES := ${META_FILES:T:O:u} 82246149Ssjg.export META_FILES 83246149Ssjg 84246149Ssjg# pickup customizations 85246149Ssjg.-include "local.gendirdeps.mk" 86246149Ssjg 87246149Ssjg# these are actually prefixes that we'll skip 88246149Ssjg# they should all be absolute paths 89246149SsjgSKIP_GENDIRDEPS ?= 90246149Ssjg.if !empty(SKIP_GENDIRDEPS) 91246149Ssjg_skip_gendirdeps = egrep -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' | 92246149Ssjg.else 93246149Ssjg_skip_gendirdeps = 94246149Ssjg.endif 95246149Ssjg 96246149Ssjg# this (*should* be set in meta.sys.mk) 97246149Ssjg# is the script that extracts what we want. 98246149SsjgMETA2DEPS ?= ${.PARSEDIR}/meta2deps.sh 99246149SsjgMETA2DEPS := ${META2DEPS} 100246149Ssjg 101246149Ssjg.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" && ${DEBUG_GENDIRDEPS:Uno:Mmeta2d*} != "" 102246149Ssjg_time = time 103246149Ssjg_sh_x = sh -x 104246149Ssjg_py_d = -ddd 105246149Ssjg.else 106246149Ssjg_time = 107246149Ssjg_sh_x = 108246149Ssjg_py_d = 109246149Ssjg.endif 110246149Ssjg 111246149Ssjg.if ${META2DEPS:E} == "py" 112246149Ssjg# we can afford to do this all the time. 113246149SsjgDPDEPS ?= no 114246149SsjgMETA2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d} \ 115249033Ssjg -R ${RELDIR} -H ${HOST_TARGET} \ 116249033Ssjg ${M2D_OBJROOTS:O:u:@o@-O $o@} 117249033Ssjg 118246149Ssjg.if ${DPDEPS:tl} != "no" 119246149SsjgMETA2DEPS_CMD += -D ${DPDEPS} 120246149Ssjg.endif 121249033Ssjg 122249033SsjgM2D_OBJROOTS += ${OBJTOP} ${_OBJROOT} ${_objroot} 123249033Ssjg.if defined(SB_OBJROOT) 124249033SsjgM2D_OBJROOTS += ${SB_OBJROOT} 125249033Ssjg.endif 126246149Ssjg.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == "" 127246149Ssjg# meta2deps.py only groks objroot 128246149Ssjg# so we need to give it what it expects 129246149Ssjg# and tell it not to add machine qualifiers 130246149SsjgMETA2DEPS_ARGS += MACHINE=none 131246149Ssjg.endif 132246149Ssjg.if defined(SB_BACKING_SB) 133249033SsjgMETA2DEPS_CMD += -S ${SB_BACKING_SB}/src 134249033SsjgM2D_OBJROOTS += ${SB_BACKING_SB}/${SB_OBJPREFIX} 135246149Ssjg.endif 136246149SsjgMETA2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' | 137246149Ssjg.elif ${META2DEPS:E} == "sh" 138246149SsjgMETA2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} \ 139246149Ssjg OBJTOP=${_objtop} SB_OBJROOT=${_objroot} 140246149Ssjg.else 141246149SsjgMETA2DEPS_CMD ?= ${META2DEPS} 142246149Ssjg.endif 143246149Ssjg 144246149Ssjg# we are only interested in the dirs 145246149Ssjg# sepecifically those we read something from. 146246149Ssjg# we canonicalize them to keep things simple 147246149Ssjg# if we are using a split-fs sandbox, it gets a little messier. 148246149Ssjg_objtop := ${_OBJTOP:tA} 149246149Ssjgdir_list != cd ${_OBJDIR} && \ 150246149Ssjg ${META2DEPS_CMD} MACHINE=${MACHINE} \ 151246149Ssjg SRCTOP=${SRCTOP} RELDIR=${RELDIR} CURDIR=${_CURDIR} \ 152246149Ssjg ${META2DEPS_ARGS} \ 153246149Ssjg ${META_FILES:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \ 154246149Ssjg sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,' 155246149Ssjg 156246149Ssjg.if ${dir_list:M*ERROR\:*} != "" 157246149Ssjg.warning ${dir_list:tW:C,.*(ERROR),\1,} 158246149Ssjg.warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,} 159246149Ssjg# we are not going to update anything 160246149Ssjg.else 161246149Ssjg 162246149Ssjg.if !empty(DPADD) 163246149Ssjg_nonlibs := ${DPADD:T:Nlib*:N*include} 164246149Ssjg.if !empty(_nonlibs) 165249033Ssjgddep_list = 166249033Ssjg.for f in ${_nonlibs:@x@${DPADD:M*/$x}@} 167249033Ssjg.if exists($f.dirdep) 168249033Ssjgddep_list += $f.dirdep 169249033Ssjg.elif exists(${f:H}.dirdep) 170249033Ssjgddep_list += ${f:H}.dirdep 171249033Ssjg.else 172249033Ssjgdir_list += ${f:H:tA} 173246149Ssjg.endif 174249033Ssjg.endfor 175249033Ssjg.if !empty(ddep_list) 176249033Ssjgddeps != cat ${ddep_list:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \ 177249033Ssjg sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,;s,\.${MACHINE}$$,,' 178249033Ssjg 179249033Ssjg.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" 180249033Ssjg.info ${RELDIR}: raw_dir_list='${dir_list}' 181249033Ssjg.info ${RELDIR}: ddeps='${ddeps}' 182246149Ssjg.endif 183249033Ssjgdir_list += ${ddeps} 184249033Ssjg.endif 185249033Ssjg.endif 186249033Ssjg.endif 187246149Ssjg 188246149Ssjg# DIRDEPS represent things that had to have been built first 189246149Ssjg# so they should all be undir OBJTOP. 190246149Ssjg# Note that ${_OBJTOP}/bsd/include/machine will get reported 191246149Ssjg# to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we 192246149Ssjg# will want to visit bsd/include 193246149Ssjg# so we add 194246149Ssjg# ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:} 195246149Ssjg# to GENDIRDEPS_DIR_LIST_XTRAS 196249033Ssjg_objtops = ${OBJTOP} ${_OBJTOP} ${_obtop} 197249033Ssjg_objtops := ${_objtops:O:u} 198246149Ssjgdirdep_list = \ 199249033Ssjg ${_objtops:@o@${dir_list:M$o*/*:C,$o[^/]*/,,}@} \ 200246149Ssjg ${GENDIRDEPS_DIR_LIST_XTRAS} 201246149Ssjg 202249033Ssjg# sort longest first 203249033SsjgM2D_OBJROOTS := ${M2D_OBJROOTS:O:u:[-1..1]} 204249033Ssjg 205246149Ssjg# anything we use from an object dir other than ours 206246149Ssjg# needs to be qualified with its .<machine> suffix 207246149Ssjg# (we used the pseudo machine "host" for the HOST_TARGET). 208249033Ssjgskip_ql= ${SRCTOP}* ${_objtops:@o@$o*@} 209249033Ssjg.for o in ${M2D_OBJROOTS:${skip_ql:${M_ListToSkip}}} 210249033Ssjg# we need := so only skip_ql to this point applies 211249033Ssjgql := ${dir_list:${skip_ql:${M_ListToSkip}}:M$o*/*/*:C,$o([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,} 212249033Ssjgqualdir_list += ${ql} 213249033Ssjgskip_ql+= $o* 214249033Ssjg.endfor 215246149Ssjg 216246149Ssjgdirdep_list := ${dirdep_list:O:u} 217249033Ssjgqualdir_list := ${qualdir_list:N*.${MACHINE}:O:u} 218246149Ssjg 219246149SsjgDIRDEPS = \ 220246149Ssjg ${dirdep_list:N${RELDIR}:N${RELDIR}/*} \ 221246149Ssjg ${qualdir_list:N${RELDIR}.*:N${RELDIR}/*} 222246149Ssjg 223246149Ssjg# We only consider things below $RELDIR/ if they have a makefile. 224246149Ssjg# This is the same test that _DIRDEPS_USE applies. 225246149Ssjg# We have do a double test with dirdep_list as it _may_ contain 226246149Ssjg# qualified dirs - if we got anything from a stage dir. 227246149Ssjg# qualdir_list we know are all qualified. 228246149Ssjg# It would be nice do peform this check for all of DIRDEPS, 229246149Ssjg# but we cannot assume that all of the tree is present, 230246149Ssjg# in fact we can only assume that RELDIR is. 231246149SsjgDIRDEPS += \ 232246149Ssjg ${dirdep_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/$d/$m):?$d:${exists(${SRCTOP}/${d:R}/$m):?$d:}}@}@} \ 233246149Ssjg ${qualdir_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/${d:R}/$m):?$d:}@}@} 234246149Ssjg 235246149SsjgDIRDEPS := ${DIRDEPS:${GENDIRDEPS_FILTER:UNno:ts:}:O:u} 236246149Ssjg 237246149Ssjg.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" 238249033Ssjg.info ${RELDIR}: M2D_OBJROOTS=${M2D_OBJROOTS} 239246149Ssjg.info ${RELDIR}: dir_list='${dir_list}' 240246149Ssjg.info ${RELDIR}: dirdep_list='${dirdep_list}' 241246149Ssjg.info ${RELDIR}: qualdir_list='${qualdir_list}' 242246149Ssjg.info ${RELDIR}: SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS}' 243246149Ssjg.info ${RELDIR}: GENDIRDEPS_FILTER='${GENDIRDEPS_FILTER}' 244246149Ssjg.info ${RELDIR}: FORCE_DPADD='${DPADD}' 245246149Ssjg.info ${RELDIR}: DIRDEPS='${DIRDEPS}' 246246149Ssjg.endif 247246149Ssjg 248246149Ssjg# SRC_DIRDEPS is for checkout logic 249246149Ssjgsrc_dirdep_list = \ 250246149Ssjg ${dir_list:M${SRCTOP}/*:S,${SRCTOP}/,,} 251246149Ssjg 252246149SsjgSRC_DIRDEPS = \ 253246149Ssjg ${src_dirdep_list:N${RELDIR}:N${RELDIR}/*:C,(/h)/.*,,} 254246149Ssjg 255246149SsjgSRC_DIRDEPS := ${SRC_DIRDEPS:${GENDIRDEPS_SRC_FILTER:UN/*:ts:}:O:u} 256246149Ssjg 257246149Ssjg# if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put 258246149Ssjg# SRC_DIRDEPS_FILE = ${_DEPENDFILE} 259246149Ssjg# in local.gendirdeps.mk 260246149Ssjg.if ${SRC_DIRDEPS_FILE:Uno:tl} != "no" 261246149SsjgECHO_SRC_DIRDEPS = echo 'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS:@d@ $d \\${.newline}@}'; echo; 262246149Ssjg 263246149Ssjg.if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T} 264246149Ssjg_include_src_dirdeps = ${ECHO_SRC_DIRDEPS} 265246149Ssjg.else 266246149Ssjgall: ${SRC_DIRDEPS_FILE} 267246149Ssjg.if !target(${SRC_DIRDEPS_FILE}) 268246149Ssjg${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS} 269246149Ssjg @(${ECHO_SRC_DIRDEPS}) > $@ 270246149Ssjg.endif 271246149Ssjg.endif 272246149Ssjg.endif 273246149Ssjg_include_src_dirdeps ?= 274246149Ssjg 275246149Ssjgall: ${_DEPENDFILE} 276246149Ssjg 277246149Ssjg# if this is going to exist it would be there by now 278246149Ssjg.if !exists(.depend) 279246149SsjgCAT_DEPEND = /dev/null 280246149Ssjg.endif 281246149SsjgCAT_DEPEND ?= .depend 282246149Ssjg 283246149Ssjg.if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS} 284246149Ssjg# we may have changed a filter 285246149Ssjg.PHONY: ${_DEPENDFILE} 286246149Ssjg.endif 287246149Ssjg 288246149Ssjg# 'cat .depend' should suffice, but if we are mixing build modes 289246149Ssjg# .depend may contain things we don't want. 290246149Ssjg# The sed command at the end of the stream, allows for the filters 291246149Ssjg# to output _{VAR} tokens which we will turn into proper ${VAR} references. 292246149Ssjg${_DEPENDFILE}: ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS} 293246149Ssjg @(echo '# Autogenerated - do NOT edit!'; echo; \ 294246149Ssjg echo 'DEP_RELDIR := $${_PARSEDIR:S,$${SRCTOP}/,,}'; echo; \ 295246149Ssjg echo 'DIRDEPS = \'; \ 296246149Ssjg echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ 297246149Ssjg ${_include_src_dirdeps} \ 298246149Ssjg echo '.include <dirdeps.mk>'; \ 299246149Ssjg echo; \ 300246149Ssjg echo '.if $${DEP_RELDIR} == $${_DEP_RELDIR}'; \ 301246149Ssjg echo '# local dependencies - needed for -jN in clean tree'; \ 302246149Ssjg [ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \ 303246149Ssjg echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID} 304246149Ssjg @${InstallNew}; InstallNew -s $@.new${.MAKE.PID} 305246149Ssjg 306246149Ssjg.endif # meta2deps failed 307246149Ssjg.elif !empty(SUBDIR) 308246149Ssjg 309246149SsjgDIRDEPS := ${SUBDIR:S,^,${RELDIR}/,:O:u} 310246149Ssjg 311246149Ssjgall: ${_DEPENDFILE} 312246149Ssjg 313246149Ssjg${_DEPENDFILE}: ${MAKEFILE} ${_this} 314246149Ssjg @(echo '# Autogenerated - do NOT edit!'; echo; \ 315246149Ssjg echo 'DEP_RELDIR := $${_PARSEDIR:S,$${SRCTOP}/,,}'; echo; \ 316246149Ssjg echo 'DIRDEPS = \'; \ 317246149Ssjg echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ 318246149Ssjg echo '.include <dirdeps.mk>'; \ 319246149Ssjg echo ) | sed 's,_\([{(]\),$$\1,g' > $@.new 320246149Ssjg @${InstallNew}; InstallNew $@.new 321246149Ssjg 322246149Ssjg.else 323246149Ssjg 324246149Ssjg# nothing to do 325246149Ssjgall ${_DEPENDFILE}: 326246149Ssjg 327246149Ssjg.endif 328246149Ssjg${_DEPENDFILE}: .PRECIOUS 329