1 # $FreeBSD: src/share/mk/bsd.dep.mk,v 1.27.2.3 2002/12/23 16:33:37 ru Exp $
2 # $DragonFly: src/share/mk/bsd.dep.mk,v 1.8 2005/09/01 14:17:58 joerg Exp $
4 # The include file <bsd.dep.mk> handles Makefile dependencies.
9 # CTAGS A tags file generation program [gtags]
11 # CTAGSFLAGS Options for ctags(1) [not set]
13 # DEPENDFILE dependencies file [.depend]
15 # GTAGSFLAGS Options for gtags(1) [-o]
17 # HTAGSFLAGS Options for htags(1) [not set]
19 # MKDEP Options for ${MKDEPCMD} [not set]
21 # MKDEPCMD Makefile dependency list program [mkdep]
23 # SRCS List of source files (c, c++, assembler)
29 # Remove depend and tags file
32 # Make the dependencies for the source files, and store
33 # them in the file ${DEPENDFILE}.
36 # In "ctags" mode, create a tags file for the source files.
37 # In "gtags" mode, create a (GLOBAL) gtags file for the
38 # source files. If HTML is defined, htags(1) is also run
41 .if !target(__<bsd.init.mk>__)
42 .error bsd.dep.mk cannot be included directly.
53 # Keep `tags' here, before SRCS are mangled below for `depend'.
54 .if !target(tags) && defined(SRCS) && !defined(NOTAGS)
56 .if ${CTAGS:T} == "ctags"
57 @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
58 ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
59 .elif ${CTAGS:T} == "gtags"
60 @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
62 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
70 .for _PSRC in ${SRCS:M*.no_obj.patch}
71 .for _PC in ${_PSRC:T:C/(\.no_obj)?\.patch$//:S|,|/|g}
73 ${_PC}: ${CONTRIBDIR}/${_PC} ${_PSRC}
75 patch -o ${.TARGET} -i ${.ALLSRC:M*.patch} ${CONTRIBDIR}/${.TARGET}
79 CLEANFILES:= ${CLEANFILES} ${_PC}
83 .for _PSRC in ${SRCS:N*.no_obj.patch:M*.patch}
84 .for _PC in ${_PSRC:T:C/(\.no_obj)?\.patch$//:S|,|/|g}
86 ${_PC}: ${CONTRIBDIR}/${_PC} ${_PSRC}
88 patch -o ${.TARGET} -i ${.ALLSRC:M*.patch} ${CONTRIBDIR}/${.TARGET}
90 SRCS:= ${SRCS:N${_PC}:S|${_PSRC}|${_PC}|}
91 CLEANFILES:= ${CLEANFILES} ${_PC}
96 .for _LSRC in ${SRCS:M*.l:N*/*}
97 .for _LC in ${_LSRC:S/.l/.c/}
99 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
100 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
101 CLEANFILES:= ${CLEANFILES} ${_LC}
105 .for _YSRC in ${SRCS:M*.y:N*/*}
106 .for _YC in ${_YSRC:S/.y/.c/}
107 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
108 CLEANFILES:= ${CLEANFILES} ${_YC}
109 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
110 .ORDER: ${_YC} y.tab.h
111 ${_YC} y.tab.h: ${_YSRC}
112 ${YACC} ${YFLAGS} ${.ALLSRC}
114 SRCS:= ${SRCS} y.tab.h
115 CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h
116 .elif !empty(YFLAGS:M-d)
117 .for _YH in ${_YC:S/.c/.h/}
118 .ORDER: ${_YC} ${_YH}
119 ${_YC} ${_YH}: ${_YSRC}
120 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
121 SRCS:= ${SRCS} ${_YH}
122 CLEANFILES:= ${CLEANFILES} ${_YH}
126 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
134 depend: beforedepend ${DEPENDFILE} afterdepend
136 # Different types of sources are compiled with slightly different flags.
137 # Split up the sources, and filter out headers and non-applicable flags.
138 ${DEPENDFILE}: ${SRCS}
140 .if ${SRCS:M*.[sS]} != ""
141 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
142 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
146 .if ${SRCS:M*.c} != ""
147 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
148 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
151 .if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cpp} != "" || \
153 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
154 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
155 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
157 .if ${SRCS:M*.m} != ""
158 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
159 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \
160 ${OBJCFLAGS:M-Wno-import*} \
163 .if target(_EXTRADEPEND)
165 ${DEPENDFILE}: _EXTRADEPEND
168 .ORDER: ${DEPENDFILE} afterdepend
170 depend: beforedepend afterdepend
172 .if !target(beforedepend)
175 .ORDER: beforedepend ${DEPENDFILE}
176 .ORDER: beforedepend afterdepend
178 .if !target(afterdepend)
183 .if !target(cleandepend)
186 .if ${CTAGS:T} == "ctags"
187 rm -f ${DEPENDFILE} tags
188 .elif ${CTAGS:T} == "gtags"
189 rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
197 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
199 .if ${OBJFORMAT} != aout
200 @ldadd=`echo \`for lib in ${DPADD} ; do \
201 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
203 ldadd1=`echo ${LDADD}` ; \
204 if [ "$$ldadd" != "$$ldadd1" ] ; then \
206 echo "DPADD -> $$ldadd" ; \
207 echo "LDADD -> $$ldadd1" ; \
210 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \
211 if [ "$$dpadd" != "${DPADD}" ] ; then \
213 echo "LDADD -> $$dpadd" ; \
214 echo "DPADD = ${DPADD}" ; \