1 # $FreeBSD: src/share/mk/bsd.dep.mk,v 1.27.2.3 2002/12/23 16:33:37 ru Exp $
3 # The include file <bsd.dep.mk> handles Makefile dependencies.
8 # CTAGS A tags file generation program [gtags]
10 # CTAGSFLAGS Options for ctags(1) [not set]
12 # DEPENDFILE dependencies file [.depend]
14 # GTAGSFLAGS Options for gtags(1) [-o]
16 # HTAGSFLAGS Options for htags(1) [not set]
18 # MKDEP Options for ${MKDEPCMD} [not set]
20 # MKDEPCC CC to be used in ${MKDEPCMD} script [cc]
22 # MKDEPCMD Makefile dependency list program [mkdep]
24 # MKDEPINTDEPS Extra internal dependencies for intermediates [not set]
26 # SRCS List of source files (c, c++, assembler)
32 # Remove depend and tags file
35 # Make the dependencies for the source files, and store
36 # them in the file ${DEPENDFILE}.
39 # In "ctags" mode, create a tags file for the source files.
40 # In "gtags" mode, create a (GLOBAL) gtags file for the
41 # source files. If HTML is defined, htags(1) is also run
44 .if !target(__<bsd.init.mk>__)
45 .error bsd.dep.mk cannot be included directly.
57 # Support better dependencies tracking for both host cc and target cc.
58 .if defined(__USE_HOST_CCVER)
59 _MKDEPENV= ${NXENV:NPATH=*}
61 _MKDEPENV= CCVER=${CCVER}
64 # Keep `tags' here, before SRCS are mangled below for `depend'.
65 .if !target(tags) && defined(SRCS) && !defined(NOTAGS)
67 .if ${CTAGS:T} == "ctags"
68 @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
69 ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
70 .elif ${CTAGS:T} == "gtags"
71 @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
73 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
81 .for _LSRC in ${SRCS:M*.l:N*/*}
82 .for _LC in ${_LSRC:R}.c
84 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
85 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
90 .for _YSRC in ${SRCS:M*.y:N*/*}
91 .for _YC in ${_YSRC:R}.c
92 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
94 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
95 .ORDER: ${_YC} y.tab.h
96 ${_YC} y.tab.h: ${_YSRC}
97 ${YACC} ${YFLAGS} ${.ALLSRC}
99 CLEANFILES+= y.tab.c y.tab.h
100 .elif !empty(YFLAGS:M-d)
101 .for _YH in ${_YC:S/.c/.h/}
104 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
110 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
118 depend: beforedepend _dependincs ${DEPENDFILE} afterdepend
120 # Tell bmake not to look for generated files via .PATH
121 .NOPATH: ${DEPENDFILE}
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 # Separate flag groups out of the sources and treat them differently.
126 # The special "_" group is for all files not in any group.
128 __FLAGS_FILES= ${SRCS}
129 .for _FG in ${FLAGS_GROUPS}
130 .for _FFILE in ${${_FG}_FLAGS_FILES}
131 __FLAGS_FILES:= ${__FLAGS_FILES:N${_FFILE}}
135 _DEPENDFILES= ${FLAGS_GROUPS:S/^/.depend_/g}
137 ${DEPENDFILE}: ${_DEPENDFILES}
140 # __FLAG_FILES is built from SRCS. That means it will contain
141 # also .h files and other files that are not direct sources, but which
142 # might be required to even run mkdep. This is important if those are
143 # generated as well, like some forwarding headers.
145 # We'll have to pass these "sources" on to the other .depend_ file targets,
146 # since otherwise they might be run before the generated sources are
147 # generated. _ALL_DEPENDS captures all files in SRCS that are not handled
148 # by the mkdep calls, i.e. all sources that are not being used directly
149 # for the .depend* file.
151 _ALL_DEPENDS=${__FLAGS_FILES:N*.[sS]:N*.c:N*.cc:N*.C:N*.cpp:N*.cpp:N*.cxx:N*.m}
153 .for _FG in _ ${FLAGS_GROUPS}
154 .depend${_FG:S/^/_/:N__}: ${${_FG}_FLAGS_FILES} ${_ALL_DEPENDS}
157 .if ${${_FG}_FLAGS_FILES:M*.[csS]} != ""
158 ${_MKDEPENV} CC=${MKDEPCC} ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
160 ${CFLAGS:M--sysroot=*} \
161 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
165 .if ${${_FG}_FLAGS_FILES:M*.cc} != "" || \
166 ${${_FG}_FLAGS_FILES:M*.C} != "" || \
167 ${${_FG}_FLAGS_FILES:M*.cpp} != "" || \
168 ${${_FG}_FLAGS_FILES:M*.cxx} != ""
169 ${_MKDEPENV} CC=${CXX} ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
171 ${CXXFLAGS:M--sysroot=*} \
172 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
173 ${CXXFLAGS:M-std=*} \
174 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
176 .if ${${_FG}_FLAGS_FILES:M*.m} != ""
177 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
179 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \
180 ${OBJCFLAGS:M-Wno-import*} \
183 .if !empty(${_FG:M_}) && !empty(_DEPENDFILES)
184 cat ${_DEPENDFILES} >> ${.TARGET}
186 .if defined(MKDEPINTDEPS) && !empty(MKDEPINTDEPS)
187 . for _ITD in ${MKDEPINTDEPS:O:u}
189 sed -e "s,${_ITD:C/^(.*:)(.*)/\1,\2 \1/},g" < ${.TARGET} > $$TMP; \
195 .if target(_EXTRADEPEND)
197 ${DEPENDFILE}: _EXTRADEPEND
201 depend: beforedepend _dependincs afterdepend
203 .if !target(beforedepend)
206 .if !target(afterdepend)
211 .if !target(cleandepend)
214 .if ${CTAGS:T} == "ctags"
215 rm -f ${DEPENDFILE} ${_DEPENDFILES} tags
216 .elif ${CTAGS:T} == "gtags"
217 rm -f ${DEPENDFILE} ${_DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
225 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
227 .if ${OBJFORMAT} != aout
228 @ldadd=`echo \`for lib in ${DPADD} ; do \
229 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
231 ldadd1=`echo ${LDADD}` ; \
232 if [ "$$ldadd" != "$$ldadd1" ] ; then \
234 echo "DPADD -> $$ldadd" ; \
235 echo "LDADD -> $$ldadd1" ; \
238 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \
239 if [ "$$dpadd" != "${DPADD}" ] ; then \
241 echo "LDADD -> $$dpadd" ; \
242 echo "DPADD = ${DPADD}" ; \
247 .if defined(INCS) && make(depend)
248 _dependincs: buildincludes .WAIT installincludes
253 .ORDER: beforedepend _dependincs ${DEPENDFILE} afterdepend