meta.autodep.mk revision 256281
1251607Sdim# $Id: meta.autodep.mk,v 1.32 2012/11/13 00:44:26 sjg Exp $ 2251607Sdim 3251607Sdim# 4251607Sdim# @(#) Copyright (c) 2010, Simon J. Gerraty 5251607Sdim# 6251607Sdim# This file is provided in the hope that it will 7251607Sdim# be of use. There is absolutely NO WARRANTY. 8251607Sdim# Permission to copy, redistribute or otherwise 9251607Sdim# use this file is hereby granted provided that 10251607Sdim# the above copyright notice and this notice are 11251607Sdim# left intact. 12251607Sdim# 13251607Sdim# Please send copies of changes and bug-fixes to: 14251607Sdim# sjg@crufty.net 15251607Sdim# 16251607Sdim 17251607Sdim_this ?= ${.PARSEFILE} 18251607Sdim.if !target(__${_this}__) 19251607Sdim__${_this}__: .NOTMAIN 20251607Sdim 21251607Sdim.-include "local.autodep.mk" 22251607Sdim 23251607Sdim.if defined(SRCS) 24251607Sdim# it would be nice to be able to query .SUFFIXES 25251607SdimOBJ_EXTENSIONS+= .o .po .lo .So 26251607Sdim 27251607Sdim# explicit dependencies help short-circuit .SUFFIX searches 28251607SdimSRCS_DEP_FILTER+= N*.[hly] 29251607Sdim.for s in ${SRCS:${SRCS_DEP_FILTER:O:u:ts:}} 30251607Sdim.for e in ${OBJ_EXTENSIONS:O:u} 31251607Sdim.if !target(${s:T:R}$e) 32251607Sdim${s:T:R}$e: $s 33251607Sdim.endif 34251607Sdim.endfor 35251607Sdim.endfor 36251607Sdim.endif 37251607Sdim 38251607Sdim.if make(gendirdeps) 39251607Sdim# you are supposed to know what you are doing! 40251607SdimUPDATE_DEPENDFILE = yes 41251607Sdim.elif !empty(.TARGETS) && !make(all) 42251607Sdim# do not update the *depend* files 43251607Sdim# unless we are building the entire directory or the default target. 44251607Sdim# NO means don't update .depend - or Makefile.depend* 45251607Sdim# no means update .depend but not Makefile.depend* 46251607SdimUPDATE_DEPENDFILE = NO 47251607Sdim.elif ${.MAKEFLAGS:M-k} != "" 48251607Sdim# it is a bad idea to update anything 49251607SdimUPDATE_DEPENDFILE = NO 50251607Sdim.endif 51251607Sdim 52251607Sdim_CURDIR ?= ${.CURDIR} 53251607Sdim_DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T} 54251607Sdim 55251607Sdim.if ${.MAKE.LEVEL} == 0 56251607Sdim.if ${BUILD_AT_LEVEL0:Uyes:tl} == "no" 57251607SdimUPDATE_DEPENDFILE = NO 58251607Sdim.endif 59251607Sdim.endif 60251607Sdim.if !exists(${_DEPENDFILE}) 61251607Sdim_bootstrap_dirdeps = yes 62251607Sdim.endif 63251607Sdim_bootstrap_dirdeps ?= no 64251607SdimUPDATE_DEPENDFILE ?= yes 65251607Sdim 66251607Sdim.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" 67251607Sdim.info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE} 68251607Sdim.endif 69251607Sdim 70251607Sdim.if !empty(XMAKE_META_FILE) 71251607Sdim.if exists(${.OBJDIR}/${XMAKE_META_FILE}) 72251607Sdim# we cannot get accurate dependencies from an update build 73251607SdimUPDATE_DEPENDFILE = NO 74251607Sdim.else 75251607SdimMETA_XTRAS += ${XMAKE_META_FILE} 76251607Sdim.endif 77251607Sdim.endif 78251607Sdim 79251607Sdim.if ${_bootstrap_dirdeps} == "yes" || exists(${_DEPENDFILE}) 80251607Sdim# if it isn't supposed to be touched by us the Makefile should have 81251607Sdim# UPDATE_DEPENDFILE = no 82251607SdimWANT_UPDATE_DEPENDFILE ?= yes 83251607Sdim.endif 84251607Sdim 85251607Sdim.if ${WANT_UPDATE_DEPENDFILE:Uno:tl} != "no" 86251607Sdim.if ${.MAKE.MODE:Mmeta*} == "" || ${.MAKE.MODE:M*read*} != "" 87251607SdimUPDATE_DEPENDFILE = no 88251607Sdim.endif 89251607Sdim 90251607Sdim.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" 91251607Sdim.info ${_DEPENDFILE:S,${SRCTOP}/,,} update=${UPDATE_DEPENDFILE} 92251607Sdim.endif 93251607Sdim 94251607Sdim.if ${UPDATE_DEPENDFILE:tl} == "yes" 95251607Sdim# sometimes we want .meta files generated to aid debugging/error detection 96251607Sdim# but do not want to consider them for dependencies 97251607Sdim# for example the result of running configure 98# just make sure this is not empty 99META_FILE_FILTER ?= N.meta 100 101.if !empty(DPADD) 102# if we have any non-libs in DPADD, 103# they probably need to be paid attention to 104.if !empty(DPLIBS) 105FORCE_DPADD = ${DPADD:${DPLIBS:${M_ListToSkip}}:${DPADD_LAST:${M_ListToSkip}}} 106.else 107_nonlibs := ${DPADD:T:Nlib*:N*include} 108.if !empty(_nonlibs) 109FORCE_DPADD += ${_nonlibs:@x@${DPADD:M*/$x}@} 110.endif 111.endif 112.endif 113 114.if !make(gendirdeps) 115.END: gendirdeps 116.endif 117 118# if we don't have OBJS, then .depend isn't useful 119.if !target(.depend) && (!empty(OBJS) || ${.ALLTARGETS:M*.o} != "") 120# some makefiles and/or targets contain 121# circular dependencies if you dig too deep 122# (as meta mode is apt to do) 123# so we provide a means of supressing them. 124# the input to the loop below is target: dependency 125# with just one dependency per line. 126# Also some targets are not really local, or use random names. 127# Use local.autodep.mk to provide local additions! 128SUPPRESS_DEPEND += \ 129 ${SB:S,/,_,g}* \ 130 *:y.tab.c \ 131 *.c:*.c \ 132 *.h:*.h 133 134.NOPATH: .depend 135# we use ${.MAKE.META.CREATED} to trigger an update but 136# we process using ${.MAKE.META.FILES} 137# the double $$ defers initial evaluation 138# if necessary, we fake .po dependencies, just so the result 139# in Makefile.depend* is stable 140# The current objdir may be refered to in various ways 141OBJDIR_REFS += ${.OBJDIR} ${.OBJDIR:tA} ${_OBJDIR} ${RELOBJTOP}/${RELDIR} 142_depend = .depend 143# it would be nice to be able to get .SUFFIXES as ${.SUFFIXES} 144# we actually only care about the .SUFFIXES of files that might be 145# generated by tools like yacc. 146DEPEND_SUFFIXES += .c .h .cpp .hpp .cxx .hxx .cc .hh 147.depend: .NOMETA $${.MAKE.META.CREATED} ${_this} 148 @echo "Updating $@: ${.OODATE:T:[1..8]}" 149 @egrep -i '^R .*\.(${DEPEND_SUFFIXES:tl:O:u:S,^.,,:ts|})$$' /dev/null ${.MAKE.META.FILES:T:O:u:${META_FILE_FILTER:ts:}:M*o.meta} | \ 150 sed -e 's, \./, ,${OBJDIR_REFS:O:u:@d@;s, $d/, ,@};/\//d' \ 151 -e 's,^\([^/][^/]*\).meta...[0-9]* ,\1: ,' | \ 152 sort -u | \ 153 while read t d; do \ 154 case "$$d:" in $$t) continue;; esac; \ 155 case "$$t$$d" in ${SUPPRESS_DEPEND:U.:O:u:ts|}) continue;; esac; \ 156 echo $$t $$d; \ 157 done > $@.${.MAKE.PID} 158 @case "${.MAKE.META.FILES:T:M*.po.*}" in \ 159 *.po.*) mv $@.${.MAKE.PID} $@;; \ 160 *) { cat $@.${.MAKE.PID}; \ 161 sed 's,\.So:,.o:,;s,\.o:,.po:,' $@.${.MAKE.PID}; } | sort -u > $@; \ 162 rm -f $@.${.MAKE.PID};; \ 163 esac 164.else 165# make sure this exists 166.depend: 167# do _not_ assume that .depend is in any fit state for us to use 168CAT_DEPEND = /dev/null 169.if ${.MAKE.LEVEL} > 0 170.export CAT_DEPEND 171.endif 172_depend = 173.endif 174 175.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" 176.info ${_DEPENDFILE:S,${SRCTOP}/,,} _depend=${_depend} 177.endif 178 179gendirdeps: ${_DEPENDFILE} 180 181.if !target(${_DEPENDFILE}) 182.if ${_bootstrap_dirdeps} == "yes" 183# We are boot-strapping a new directory 184# Use DPADD to seed DIRDEPS 185.if !empty(DPADD) 186# anything which matches ${_OBJROOT}* but not ${_OBJTOP}* 187# needs to be qualified in DIRDEPS 188# The pseudo machine "host" is used for HOST_TARGET 189DIRDEPS = \ 190 ${DPADD:M${_OBJTOP}*:H:C,${_OBJTOP}[^/]*/,,:N.:O:u} \ 191 ${DPADD:M${_OBJROOT}*:N${_OBJTOP}*:H:S,${_OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u} 192 193.endif 194.endif 195 196_gendirdeps_mutex = 197.if defined(NEED_GENDIRDEPS_MUTEX) 198# If a src dir gets built with multiple object dirs, 199# we need a mutex. Obviously, this is best avoided. 200# Note if .MAKE.DEPENDFILE is common for all ${MACHINE} 201# you either need to mutex, or ensure only one machine builds at a time! 202# lockf is an example of a suitable tool 203LOCKF ?= /usr/bin/lockf 204.if exists(${LOCKF}) 205GENDIRDEPS_MUTEXER ?= ${LOCKF} -k 206.endif 207.if empty(GENDIRDEPS_MUTEXER) 208.error NEED_GENDIRDEPS_MUTEX defined, but GENDIRDEPS_MUTEXER not set 209.else 210_gendirdeps_mutex = ${GENDIRDEPS_MUTEXER} ${GENDIRDEPS_MUTEX:U${_CURDIR}/Makefile} 211.endif 212.endif 213 214# If we have META_XTRAS we most likely did not create them 215# but we need to behave as if we did. 216# Avoid adding glob patterns to .MAKE.META.CREATED though. 217.MAKE.META.CREATED += ${META_XTRAS:N*\**:O:u} 218 219.if make(gendirdeps) 220META_FILES = *.meta 221.elif ${OPTIMIZE_OBJECT_META_FILES:Uno:tl} == "no" 222META_FILES = ${.MAKE.META.FILES:T:N.depend*:O:u} 223.else 224# if we have 1000's of .o.meta, .So.meta etc we need only look at one set 225# it is left as an exercise for the reader to work out what this does 226META_FILES = ${.MAKE.META.FILES:T:N.depend*:N*o.meta:O:u} \ 227 ${.MAKE.META.FILES:T:M*.${.MAKE.META.FILES:M*o.meta:R:E:O:u:[1]}.meta:O:u} 228.endif 229 230.if ${DEBUG_AUTODEP:Uno:@m@${RELDIR:M$m}@} != "" 231.info ${_DEPENDFILE:S,${SRCTOP}/,,}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} xtras=${META_XTRAS} 232.endif 233 234.if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER) 235.export GENDIRDEPS_FILTER 236.endif 237 238# we might have .../ in MAKESYSPATH 239_makesyspath:= ${_PARSEDIR} 240${_DEPENDFILE}: ${_depend} ${.PARSEDIR}/gendirdeps.mk ${META2DEPS} $${.MAKE.META.CREATED} 241 @echo Checking $@: ${.OODATE:T:[1..8]} 242 @(cd . && \ 243 SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS:O:u}' \ 244 DPADD='${FORCE_DPADD:O:u}' ${_gendirdeps_mutex} \ 245 MAKESYSPATH=${_makesyspath} \ 246 ${.MAKE} -f gendirdeps.mk RELDIR=${RELDIR} _DEPENDFILE=${_DEPENDFILE} \ 247 META_FILES='${META_XTRAS:T:O:u} ${META_FILES:T:O:u:${META_FILE_FILTER:ts:}}') 248 @test -s $@ && touch $@; : 249.endif 250 251.endif 252.endif 253 254.if ${_bootstrap_dirdeps} == "yes" 255# make sure this is included at least once 256.include <dirdeps.mk> 257.else 258${_DEPENDFILE}: .PRECIOUS 259.endif 260 261CLEANFILES += *.meta filemon.* *.db 262.endif 263