gendirdeps.mk revision 296637
1296637Ssjg# $Id: gendirdeps.mk,v 1.30 2016/02/27 00:20:39 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 96281812Ssjg# Below we will turn _{VAR} into ${VAR} which keeps this simple 97281812Ssjg# GENDIRDEPS_FILTER_DIR_VARS is a list of dirs to be substiuted for. 98281812Ssjg# GENDIRDEPS_FILTER_VARS is more general. 99281812Ssjg# In each case order matters. 100281812Ssjg.if !empty(GENDIRDEPS_FILTER_DIR_VARS) 101281812SsjgGENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_DIR_VARS:@v@S,${$v},_{${v}},@} 102281812Ssjg.endif 103281812Ssjg.if !empty(GENDIRDEPS_FILTER_VARS) 104281812SsjgGENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_VARS:@v@S,/${$v}/,/_{${v}}/,@:NS,//,*:u} 105281812Ssjg.endif 106281812Ssjg 107246149Ssjg# this (*should* be set in meta.sys.mk) 108246149Ssjg# is the script that extracts what we want. 109246149SsjgMETA2DEPS ?= ${.PARSEDIR}/meta2deps.sh 110246149SsjgMETA2DEPS := ${META2DEPS} 111246149Ssjg 112246149Ssjg.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" && ${DEBUG_GENDIRDEPS:Uno:Mmeta2d*} != "" 113246149Ssjg_time = time 114246149Ssjg_sh_x = sh -x 115246149Ssjg_py_d = -ddd 116246149Ssjg.else 117246149Ssjg_time = 118246149Ssjg_sh_x = 119246149Ssjg_py_d = 120246149Ssjg.endif 121246149Ssjg 122246149Ssjg.if ${META2DEPS:E} == "py" 123246149Ssjg# we can afford to do this all the time. 124246149SsjgDPDEPS ?= no 125250837SsjgMETA2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d} 126246149Ssjg.if ${DPDEPS:tl} != "no" 127246149SsjgMETA2DEPS_CMD += -D ${DPDEPS} 128246149Ssjg.endif 129250837SsjgMETA2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' | 130250837Ssjg.elif ${META2DEPS:E} == "sh" 131250837SsjgMETA2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} OBJTOP=${_OBJTOP} 132250837Ssjg.else 133250837SsjgMETA2DEPS_CMD ?= ${META2DEPS} 134250837Ssjg.endif 135249033Ssjg 136250837Ssjg.if ${TARGET_OBJ_SPEC:U${MACHINE}} != ${MACHINE} 137250837SsjgMETA2DEPS_CMD += -T ${TARGET_OBJ_SPEC} 138250837Ssjg.endif 139250837SsjgMETA2DEPS_CMD += \ 140250837Ssjg -R ${RELDIR} -H ${HOST_TARGET} \ 141250837Ssjg ${M2D_OBJROOTS:O:u:@o@-O $o@} 142250837Ssjg 143250837Ssjg 144249033SsjgM2D_OBJROOTS += ${OBJTOP} ${_OBJROOT} ${_objroot} 145249033Ssjg.if defined(SB_OBJROOT) 146249033SsjgM2D_OBJROOTS += ${SB_OBJROOT} 147249033Ssjg.endif 148246149Ssjg.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == "" 149246149Ssjg# meta2deps.py only groks objroot 150246149Ssjg# so we need to give it what it expects 151246149Ssjg# and tell it not to add machine qualifiers 152246149SsjgMETA2DEPS_ARGS += MACHINE=none 153246149Ssjg.endif 154246149Ssjg.if defined(SB_BACKING_SB) 155249033SsjgMETA2DEPS_CMD += -S ${SB_BACKING_SB}/src 156249033SsjgM2D_OBJROOTS += ${SB_BACKING_SB}/${SB_OBJPREFIX} 157246149Ssjg.endif 158246149Ssjg 159246149Ssjg# we are only interested in the dirs 160289842Ssjg# specifically those we read something from. 161246149Ssjg# we canonicalize them to keep things simple 162246149Ssjg# if we are using a split-fs sandbox, it gets a little messier. 163246149Ssjg_objtop := ${_OBJTOP:tA} 164246149Ssjgdir_list != cd ${_OBJDIR} && \ 165246149Ssjg ${META2DEPS_CMD} MACHINE=${MACHINE} \ 166246149Ssjg SRCTOP=${SRCTOP} RELDIR=${RELDIR} CURDIR=${_CURDIR} \ 167246149Ssjg ${META2DEPS_ARGS} \ 168246149Ssjg ${META_FILES:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \ 169246149Ssjg sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,' 170246149Ssjg 171246149Ssjg.if ${dir_list:M*ERROR\:*} != "" 172246149Ssjg.warning ${dir_list:tW:C,.*(ERROR),\1,} 173246149Ssjg.warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,} 174246149Ssjg# we are not going to update anything 175246149Ssjg.else 176255253Ssjgdpadd_dir_list= 177246149Ssjg.if !empty(DPADD) 178246149Ssjg_nonlibs := ${DPADD:T:Nlib*:N*include} 179246149Ssjg.if !empty(_nonlibs) 180249033Ssjgddep_list = 181249033Ssjg.for f in ${_nonlibs:@x@${DPADD:M*/$x}@} 182249033Ssjg.if exists($f.dirdep) 183249033Ssjgddep_list += $f.dirdep 184249033Ssjg.elif exists(${f:H}.dirdep) 185249033Ssjgddep_list += ${f:H}.dirdep 186249033Ssjg.else 187249033Ssjgdir_list += ${f:H:tA} 188255253Ssjgdpadd_dir_list += ${f:H:tA} 189246149Ssjg.endif 190249033Ssjg.endfor 191249033Ssjg.if !empty(ddep_list) 192249033Ssjgddeps != cat ${ddep_list:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \ 193249033Ssjg sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,;s,\.${MACHINE}$$,,' 194249033Ssjg 195249033Ssjg.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" 196249033Ssjg.info ${RELDIR}: raw_dir_list='${dir_list}' 197249033Ssjg.info ${RELDIR}: ddeps='${ddeps}' 198246149Ssjg.endif 199249033Ssjgdir_list += ${ddeps} 200249033Ssjg.endif 201249033Ssjg.endif 202249033Ssjg.endif 203246149Ssjg 204246149Ssjg# DIRDEPS represent things that had to have been built first 205246149Ssjg# so they should all be undir OBJTOP. 206246149Ssjg# Note that ${_OBJTOP}/bsd/include/machine will get reported 207246149Ssjg# to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we 208246149Ssjg# will want to visit bsd/include 209246149Ssjg# so we add 210246149Ssjg# ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:} 211246149Ssjg# to GENDIRDEPS_DIR_LIST_XTRAS 212255253Ssjg_objtops = ${OBJTOP} ${_OBJTOP} ${_objtop} 213249033Ssjg_objtops := ${_objtops:O:u} 214246149Ssjgdirdep_list = \ 215249033Ssjg ${_objtops:@o@${dir_list:M$o*/*:C,$o[^/]*/,,}@} \ 216246149Ssjg ${GENDIRDEPS_DIR_LIST_XTRAS} 217246149Ssjg 218249033Ssjg# sort longest first 219249033SsjgM2D_OBJROOTS := ${M2D_OBJROOTS:O:u:[-1..1]} 220249033Ssjg 221246149Ssjg# anything we use from an object dir other than ours 222246149Ssjg# needs to be qualified with its .<machine> suffix 223246149Ssjg# (we used the pseudo machine "host" for the HOST_TARGET). 224249033Ssjgskip_ql= ${SRCTOP}* ${_objtops:@o@$o*@} 225249033Ssjg.for o in ${M2D_OBJROOTS:${skip_ql:${M_ListToSkip}}} 226249033Ssjg# we need := so only skip_ql to this point applies 227255253Ssjgql.$o := ${dir_list:${skip_ql:${M_ListToSkip}}:M$o*/*/*:C,$o([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,} 228255253Ssjgqualdir_list += ${ql.$o} 229255253Ssjg.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" 230255253Ssjg.info ${RELDIR}: o=$o ${ql.$o qualdir_list:L:@v@$v=${$v}@} 231255253Ssjg.endif 232249033Ssjgskip_ql+= $o* 233249033Ssjg.endfor 234246149Ssjg 235246149Ssjgdirdep_list := ${dirdep_list:O:u} 236249033Ssjgqualdir_list := ${qualdir_list:N*.${MACHINE}:O:u} 237246149Ssjg 238246149SsjgDIRDEPS = \ 239246149Ssjg ${dirdep_list:N${RELDIR}:N${RELDIR}/*} \ 240246149Ssjg ${qualdir_list:N${RELDIR}.*:N${RELDIR}/*} 241246149Ssjg 242246149Ssjg# We only consider things below $RELDIR/ if they have a makefile. 243268437Ssjg# This is the same test that _DIRDEP_USE applies. 244246149Ssjg# We have do a double test with dirdep_list as it _may_ contain 245246149Ssjg# qualified dirs - if we got anything from a stage dir. 246246149Ssjg# qualdir_list we know are all qualified. 247246149Ssjg# It would be nice do peform this check for all of DIRDEPS, 248246149Ssjg# but we cannot assume that all of the tree is present, 249246149Ssjg# in fact we can only assume that RELDIR is. 250246149SsjgDIRDEPS += \ 251246149Ssjg ${dirdep_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/$d/$m):?$d:${exists(${SRCTOP}/${d:R}/$m):?$d:}}@}@} \ 252246149Ssjg ${qualdir_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/${d:R}/$m):?$d:}@}@} 253246149Ssjg 254268437SsjgDIRDEPS := ${DIRDEPS:${GENDIRDEPS_FILTER:UNno:ts:}:C,//+,/,g:O:u} 255246149Ssjg 256246149Ssjg.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" 257249033Ssjg.info ${RELDIR}: M2D_OBJROOTS=${M2D_OBJROOTS} 258246149Ssjg.info ${RELDIR}: dir_list='${dir_list}' 259255253Ssjg.info ${RELDIR}: dpadd_dir_list='${dpadd_dir_list}' 260246149Ssjg.info ${RELDIR}: dirdep_list='${dirdep_list}' 261246149Ssjg.info ${RELDIR}: qualdir_list='${qualdir_list}' 262246149Ssjg.info ${RELDIR}: SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS}' 263246149Ssjg.info ${RELDIR}: GENDIRDEPS_FILTER='${GENDIRDEPS_FILTER}' 264246149Ssjg.info ${RELDIR}: FORCE_DPADD='${DPADD}' 265246149Ssjg.info ${RELDIR}: DIRDEPS='${DIRDEPS}' 266246149Ssjg.endif 267246149Ssjg 268246149Ssjg# SRC_DIRDEPS is for checkout logic 269246149Ssjgsrc_dirdep_list = \ 270246149Ssjg ${dir_list:M${SRCTOP}/*:S,${SRCTOP}/,,} 271246149Ssjg 272246149SsjgSRC_DIRDEPS = \ 273246149Ssjg ${src_dirdep_list:N${RELDIR}:N${RELDIR}/*:C,(/h)/.*,,} 274246149Ssjg 275268437SsjgSRC_DIRDEPS := ${SRC_DIRDEPS:${GENDIRDEPS_SRC_FILTER:UN/*:ts:}:C,//+,/,g:O:u} 276246149Ssjg 277246149Ssjg# if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put 278246149Ssjg# SRC_DIRDEPS_FILE = ${_DEPENDFILE} 279246149Ssjg# in local.gendirdeps.mk 280246149Ssjg.if ${SRC_DIRDEPS_FILE:Uno:tl} != "no" 281246149SsjgECHO_SRC_DIRDEPS = echo 'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS:@d@ $d \\${.newline}@}'; echo; 282246149Ssjg 283246149Ssjg.if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T} 284246149Ssjg_include_src_dirdeps = ${ECHO_SRC_DIRDEPS} 285246149Ssjg.else 286246149Ssjgall: ${SRC_DIRDEPS_FILE} 287246149Ssjg.if !target(${SRC_DIRDEPS_FILE}) 288246149Ssjg${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS} 289246149Ssjg @(${ECHO_SRC_DIRDEPS}) > $@ 290246149Ssjg.endif 291246149Ssjg.endif 292246149Ssjg.endif 293246149Ssjg_include_src_dirdeps ?= 294246149Ssjg 295246149Ssjgall: ${_DEPENDFILE} 296246149Ssjg 297246149Ssjg# if this is going to exist it would be there by now 298246149Ssjg.if !exists(.depend) 299246149SsjgCAT_DEPEND = /dev/null 300246149Ssjg.endif 301246149SsjgCAT_DEPEND ?= .depend 302246149Ssjg 303246149Ssjg.if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS} 304246149Ssjg# we may have changed a filter 305246149Ssjg.PHONY: ${_DEPENDFILE} 306246149Ssjg.endif 307246149Ssjg 308246149Ssjg# 'cat .depend' should suffice, but if we are mixing build modes 309246149Ssjg# .depend may contain things we don't want. 310246149Ssjg# The sed command at the end of the stream, allows for the filters 311246149Ssjg# to output _{VAR} tokens which we will turn into proper ${VAR} references. 312296637Ssjg${_DEPENDFILE}: .NOMETA ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS} 313289842Ssjg @(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \ 314246149Ssjg echo 'DIRDEPS = \'; \ 315246149Ssjg echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ 316246149Ssjg ${_include_src_dirdeps} \ 317246149Ssjg echo '.include <dirdeps.mk>'; \ 318246149Ssjg echo; \ 319246149Ssjg echo '.if $${DEP_RELDIR} == $${_DEP_RELDIR}'; \ 320246149Ssjg echo '# local dependencies - needed for -jN in clean tree'; \ 321246149Ssjg [ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \ 322246149Ssjg echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID} 323246149Ssjg @${InstallNew}; InstallNew -s $@.new${.MAKE.PID} 324246149Ssjg 325246149Ssjg.endif # meta2deps failed 326246149Ssjg.elif !empty(SUBDIR) 327246149Ssjg 328246149SsjgDIRDEPS := ${SUBDIR:S,^,${RELDIR}/,:O:u} 329246149Ssjg 330246149Ssjgall: ${_DEPENDFILE} 331246149Ssjg 332296637Ssjg${_DEPENDFILE}: .NOMETA ${MAKEFILE} ${_this} 333289842Ssjg @(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \ 334246149Ssjg echo 'DIRDEPS = \'; \ 335246149Ssjg echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ 336246149Ssjg echo '.include <dirdeps.mk>'; \ 337246149Ssjg echo ) | sed 's,_\([{(]\),$$\1,g' > $@.new 338246149Ssjg @${InstallNew}; InstallNew $@.new 339246149Ssjg 340246149Ssjg.else 341246149Ssjg 342246149Ssjg# nothing to do 343246149Ssjgall ${_DEPENDFILE}: 344246149Ssjg 345246149Ssjg.endif 346246149Ssjg${_DEPENDFILE}: .PRECIOUS 347