xref: /freebsd/share/mk/bsd.dep.mk (revision bca92be68309e9b0c8f1c1c0a9ca87081c4ab27d)
17f3dea24SPeter Wemm# $FreeBSD$
253996fadSWolfram Schneider#
353996fadSWolfram Schneider# The include file <bsd.dep.mk> handles Makefile dependencies.
453996fadSWolfram Schneider#
553996fadSWolfram Schneider#
653996fadSWolfram Schneider# +++ variables +++
753996fadSWolfram Schneider#
8ae038fc3SBryan Drewery# CLEANDEPENDDIRS	Additional directories to remove for the cleandepend
9ae038fc3SBryan Drewery# 			target.
10ae038fc3SBryan Drewery#
11ae038fc3SBryan Drewery# CLEANDEPENDFILES	Additional files to remove for the cleandepend target.
12ae038fc3SBryan Drewery#
13ccc4bab1SRuslan Ermilov# CTAGS		A tags file generation program [gtags]
14ccc4bab1SRuslan Ermilov#
15ccc4bab1SRuslan Ermilov# CTAGSFLAGS	Options for ctags(1) [not set]
16ccc4bab1SRuslan Ermilov#
1753996fadSWolfram Schneider# DEPENDFILE	dependencies file [.depend]
1853996fadSWolfram Schneider#
19ccc4bab1SRuslan Ermilov# GTAGSFLAGS	Options for gtags(1) [-o]
20ccc4bab1SRuslan Ermilov#
21ccc4bab1SRuslan Ermilov# HTAGSFLAGS	Options for htags(1) [not set]
22ccc4bab1SRuslan Ermilov#
2353996fadSWolfram Schneider# SRCS          List of source files (c, c++, assembler)
2453996fadSWolfram Schneider#
2511dc9298SRuslan Ermilov# DPSRCS	List of source files which are needed for generating
2611dc9298SRuslan Ermilov#		dependencies, ${SRCS} are always part of it.
2753996fadSWolfram Schneider#
2853996fadSWolfram Schneider# +++ targets +++
2953996fadSWolfram Schneider#
3053996fadSWolfram Schneider#	cleandepend:
31ae038fc3SBryan Drewery#		remove ${CLEANDEPENDFILES}; remove ${CLEANDEPENDDIRS} and all
32ae038fc3SBryan Drewery#		contents.
3353996fadSWolfram Schneider#
3453996fadSWolfram Schneider#	depend:
3553996fadSWolfram Schneider#		Make the dependencies for the source files, and store
3653996fadSWolfram Schneider#		them in the file ${DEPENDFILE}.
3753996fadSWolfram Schneider#
3853996fadSWolfram Schneider#	tags:
39ccc4bab1SRuslan Ermilov#		In "ctags" mode, create a tags file for the source files.
40ccc4bab1SRuslan Ermilov#		In "gtags" mode, create a (GLOBAL) gtags file for the
41ccc4bab1SRuslan Ermilov#		source files.  If HTML is defined, htags(1) is also run
42ccc4bab1SRuslan Ermilov#		after gtags(1).
4353996fadSWolfram Schneider
445ffdf361SRuslan Ermilov.if !target(__<bsd.init.mk>__)
455ffdf361SRuslan Ermilov.error bsd.dep.mk cannot be included directly.
465ffdf361SRuslan Ermilov.endif
47b16495e7SWolfram Schneider
48ccc4bab1SRuslan ErmilovCTAGS?=		gtags
49ccc4bab1SRuslan ErmilovCTAGSFLAGS?=
50ccc4bab1SRuslan ErmilovGTAGSFLAGS?=	-o
51ccc4bab1SRuslan ErmilovHTAGSFLAGS?=
52ccc4bab1SRuslan Ermilov
53369737d7SBryan Drewery.if ${MK_DIRDEPS_BUILD} == "no"
54fc2c2cd9SBryan Drewery.MAKE.DEPENDFILE= ${DEPENDFILE}
55369737d7SBryan Drewery.endif
56caf1fb32SBryan DreweryCLEANDEPENDFILES+=	${DEPENDFILE} ${DEPENDFILE}.*
57b964b943SBryan Drewery.if ${MK_META_MODE} == "yes"
58b964b943SBryan DreweryCLEANDEPENDFILES+=	*.meta
59b964b943SBryan Drewery.endif
60d14f862cSGarrett Wollman
61ccc4bab1SRuslan Ermilov# Keep `tags' here, before SRCS are mangled below for `depend'.
626260f1d8SRuslan Ermilov.if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
63ccc4bab1SRuslan Ermilovtags: ${SRCS}
64213a4447SRuslan Ermilov.if ${CTAGS:T} == "gtags"
65ccc4bab1SRuslan Ermilov	@cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
66ccc4bab1SRuslan Ermilov.if defined(HTML)
67ccc4bab1SRuslan Ermilov	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
68ccc4bab1SRuslan Ermilov.endif
69213a4447SRuslan Ermilov.else
70213a4447SRuslan Ermilov	@${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
71213a4447SRuslan Ermilov	    ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
72ccc4bab1SRuslan Ermilov.endif
73ccc4bab1SRuslan Ermilov.endif
74ccc4bab1SRuslan Ermilov
75799483e4SBryan Drewery.if !empty(.MAKE.MODE:Mmeta) && empty(.MAKE.MODE:Mnofilemon)
76799483e4SBryan Drewery_meta_filemon=	1
77799483e4SBryan Drewery.endif
78396561c9SBryan Drewery# By default META_MODE is disabled in bmake if there is no OBJDIR
79396561c9SBryan Drewery# unless .MAKE.MODE contains "curdirOk=[^0nNfF]"
80396561c9SBryan Drewery.if defined(_meta_filemon) && ${.OBJDIR} == ${.CURDIR} && \
81396561c9SBryan Drewery    (empty(.MAKE.MODE:tl:Mcurdirok=*) || \
82396561c9SBryan Drewery    !empty(.MAKE.MODE:tl:Mcurdirok=[0NnFf]*))
83396561c9SBryan Drewery.undef _meta_filemon
84396561c9SBryan Drewery.endif
85799483e4SBryan Drewery
86c30c436aSBryan Drewery# Skip reading .depend when not needed to speed up tree-walks and simple
87d7173250SBryan Drewery# lookups.  See _SKIP_BUILD logic in bsd.init.mk for more details.
88799483e4SBryan Drewery# Also skip generating or including .depend.* files if in meta+filemon mode
89210ecc00SBryan Drewery# since it will track dependencies itself.  OBJS_DEPEND_GUESS is still used
90210ecc00SBryan Drewery# for _meta_filemon but not for _SKIP_DEPEND.
91ecc39238SBryan Drewery.if !defined(NO_SKIP_DEPEND) && defined(_SKIP_BUILD)
92210ecc00SBryan Drewery_SKIP_DEPEND=	1
93210ecc00SBryan Drewery.endif
94e65dd92bSBryan Drewery.if ${MK_DIRDEPS_BUILD} == "no"
95210ecc00SBryan Drewery.if defined(_SKIP_DEPEND) || defined(_meta_filemon)
969fb02a70SBryan Drewery.MAKE.DEPENDFILE=	/dev/null
979fb02a70SBryan Drewery.endif
989fb02a70SBryan Drewery.endif
999fb02a70SBryan Drewery
1002ec8b6deSBruce Evans.if defined(SRCS)
1012ec8b6deSBruce EvansCLEANFILES?=
1022ec8b6deSBruce Evans
1038a152f97SRui Paulo.for _S in ${SRCS:N*.[dhly]}
1042506d700SSimon J. GerratyOBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.o+=	${_S}
105d7beff08SBryan Drewery.endfor
1066b14fdfaSRuslan Ermilov
1079f65e34fSRui Paulo# Lexical analyzers
1082ec8b6deSBruce Evans.for _LSRC in ${SRCS:M*.l:N*/*}
109484933a9SRuslan Ermilov.for _LC in ${_LSRC:R}.c
1105852ae2dSBryan Drewery${_LC}: ${_LSRC}
1115a2899acSBjoern A. Zeeb	${LEX} ${LFLAGS} ${LFLAGS.${_LSRC}} -o${.TARGET} ${.ALLSRC}
112919154d9SBryan DreweryOBJS_DEPEND_GUESS.${_LC:R}.o+=	${_LC}
1132ec8b6deSBruce EvansSRCS:=	${SRCS:S/${_LSRC}/${_LC}/}
114484933a9SRuslan ErmilovCLEANFILES+= ${_LC}
1152ec8b6deSBruce Evans.endfor
1162ec8b6deSBruce Evans.endfor
1172ec8b6deSBruce Evans
1189f65e34fSRui Paulo# Yacc grammars
1192ec8b6deSBruce Evans.for _YSRC in ${SRCS:M*.y:N*/*}
120484933a9SRuslan Ermilov.for _YC in ${_YSRC:R}.c
1212ec8b6deSBruce EvansSRCS:=	${SRCS:S/${_YSRC}/${_YC}/}
122484933a9SRuslan ErmilovCLEANFILES+= ${_YC}
12365d2bdc6SRuslan Ermilov.if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
124000a2e70SBryan Drewery# Multi-output targets both expect a .meta file and will fight over it. Only
125000a2e70SBryan Drewery# allow it on the .c file instead.
126000a2e70SBryan Dreweryy.tab.h: ${_YC} .NOMETA
127000a2e70SBryan Drewery# Force rebuild the .c file if any of its other outputs are missing.
128000a2e70SBryan Drewery.if !exists(y.tab.h)
129000a2e70SBryan Drewery${_YC}: .PHONY .META
130000a2e70SBryan Drewery.endif
131000a2e70SBryan Drewery${_YC}: ${_YSRC}
1325a2899acSBjoern A. Zeeb	${YACC} ${YFLAGS} ${YFLAGS.${_YSRC}} ${.ALLSRC}
1332ec8b6deSBruce Evans	cp y.tab.c ${_YC}
134484933a9SRuslan ErmilovCLEANFILES+= y.tab.c y.tab.h
13565d2bdc6SRuslan Ermilov.elif !empty(YFLAGS:M-d)
136484933a9SRuslan Ermilov.for _YH in ${_YC:R}.h
137000a2e70SBryan Drewery# Multi-output targets both expect a .meta file and will fight over it. Only
138000a2e70SBryan Drewery# allow it on the .c file instead.
139000a2e70SBryan Drewery${_YH}: ${_YC} .NOMETA
140000a2e70SBryan Drewery# Force rebuild the .c file if any of its other outputs are missing.
141000a2e70SBryan Drewery.if !exists(${_YH})
142000a2e70SBryan Drewery${_YC}: .PHONY .META
143000a2e70SBryan Drewery.endif
144000a2e70SBryan Drewery${_YC}: ${_YSRC}
1455a2899acSBjoern A. Zeeb	${YACC} ${YFLAGS} ${YFLAGS.${_YSRC}} -o ${_YC} ${.ALLSRC}
146484933a9SRuslan ErmilovSRCS+=	${_YH}
147484933a9SRuslan ErmilovCLEANFILES+= ${_YH}
1482ec8b6deSBruce Evans.endfor
1492ec8b6deSBruce Evans.else
1505852ae2dSBryan Drewery${_YC}: ${_YSRC}
1515a2899acSBjoern A. Zeeb	${YACC} ${YFLAGS} ${YFLAGS.${_YSRC}} -o ${_YC} ${.ALLSRC}
1522ec8b6deSBruce Evans.endif
153919154d9SBryan DreweryOBJS_DEPEND_GUESS.${_YC:R}.o+=	${_YC}
1542ec8b6deSBruce Evans.endfor
1552ec8b6deSBruce Evans.endfor
1569f65e34fSRui Paulo
1579f65e34fSRui Paulo# DTrace probe definitions
158ff0f36e7SRui Paulo.if ${SRCS:M*.d}
1595439a715SMark JohnstonCFLAGS+=	-I${.OBJDIR}
160ff0f36e7SRui Paulo.endif
1619f65e34fSRui Paulo.for _DSRC in ${SRCS:M*.d:N*/*}
162ff0f36e7SRui Paulo.for _D in ${_DSRC:R}
163cfa5f2beSBryan DrewerySRCS+=	${_D}.h
1645852ae2dSBryan Drewery${_D}.h: ${_DSRC}
1650c76c8aaSMark Johnston	${DTRACE} ${DTRACEFLAGS} -h -s ${.ALLSRC}
166e9083b2dSMark JohnstonSRCS:=	${SRCS:S/^${_DSRC}$//}
167d8b63155SRui PauloOBJS+=	${_D}.o
1689b646f25SRui PauloCLEANFILES+= ${_D}.h ${_D}.o
1695852ae2dSBryan Drewery${_D}.o: ${_DSRC} ${OBJS:S/^${_D}.o$//}
170a298c279SBryan Drewery	@rm -f ${.TARGET}
171cfa5f2beSBryan Drewery	${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
1729b646f25SRui Paulo.if defined(LIB)
1732d781301SAlex RichardsonCLEANFILES+= ${_D}.pico ${_D}.pieo ${_D}.po ${_D}.nossppico
1742b4da8aaSMarcel Moolenaar${_D}.pico: ${_DSRC} ${SOBJS:S/^${_D}.pico$//}
175a298c279SBryan Drewery	@rm -f ${.TARGET}
176cfa5f2beSBryan Drewery	${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
1772d781301SAlex Richardson${_D}.pieo: ${_DSRC} ${OBJS:S/^${_D}.pieo$//}
1782d781301SAlex Richardson	@rm -f ${.TARGET}
1792d781301SAlex Richardson	${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
1805852ae2dSBryan Drewery${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
181a298c279SBryan Drewery	@rm -f ${.TARGET}
182cfa5f2beSBryan Drewery	${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
183db08bfceSKonstantin Belousov${_D}.nossppico: ${_DSRC} ${SOBJS:S/^${_D}.nossppico$//}
184db08bfceSKonstantin Belousov	@rm -f ${.TARGET}
185db08bfceSKonstantin Belousov	${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
186ff0f36e7SRui Paulo.endif
1879f65e34fSRui Paulo.endfor
1889f65e34fSRui Paulo.endfor
189ee4eeb32SBryan Drewery.endif	# defined(SRCS)
190b9964333SBryan Drewery
191e32a2cbeSBryan Drewery.if ${MAKE_VERSION} < 20160220
192b9964333SBryan DreweryDEPEND_MP?=	-MP
193e32a2cbeSBryan Drewery.endif
194b9964333SBryan Drewery# Handle OBJS=../somefile.o hacks.  Just replace '/' rather than use :T to
195b9964333SBryan Drewery# avoid collisions.
196b9964333SBryan DreweryDEPEND_FILTER=	C,/,_,g
197ee4eeb32SBryan Drewery.if !empty(OBJS)
198ab0c68baSAlex Richardson.if !defined(_ALLOW_ABSOLUTE_OBJ_PATH) && ${OBJS:M/*}
199ab0c68baSAlex Richardson# Absolute paths to OBJS should be an error inside ${SRCTOP}, but some users
200ab0c68baSAlex Richardson# might be relying on this feature, so add an opt-out mechanism.
201ab0c68baSAlex Richardson.if defined(SRCTOP) && ${OBJS:M${SRCTOP}*}
202*bca92be6SJohn Baldwin.error $$OBJS inside $$SRCTOP not allowed: ${OBJS:M${SRCTOP}*}
203ab0c68baSAlex Richardson.elif ${OBJS:N${_ABSOLUTE_PATH_OBJS}:M/*}
204*bca92be6SJohn Baldwin.error $$OBJS absolute path not allowed: ${OBJS:N${_ABSOLUTE_PATH_OBJS}:M/*}.\
205ab0c68baSAlex Richardson    If this is intended, add them to _ABSOLUTE_PATH_OBJS to silence this error\
206*bca92be6SJohn Baldwin    or define _ALLOW_ABSOLUTE_OBJ_PATH to disable this diagnostic.
207ab0c68baSAlex Richardson.endif
208ab0c68baSAlex Richardson.endif
209ee4eeb32SBryan DreweryDEPENDOBJS+=	${OBJS}
210ee4eeb32SBryan Drewery.else
211649fed8eSBryan DreweryDEPENDSRCS+=	${SRCS:M*.[cSC]} ${SRCS:M*.cxx} ${SRCS:M*.cpp} ${SRCS:M*.cc}
21249ccbde1SBryan DreweryDEPENDSRCS+=	${DPSRCS:M*.[cSC]} ${DPSRCS:M*.cxx} ${DPSRCS:M*.cpp} ${DPSRCS:M*.cc}
21370ca9ec4SBryan Drewery.if !empty(DEPENDSRCS)
2142506d700SSimon J. GerratyDEPENDOBJS+=	${DEPENDSRCS:${OBJS_SRCS_FILTER:ts:}:S,$,.o,}
21570ca9ec4SBryan Drewery.endif
216ee4eeb32SBryan Drewery.endif	# !empty(OBJS)
2173d04f5a9SBryan Drewery.if !empty(DEPENDOBJS)
218068306e9SBryan DreweryDEPENDFILES+=	${DEPENDOBJS:O:u:${DEPEND_FILTER}:C/^/${DEPENDFILE}./}
2193d04f5a9SBryan Drewery.endif
220210ecc00SBryan Drewery.if defined(_SKIP_DEPEND)
221210ecc00SBryan Drewery# Don't bother statting any .meta files for .depend*
222210ecc00SBryan Drewery${DEPENDOBJS}:	.NOMETA
223210ecc00SBryan Drewery${DEPENDFILE}:	.NOMETA
224210ecc00SBryan Drewery# Unset these to avoid looping/statting on them later.
225210ecc00SBryan Drewery.undef DEPENDSRCS
226210ecc00SBryan Drewery.undef DEPENDOBJS
227068306e9SBryan Drewery.undef DEPENDFILES
228210ecc00SBryan Drewery.endif	# defined(_SKIP_DEPEND)
229b9964333SBryan DreweryDEPEND_CFLAGS+=	-MD ${DEPEND_MP} -MF${DEPENDFILE}.${.TARGET:${DEPEND_FILTER}}
230b9964333SBryan DreweryDEPEND_CFLAGS+=	-MT${.TARGET}
23170ca9ec4SBryan Drewery.if !defined(_meta_filemon)
232c2fd1d01SBryan Drewery.if !empty(DEPEND_CFLAGS)
23310f696a5SBryan Drewery# Only add in DEPEND_CFLAGS for CFLAGS on files we expect from DEPENDOBJS
23410f696a5SBryan Drewery# as those are the only ones we will include.
2357c0c104bSBryan DreweryDEPEND_CFLAGS_CONDITION= "${DEPENDOBJS:${DEPEND_FILTER}:M${.TARGET:${DEPEND_FILTER}}}" != ""
23610f696a5SBryan DreweryCFLAGS+=	${${DEPEND_CFLAGS_CONDITION}:?${DEPEND_CFLAGS}:}
23710f696a5SBryan Drewery.endif
238068306e9SBryan Drewery.for __depend_obj in ${DEPENDFILES}
239e32a2cbeSBryan Drewery.if ${MAKE_VERSION} < 20160220
240e9508dc2SBryan Drewery.sinclude "${.OBJDIR}/${__depend_obj}"
241e32a2cbeSBryan Drewery.else
242e32a2cbeSBryan Drewery.dinclude "${.OBJDIR}/${__depend_obj}"
243e32a2cbeSBryan Drewery.endif
244b9964333SBryan Drewery.endfor
24570ca9ec4SBryan Drewery.endif	# !defined(_meta_filemon)
2462ec8b6deSBruce Evans
24734d39d2cSBryan Drewery.if ${MK_DIRDEPS_BUILD} == "yes" && ${.MAKE.DEPENDFILE} != "/dev/null"
248b9cd412eSBryan Drewery# Prevent meta.autodep.mk from tracking "local dependencies".
249b9cd412eSBryan Drewery.depend:
2507750ad47SMarcel Moolenaar.include <meta.autodep.mk>
25170ca9ec4SBryan Drewery# If using filemon then _EXTRADEPEND is skipped since it is not needed.
252799483e4SBryan Drewery.if defined(_meta_filemon)
2537750ad47SMarcel Moolenaar# this depend: bypasses that below
2547750ad47SMarcel Moolenaar# the dependency helps when bootstrapping
2557750ad47SMarcel Moolenaardepend: beforedepend ${DPSRCS} ${SRCS} afterdepend
2567750ad47SMarcel Moolenaarbeforedepend:
2577750ad47SMarcel Moolenaarafterdepend: beforedepend
2587750ad47SMarcel Moolenaar.endif
25970ca9ec4SBryan Drewery.endif
2607750ad47SMarcel Moolenaar
261d7beff08SBryan Drewery# Guess some dependencies for when no ${DEPENDFILE}.OBJ is generated yet.
26270ca9ec4SBryan Drewery# For meta+filemon the .meta file is checked for since it is the dependency
26370ca9ec4SBryan Drewery# file used.
264d7beff08SBryan Drewery.for __obj in ${DEPENDOBJS:O:u}
2657c0c104bSBryan Drewery# If the obj has any '/', then replace with '_'.  For meta files, this is
2667c0c104bSBryan Drewery# mimicing what bmake's meta_name() does and adding in the full path
2677c0c104bSBryan Drewery# as well to ensure that the expected meta file is read.
2687c0c104bSBryan Drewery.if ${__obj:M*/*}
2692a8176cbSBryan Drewery.if ${MAKE_VERSION} < 20171028
2707c0c104bSBryan Drewery_meta_obj=	${.OBJDIR:C,/,_,g}_${__obj:C,/,_,g}.meta
2717c0c104bSBryan Drewery.else
2722a8176cbSBryan Drewery_meta_obj=	${__obj:C,/,_,g}.meta
2732a8176cbSBryan Drewery.endif	# ${MAKE_VERSION} < 20171028
2742a8176cbSBryan Drewery.else
2757c0c104bSBryan Drewery_meta_obj=	${__obj}.meta
2762a8176cbSBryan Drewery.endif	# ${__obj:M*/*}
2777c0c104bSBryan Drewery_dep_obj=	${DEPENDFILE}.${__obj:${DEPEND_FILTER}}
278711019f7SBryan Drewery.if defined(_meta_filemon)
279711019f7SBryan Drewery_depfile=	${.OBJDIR}/${_meta_obj}
280711019f7SBryan Drewery.else
281711019f7SBryan Drewery_depfile=	${.OBJDIR}/${_dep_obj}
282711019f7SBryan Drewery.endif
283f39f6a56SBryan Drewery.if !exists(${_depfile}) || defined(_meta_filemon)
284f39f6a56SBryan Drewery# - Headers are normally built in beforebuild when included in DPSRCS or SRCS.
285f39f6a56SBryan Drewery#   So we don't need it as a guessed dependency (it may lead to cyclic problems
286f39f6a56SBryan Drewery#   if custom rules are defined).  The only time this causes a problem is when
287f39f6a56SBryan Drewery#   'make foo.o' is ran.
288f39f6a56SBryan Drewery# - For meta mode we still need to know which file to depend on to avoid
2893b828e44SBryan Drewery#   ambiguous suffix transformation rules from .PATH.  Meta mode does not
290f39f6a56SBryan Drewery#   use .depend files when filemon is in use.
29146dea205SBryan Drewery.if !target(${__obj})
29246dea205SBryan Drewery${__obj}: ${OBJS_DEPEND_GUESS}
29346dea205SBryan Drewery.endif
294c155deccSBryan Drewery${__obj}: ${OBJS_DEPEND_GUESS.${__obj}}
295f39f6a56SBryan Drewery.endif	# !exists(${_depfile}) || defined(_meta_filemon)
296d7beff08SBryan Drewery.endfor
297b9cd412eSBryan Drewery
298b9cd412eSBryan Drewery# Always run 'make depend' to generate dependencies early and to avoid the
299b9cd412eSBryan Drewery# need for manually running it.  The dirdeps build should only do this in
300b9cd412eSBryan Drewery# sub-makes though since MAKELEVEL0 is for dirdeps calculations.
301b9cd412eSBryan Drewery.if ${MK_DIRDEPS_BUILD} == "no" || ${.MAKE.LEVEL} > 0
302b9cd412eSBryan Drewerybeforebuild: depend
303d7beff08SBryan Drewery.endif
304d7beff08SBryan Drewery
305d14f862cSGarrett Wollman.if !target(depend)
306d14f862cSGarrett Wollman.if defined(SRCS)
307b25a566dSRuslan Ermilovdepend: beforedepend ${DEPENDFILE} afterdepend
308b16495e7SWolfram Schneider
3097750ad47SMarcel Moolenaar# Tell bmake not to look for generated files via .PATH
310068306e9SBryan Drewery.NOPATH: ${DEPENDFILE} ${DEPENDFILES}
3117750ad47SMarcel Moolenaar
312497e8091SBryan Drewery# A .depend file will only be generated if there are commands in
313799483e4SBryan Drewery# beforedepend/_EXTRADEPEND/afterdepend  The _EXTRADEPEND target is
314799483e4SBryan Drewery# ignored if using meta+filemon since it handles all dependencies.  The other
315799483e4SBryan Drewery# targets are kept as they be used for generating something.  The target is
316799483e4SBryan Drewery# kept to allow 'make depend' to generate files.
317a854949fSBryan Drewery${DEPENDFILE}: ${SRCS} ${DPSRCS}
318210ecc00SBryan Drewery.if !defined(_SKIP_DEPEND)
319987c375fSBryan Drewery.if exists(${.OBJDIR}/${DEPENDFILE}) || \
320799483e4SBryan Drewery    ((commands(beforedepend) || \
321799483e4SBryan Drewery    (!defined(_meta_filemon) && commands(_EXTRADEPEND)) || \
322987c375fSBryan Drewery    commands(afterdepend)) && !empty(.MAKE.MODE:Mmeta))
323b16495e7SWolfram Schneider	rm -f ${DEPENDFILE}
32480f9a973SBryan Drewery.endif
325210ecc00SBryan Drewery.endif
326799483e4SBryan Drewery.if !defined(_meta_filemon) && target(_EXTRADEPEND)
32770e82473SRuslan Ermilov_EXTRADEPEND: .USE
3280cfacc86SRuslan Ermilov${DEPENDFILE}: _EXTRADEPEND
329663e9677SBruce Evans.endif
330b16495e7SWolfram Schneider
33197fe7f47SJordan K. Hubbard.ORDER: ${DEPENDFILE} afterdepend
332d14f862cSGarrett Wollman.else
333b25a566dSRuslan Ermilovdepend: beforedepend afterdepend
334d14f862cSGarrett Wollman.endif
335d14f862cSGarrett Wollman.if !target(beforedepend)
336d14f862cSGarrett Wollmanbeforedepend:
33797fe7f47SJordan K. Hubbard.else
33897fe7f47SJordan K. Hubbard.ORDER: beforedepend ${DEPENDFILE}
33997fe7f47SJordan K. Hubbard.ORDER: beforedepend afterdepend
340d14f862cSGarrett Wollman.endif
341d14f862cSGarrett Wollman.if !target(afterdepend)
342d14f862cSGarrett Wollmanafterdepend:
343d14f862cSGarrett Wollman.endif
344d14f862cSGarrett Wollman.endif
345d14f862cSGarrett Wollman
3463d437ee2SBryan Drewery.if defined(SRCS)
347ae038fc3SBryan Drewery.if ${CTAGS:T} == "gtags"
348ae038fc3SBryan DreweryCLEANDEPENDFILES+=	GPATH GRTAGS GSYMS GTAGS
349ae038fc3SBryan Drewery.if defined(HTML)
350ae038fc3SBryan DreweryCLEANDEPENDDIRS+=	HTML
351ae038fc3SBryan Drewery.endif
352ae038fc3SBryan Drewery.else
353ae038fc3SBryan DreweryCLEANDEPENDFILES+=	tags
354ae038fc3SBryan Drewery.endif
3553d437ee2SBryan Drewery.endif
356cd9a2f5cSJordan K. Hubbard.if !target(cleandepend)
357b25a566dSRuslan Ermilovcleandepend:
3583d437ee2SBryan Drewery.if !empty(CLEANDEPENDFILES)
359ae038fc3SBryan Drewery	rm -f ${CLEANDEPENDFILES}
3603d437ee2SBryan Drewery.endif
361ae038fc3SBryan Drewery.if !empty(CLEANDEPENDDIRS)
362ae038fc3SBryan Drewery	rm -rf ${CLEANDEPENDDIRS}
3636eb5e456SJordan K. Hubbard.endif
364cd9a2f5cSJordan K. Hubbard.endif
365190348aeSBryan Drewery.ORDER: cleandepend all
366190348aeSBryan Drewery.ORDER: cleandepend depend
367b284f322SBryan Drewery.if ${MK_AUTO_OBJ} == "yes"
368b284f322SBryan Drewery.ORDER: cleanobj depend
369b284f322SBryan Drewery.ORDER: cleandir depend
370b284f322SBryan Drewery.endif
3716e02167bSRuslan Ermilov
3726e02167bSRuslan Ermilov.if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
37341ae64f3SEnji Cooper_LDADD_FROM_DPADD=	${DPADD:R:T:C;^lib(.*)$;-l\1;g}
37441ae64f3SEnji Cooper# Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
37541ae64f3SEnji Cooper# LDADD list due to unresolved symbols
37641ae64f3SEnji Cooper_LDADD_CANONICALIZED=	${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
3776e02167bSRuslan Ermilovcheckdpadd:
3782e3c6179SBruce Evans.if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
3792e3c6179SBruce Evans	@echo ${.CURDIR}
3802e3c6179SBruce Evans	@echo "DPADD -> ${_LDADD_FROM_DPADD}"
3812e3c6179SBruce Evans	@echo "LDADD -> ${_LDADD_CANONICALIZED}"
3822e3c6179SBruce Evans.endif
3836e02167bSRuslan Ermilov.endif
384