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.9 2006/02/13 13:27:20 corecode 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 _LSRC in ${SRCS:M*.l:N*/*}
71 .for _LC in ${_LSRC:S/.l/.c/}
73 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
74 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
75 CLEANFILES:= ${CLEANFILES} ${_LC}
79 .for _YSRC in ${SRCS:M*.y:N*/*}
80 .for _YC in ${_YSRC:S/.y/.c/}
81 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
82 CLEANFILES:= ${CLEANFILES} ${_YC}
83 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
84 .ORDER: ${_YC} y.tab.h
85 ${_YC} y.tab.h: ${_YSRC}
86 ${YACC} ${YFLAGS} ${.ALLSRC}
88 SRCS:= ${SRCS} y.tab.h
89 CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h
90 .elif !empty(YFLAGS:M-d)
91 .for _YH in ${_YC:S/.c/.h/}
93 ${_YC} ${_YH}: ${_YSRC}
94 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
96 CLEANFILES:= ${CLEANFILES} ${_YH}
100 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
108 depend: beforedepend _dependincs ${DEPENDFILE} afterdepend
110 # Different types of sources are compiled with slightly different flags.
111 # Split up the sources, and filter out headers and non-applicable flags.
112 # Separate flag groups out of the sources and treat them differently.
113 # The special "_" group is for all files not in any group.
115 __FLAGS_FILES= ${SRCS}
116 .for _FG in ${FLAGS_GROUPS}
117 .for _FFILE in ${${_FG}_FLAGS_FILES}
118 __FLAGS_FILES:= ${__FLAGS_FILES:N${_FFILE}}
122 _DEPENDFILES= ${FLAGS_GROUPS:S/^/.depend_/g}
123 .ORDER: ${_DEPENDFILES}
125 ${DEPENDFILE}: ${_DEPENDFILES}
128 # __FLAG_FILES is built from SRCS. That means it will contain
129 # also .h files and other files that are not direct sources, but which
130 # might be required to even run mkdep. This is important if those are
131 # generated as well, like some forwarding headers.
133 # We'll have to pass these "sources" on to the other .depend_ file targets,
134 # since otherwise they might be run before the generated sources are
135 # generated. _ALL_DEPENDS captures all files in SRCS that are not handled
136 # by the mkdep calls, i.e. all sources that are not being used directly
137 # for the .depend* file.
139 _ALL_DEPENDS=${__FLAGS_FILES:N*.[sS]:N*.c:N*.cc:N*.C:N*.cpp:N*.cpp:N*.cxx:N*.m}
141 .for _FG in _ ${FLAGS_GROUPS}
142 .depend${_FG:S/^/_/:N__}: ${${_FG}_FLAGS_FILES} ${_ALL_DEPENDS}
145 .if ${${_FG}_FLAGS_FILES:M*.[sS]} != ""
146 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
148 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
152 .if ${${_FG}_FLAGS_FILES:M*.c} != ""
153 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
155 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
159 .if ${${_FG}_FLAGS_FILES:M*.cc} != "" || \
160 ${${_FG}_FLAGS_FILES:M*.C} != "" || \
161 ${${_FG}_FLAGS_FILES:M*.cpp} != "" || \
162 ${${_FG}_FLAGS_FILES:M*.cxx} != ""
163 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
165 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
166 ${CXXFLAGS:M-std=*} \
167 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
169 .if ${${_FG}_FLAGS_FILES:M*.m} != ""
170 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
172 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \
173 ${OBJCFLAGS:M-Wno-import*} \
176 .if !empty(${_FG:M_}) && !empty(_DEPENDFILES)
177 cat ${_DEPENDFILES} >> ${.TARGET}
181 .if target(_EXTRADEPEND)
183 ${DEPENDFILE}: _EXTRADEPEND
186 .ORDER: ${_DEPENDFILES} ${DEPENDFILE} afterdepend
188 depend: beforedepend _dependincs afterdepend
190 .if !target(beforedepend)
193 .ORDER: beforedepend ${_DEPENDFILES} ${DEPENDFILE}
194 .ORDER: beforedepend afterdepend
196 .if !target(afterdepend)
201 .if !target(cleandepend)
204 .if ${CTAGS:T} == "ctags"
205 rm -f ${DEPENDFILE} ${_DEPENDFILES} tags
206 .elif ${CTAGS:T} == "gtags"
207 rm -f ${DEPENDFILE} ${_DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
215 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
217 .if ${OBJFORMAT} != aout
218 @ldadd=`echo \`for lib in ${DPADD} ; do \
219 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
221 ldadd1=`echo ${LDADD}` ; \
222 if [ "$$ldadd" != "$$ldadd1" ] ; then \
224 echo "DPADD -> $$ldadd" ; \
225 echo "LDADD -> $$ldadd1" ; \
228 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \
229 if [ "$$dpadd" != "${DPADD}" ] ; then \
231 echo "LDADD -> $$dpadd" ; \
232 echo "DPADD = ${DPADD}" ; \
237 .if defined(INCS) && make(depend)
239 _dependincs: ${INCS} ${SRCS}
241 .ORDER: _dependincs depend