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.7 2004/11/13 17:31:00 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*.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}
77 SRCS:= ${SRCS:N${_PC}:S|${_PSRC}|${_PC}|}
78 CLEANFILES:= ${CLEANFILES} ${_PC}
83 .for _LSRC in ${SRCS:M*.l:N*/*}
84 .for _LC in ${_LSRC:S/.l/.c/}
86 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
87 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
88 CLEANFILES:= ${CLEANFILES} ${_LC}
92 .for _YSRC in ${SRCS:M*.y:N*/*}
93 .for _YC in ${_YSRC:S/.y/.c/}
94 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
95 CLEANFILES:= ${CLEANFILES} ${_YC}
96 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
97 .ORDER: ${_YC} y.tab.h
98 ${_YC} y.tab.h: ${_YSRC}
99 ${YACC} ${YFLAGS} ${.ALLSRC}
101 SRCS:= ${SRCS} y.tab.h
102 CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h
103 .elif !empty(YFLAGS:M-d)
104 .for _YH in ${_YC:S/.c/.h/}
105 .ORDER: ${_YC} ${_YH}
106 ${_YC} ${_YH}: ${_YSRC}
107 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
108 SRCS:= ${SRCS} ${_YH}
109 CLEANFILES:= ${CLEANFILES} ${_YH}
113 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
121 depend: beforedepend ${DEPENDFILE} afterdepend
123 # Different types of sources are compiled with slightly different flags.
124 # Split up the sources, and filter out headers and non-applicable flags.
125 ${DEPENDFILE}: ${SRCS}
127 .if ${SRCS:M*.[sS]} != ""
128 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
129 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
133 .if ${SRCS:M*.c} != ""
134 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
135 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
138 .if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cpp} != "" || \
140 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
141 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
142 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
144 .if ${SRCS:M*.m} != ""
145 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
146 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \
147 ${OBJCFLAGS:M-Wno-import*} \
150 .if target(_EXTRADEPEND)
152 ${DEPENDFILE}: _EXTRADEPEND
155 .ORDER: ${DEPENDFILE} afterdepend
157 depend: beforedepend afterdepend
159 .if !target(beforedepend)
162 .ORDER: beforedepend ${DEPENDFILE}
163 .ORDER: beforedepend afterdepend
165 .if !target(afterdepend)
170 .if !target(cleandepend)
173 .if ${CTAGS:T} == "ctags"
174 rm -f ${DEPENDFILE} tags
175 .elif ${CTAGS:T} == "gtags"
176 rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
184 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
186 .if ${OBJFORMAT} != aout
187 @ldadd=`echo \`for lib in ${DPADD} ; do \
188 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
190 ldadd1=`echo ${LDADD}` ; \
191 if [ "$$ldadd" != "$$ldadd1" ] ; then \
193 echo "DPADD -> $$ldadd" ; \
194 echo "LDADD -> $$ldadd1" ; \
197 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \
198 if [ "$$dpadd" != "${DPADD}" ] ; then \
200 echo "LDADD -> $$dpadd" ; \
201 echo "DPADD = ${DPADD}" ; \