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 # MKDEPCMD Makefile dependency list program [mkdep]
22 # SRCS List of source files (c, c++, assembler)
24 # DPSRCS List of source files which are needed for generating
25 # dependencies, ${SRCS} are always part of it.
30 # Remove depend and tags file
33 # Make the dependencies for the source files, and store
34 # them in the file ${DEPENDFILE}.
37 # In "ctags" mode, create a tags file for the source files.
38 # In "gtags" mode, create a (GLOBAL) gtags file for the
39 # source files. If HTML is defined, htags(1) is also run
42 .if !target(__<bsd.init.mk>__)
43 .error bsd.dep.mk cannot be included directly.
51 _MKDEPCC:= ${CC:N${CCACHE_BIN}}
52 # XXX: DEPFLAGS can come out once Makefile.inc1 properly passes down
55 _MKDEPCC+= ${DEPFLAGS}
57 MKDEPCMD?= CC='${_MKDEPCC}' mkdep
59 DEPENDFILES= ${DEPENDFILE}
60 .if ${MK_FAST_DEPEND} == "yes" && ${.MAKE.MODE:Unormal:Mmeta*} == ""
61 DEPENDFILES+= ${DEPENDFILE}.*
62 DEPEND_CFLAGS+= -MD -MP -MF${DEPENDFILE}.${.TARGET}
63 DEPEND_CFLAGS+= -MT${.TARGET}
64 CFLAGS+= ${DEPEND_CFLAGS}
65 DEPENDOBJS+= ${OBJS} ${POBJS} ${SOBJS}
66 .for __obj in ${DEPENDOBJS:O:u}
67 .if ${.MAKEFLAGS:M-V} == ""
68 .sinclude "${DEPENDFILE}.${__obj}"
70 DEPENDFILES_OBJS+= ${DEPENDFILE}.${__obj}
72 .endif # ${MK_FAST_DEPEND} == "yes"
74 # Keep `tags' here, before SRCS are mangled below for `depend'.
75 .if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
77 .if ${CTAGS:T} == "gtags"
78 @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
80 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
83 @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
84 ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
91 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
92 .for _S in ${SRCS:N*.[dhly]}
98 .for _LSRC in ${SRCS:M*.l:N*/*}
99 .for _LC in ${_LSRC:R}.c
101 ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
102 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
105 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
111 .for _YSRC in ${SRCS:M*.y:N*/*}
112 .for _YC in ${_YSRC:R}.c
113 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
115 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
116 .ORDER: ${_YC} y.tab.h
117 ${_YC} y.tab.h: ${_YSRC}
118 ${YACC} ${YFLAGS} ${.ALLSRC}
120 CLEANFILES+= y.tab.c y.tab.h
121 .elif !empty(YFLAGS:M-d)
122 .for _YH in ${_YC:R}.h
125 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
131 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
133 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
139 # DTrace probe definitions
141 CFLAGS+= -I${.OBJDIR}
143 .for _DSRC in ${SRCS:M*.d:N*/*}
144 .for _D in ${_DSRC:R}
147 ${DTRACE} ${DTRACEFLAGS} -h -s ${.ALLSRC}
148 SRCS:= ${SRCS:S/^${_DSRC}$//}
150 CLEANFILES+= ${_D}.h ${_D}.o
151 ${_D}.o: ${_DSRC} ${OBJS:S/^${_D}.o$//}
152 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
154 CLEANFILES+= ${_D}.So ${_D}.po
155 ${_D}.So: ${_DSRC} ${SOBJS:S/^${_D}.So$//}
156 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
157 ${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
158 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
162 beforedepend: ${DHDRS}
163 beforebuild: ${DHDRS}
166 .if ${MK_DIRDEPS_BUILD} == "yes"
167 .include <meta.autodep.mk>
168 # this depend: bypasses that below
169 # the dependency helps when bootstrapping
170 depend: beforedepend ${DPSRCS} ${SRCS} afterdepend
172 afterdepend: beforedepend
177 depend: beforedepend ${DEPENDFILE} afterdepend
179 # Tell bmake not to look for generated files via .PATH
180 .NOPATH: ${DEPENDFILE} ${DEPENDFILES_OBJS}
182 # Different types of sources are compiled with slightly different flags.
183 # Split up the sources, and filter out headers and non-applicable flags.
184 MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
186 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
187 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*}
190 ${DEPENDFILE}: ${DPSRCS}
191 .if ${MK_FAST_DEPEND} == "no"
193 .if !empty(DPSRCS:M*.[cS])
194 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
195 ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
197 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
198 !empty(DPSRCS:M*.cxx)
199 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
201 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
206 .endif # ${MK_FAST_DEPEND} == "no"
207 .if target(_EXTRADEPEND)
209 ${DEPENDFILE}: _EXTRADEPEND
212 .ORDER: ${DEPENDFILE} afterdepend
214 depend: beforedepend afterdepend
216 .if !target(beforedepend)
219 .ORDER: beforedepend ${DEPENDFILE}
220 .ORDER: beforedepend afterdepend
222 .if !target(afterdepend)
227 .if !target(cleandepend)
230 .if ${CTAGS:T} == "gtags"
231 rm -f ${DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
236 rm -f ${DEPENDFILES} tags
241 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
242 _LDADD_FROM_DPADD= ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
243 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
244 # LDADD list due to unresolved symbols
245 _LDADD_CANONICALIZED= ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
247 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
249 @echo "DPADD -> ${_LDADD_FROM_DPADD}"
250 @echo "LDADD -> ${_LDADD_CANONICALIZED}"