xref: /freebsd/share/mk/bsd.dep.mk (revision 6e02167b575ec287086e82620752cded7dba3d2c)
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#
853996fadSWolfram Schneider# DEPENDFILE	dependencies file [.depend]
953996fadSWolfram Schneider#
1053996fadSWolfram Schneider# MKDEP		Options for ${MKDEPCMD} [not set]
1153996fadSWolfram Schneider#
1253996fadSWolfram Schneider# MKDEPCMD	Makefile dependency list program [mkdep]
1353996fadSWolfram Schneider#
1453996fadSWolfram Schneider# SRCS          List of source files (c, c++, assembler)
1553996fadSWolfram Schneider#
1653996fadSWolfram Schneider#
1753996fadSWolfram Schneider# +++ targets +++
1853996fadSWolfram Schneider#
1953996fadSWolfram Schneider#	cleandepend:
2053996fadSWolfram Schneider#		Remove depend and tags file
2153996fadSWolfram Schneider#
2253996fadSWolfram Schneider#	depend:
2353996fadSWolfram Schneider#		Make the dependencies for the source files, and store
2453996fadSWolfram Schneider#		them in the file ${DEPENDFILE}.
2553996fadSWolfram Schneider#
2653996fadSWolfram Schneider#	tags:
276eb5e456SJordan K. Hubbard#		Create a (GLOBAL) gtags file for the source files.
286eb5e456SJordan K. Hubbard#		If HTML is defined, htags is also run after gtags.
2953996fadSWolfram Schneider
305ffdf361SRuslan Ermilov.if !target(__<bsd.init.mk>__)
315ffdf361SRuslan Ermilov.error bsd.dep.mk cannot be included directly.
325ffdf361SRuslan Ermilov.endif
33b16495e7SWolfram Schneider
34e16529d3SRuslan Ermilov.if ${CC} != "cc"
35732757a7SBruce EvansMKDEPCMD?=	CC='${CC}' mkdep
36e16529d3SRuslan Ermilov.else
37e16529d3SRuslan ErmilovMKDEPCMD?=	mkdep
38e16529d3SRuslan Ermilov.endif
39b16495e7SWolfram SchneiderDEPENDFILE?=	.depend
40d14f862cSGarrett Wollman
412ec8b6deSBruce Evans.if defined(SRCS)
422ec8b6deSBruce EvansCLEANFILES?=
432ec8b6deSBruce Evans
442ec8b6deSBruce Evans.for _LSRC in ${SRCS:M*.l:N*/*}
452ec8b6deSBruce Evans.for _LC in ${_LSRC:S/.l/.c/}
462ec8b6deSBruce Evans${_LC}: ${_LSRC}
472ec8b6deSBruce Evans	${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
482ec8b6deSBruce EvansSRCS:=	${SRCS:S/${_LSRC}/${_LC}/}
492ec8b6deSBruce EvansCLEANFILES:= ${CLEANFILES} ${_LC}
502ec8b6deSBruce Evans.endfor
512ec8b6deSBruce Evans.endfor
522ec8b6deSBruce Evans
532ec8b6deSBruce Evans.for _YSRC in ${SRCS:M*.y:N*/*}
542ec8b6deSBruce Evans.for _YC in ${_YSRC:S/.y/.c/}
552ec8b6deSBruce EvansSRCS:=	${SRCS:S/${_YSRC}/${_YC}/}
562ec8b6deSBruce EvansCLEANFILES:= ${CLEANFILES} ${_YC}
572ec8b6deSBruce Evans.if ${YFLAGS:M-d} != "" && ${SRCS:My.tab.h}
582ec8b6deSBruce Evans.ORDER: ${_YC} y.tab.h
592ec8b6deSBruce Evans${_YC} y.tab.h: ${_YSRC}
602ec8b6deSBruce Evans	${YACC} ${YFLAGS} ${.ALLSRC}
612ec8b6deSBruce Evans	cp y.tab.c ${_YC}
622ec8b6deSBruce EvansSRCS:=	${SRCS} y.tab.h
632ec8b6deSBruce EvansCLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h
642ec8b6deSBruce Evans.elif ${YFLAGS:M-d} != ""
652ec8b6deSBruce Evans.for _YH in ${_YC:S/.c/.h/}
662ec8b6deSBruce Evans.ORDER: ${_YC} ${_YH}
672ec8b6deSBruce Evans${_YC} ${_YH}: ${_YSRC}
682ec8b6deSBruce Evans	${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
692ec8b6deSBruce EvansSRCS:=	${SRCS} ${_YH}
702ec8b6deSBruce EvansCLEANFILES:= ${CLEANFILES} ${_YH}
712ec8b6deSBruce Evans.endfor
722ec8b6deSBruce Evans.else
732ec8b6deSBruce Evans${_YC}: ${_YSRC}
742ec8b6deSBruce Evans	${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
752ec8b6deSBruce Evans.endif
762ec8b6deSBruce Evans.endfor
772ec8b6deSBruce Evans.endfor
782ec8b6deSBruce Evans.endif
792ec8b6deSBruce Evans
80d14f862cSGarrett Wollman.if !target(depend)
81d14f862cSGarrett Wollman.if defined(SRCS)
82b25a566dSRuslan Ermilovdepend: beforedepend ${DEPENDFILE} afterdepend
83b16495e7SWolfram Schneider
84a813856eSBruce Evans# Different types of sources are compiled with slightly different flags.
85a813856eSBruce Evans# Split up the sources, and filter out headers and non-applicable flags.
8670e82473SRuslan Ermilov${DEPENDFILE}: ${SRCS}
87b16495e7SWolfram Schneider	rm -f ${DEPENDFILE}
88a813856eSBruce Evans.if ${SRCS:M*.[sS]} != ""
89a813856eSBruce Evans	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
90a813856eSBruce Evans	    ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
91a813856eSBruce Evans	    ${AINC} \
92b16495e7SWolfram Schneider	    ${.ALLSRC:M*.[sS]}
93b16495e7SWolfram Schneider.endif
94a813856eSBruce Evans.if ${SRCS:M*.c} != ""
95a813856eSBruce Evans	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
96a813856eSBruce Evans	    ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
97b16495e7SWolfram Schneider	    ${.ALLSRC:M*.c}
98b16495e7SWolfram Schneider.endif
99c7cbe79eSDmitrij Tejblum.if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cpp} != "" || \
100c7cbe79eSDmitrij Tejblum    ${SRCS:M*.cxx} != ""
101b16495e7SWolfram Schneider	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
102a813856eSBruce Evans	    ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
103c7cbe79eSDmitrij Tejblum	    ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
104b16495e7SWolfram Schneider.endif
10570a6e331SBruce Evans.if ${SRCS:M*.m} != ""
10670a6e331SBruce Evans	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
10770a6e331SBruce Evans	    ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \
10870a6e331SBruce Evans	    ${OBJCFLAGS:M-Wno-import*} \
10970a6e331SBruce Evans	    ${.ALLSRC:M*.m}
11070a6e331SBruce Evans.endif
111663e9677SBruce Evans.if target(_EXTRADEPEND)
11270e82473SRuslan Ermilov_EXTRADEPEND: .USE
1130cfacc86SRuslan Ermilov${DEPENDFILE}: _EXTRADEPEND
114663e9677SBruce Evans.endif
115b16495e7SWolfram Schneider
11697fe7f47SJordan K. Hubbard.ORDER: ${DEPENDFILE} afterdepend
117d14f862cSGarrett Wollman.else
118b25a566dSRuslan Ermilovdepend: beforedepend afterdepend
119d14f862cSGarrett Wollman.endif
120d14f862cSGarrett Wollman.if !target(beforedepend)
121d14f862cSGarrett Wollmanbeforedepend:
12297fe7f47SJordan K. Hubbard.else
12397fe7f47SJordan K. Hubbard.ORDER: beforedepend ${DEPENDFILE}
12497fe7f47SJordan K. Hubbard.ORDER: beforedepend afterdepend
125d14f862cSGarrett Wollman.endif
126d14f862cSGarrett Wollman.if !target(afterdepend)
127d14f862cSGarrett Wollmanafterdepend:
128d14f862cSGarrett Wollman.endif
129d14f862cSGarrett Wollman.endif
130d14f862cSGarrett Wollman
1316eb5e456SJordan K. Hubbard.if defined(NOTAGS)
1326eb5e456SJordan K. Hubbardtags:
1336eb5e456SJordan K. Hubbard.endif
1346eb5e456SJordan K. Hubbard
135d14f862cSGarrett Wollman.if !target(tags)
136b25a566dSRuslan Ermilovtags: ${SRCS}
1371ed9b1c3SEivind Eklund	@cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR}
1386eb5e456SJordan K. Hubbard.if defined(HTML)
1391ed9b1c3SEivind Eklund	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
140d14f862cSGarrett Wollman.endif
141d14f862cSGarrett Wollman.endif
142d14f862cSGarrett Wollman
143cd9a2f5cSJordan K. Hubbard.if !target(cleandepend)
144b25a566dSRuslan Ermilovcleandepend:
145662773e2SBruce Evans.if defined(SRCS)
146f9ed7e77SHidetoshi Shimokawa	rm -f ${DEPENDFILE} ${.OBJDIR}/GPATH ${.OBJDIR}/GRTAGS \
147f9ed7e77SHidetoshi Shimokawa		${.OBJDIR}/GSYMS ${.OBJDIR}/GTAGS
1486eb5e456SJordan K. Hubbard.if defined(HTML)
1491ed9b1c3SEivind Eklund	rm -rf ${.OBJDIR}/HTML
1506eb5e456SJordan K. Hubbard.endif
151cd9a2f5cSJordan K. Hubbard.endif
152cd9a2f5cSJordan K. Hubbard.endif
1536e02167bSRuslan Ermilov
1546e02167bSRuslan Ermilov.if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
1556e02167bSRuslan Ermilovcheckdpadd:
1566e02167bSRuslan Ermilov.if ${OBJFORMAT} != aout
1576e02167bSRuslan Ermilov	@ldadd=`echo \`for lib in ${DPADD} ; do \
1586e02167bSRuslan Ermilov		echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
1596e02167bSRuslan Ermilov	done \`` ; \
1606e02167bSRuslan Ermilov	ldadd1=`echo ${LDADD}` ; \
1616e02167bSRuslan Ermilov	if [ "$$ldadd" != "$$ldadd1" ] ; then \
1626e02167bSRuslan Ermilov		echo ${.CURDIR} ; \
1636e02167bSRuslan Ermilov		echo "DPADD -> $$ldadd" ; \
1646e02167bSRuslan Ermilov		echo "LDADD -> $$ldadd1" ; \
1656e02167bSRuslan Ermilov	fi
1666e02167bSRuslan Ermilov.else
1676e02167bSRuslan Ermilov	@dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \
1686e02167bSRuslan Ermilov	if [ "$$dpadd" != "${DPADD}" ] ; then \
1696e02167bSRuslan Ermilov		echo ${.CURDIR} ; \
1706e02167bSRuslan Ermilov		echo "LDADD -> $$dpadd" ; \
1716e02167bSRuslan Ermilov		echo "DPADD =  ${DPADD}" ; \
1726e02167bSRuslan Ermilov	fi
1736e02167bSRuslan Ermilov.endif
1746e02167bSRuslan Ermilov.endif
175