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}
61 # Keep `tags' here, before SRCS are mangled below for `depend'.
62 .if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
64 .if ${CTAGS:T} == "gtags"
65 @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
67 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
70 @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
71 ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
78 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
79 .for _S in ${SRCS:N*.[dhly]}
85 .for _LSRC in ${SRCS:M*.l:N*/*}
86 .for _LC in ${_LSRC:R}.c
88 ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
89 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
92 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
98 .for _YSRC in ${SRCS:M*.y:N*/*}
99 .for _YC in ${_YSRC:R}.c
100 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
102 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
103 .ORDER: ${_YC} y.tab.h
104 ${_YC} y.tab.h: ${_YSRC}
105 ${YACC} ${YFLAGS} ${.ALLSRC}
107 CLEANFILES+= y.tab.c y.tab.h
108 .elif !empty(YFLAGS:M-d)
109 .for _YH in ${_YC:R}.h
112 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
118 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
120 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
126 # DTrace probe definitions
128 CFLAGS+= -I${.OBJDIR}
130 .for _DSRC in ${SRCS:M*.d:N*/*}
131 .for _D in ${_DSRC:R}
134 ${DTRACE} ${DTRACEFLAGS} -h -s ${.ALLSRC}
135 SRCS:= ${SRCS:S/^${_DSRC}$//}
137 CLEANFILES+= ${_D}.h ${_D}.o
138 ${_D}.o: ${_DSRC} ${OBJS:S/^${_D}.o$//}
139 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
141 CLEANFILES+= ${_D}.So ${_D}.po
142 ${_D}.So: ${_DSRC} ${SOBJS:S/^${_D}.So$//}
143 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
144 ${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
145 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
149 beforedepend: ${DHDRS}
150 beforebuild: ${DHDRS}
153 .if ${MK_FAST_DEPEND} == "yes" && ${.MAKE.MODE:Unormal:Mmeta*} == ""
154 DEPENDFILES+= ${DEPENDFILE}.*
156 # Handle OBJS=../somefile.o hacks. Just replace '/' rather than use :T to
158 DEPEND_FILTER= C,/,_,g
159 DEPEND_CFLAGS+= -MD ${DEPEND_MP} -MF${DEPENDFILE}.${.TARGET:${DEPEND_FILTER}}
160 DEPEND_CFLAGS+= -MT${.TARGET}
161 CFLAGS+= ${DEPEND_CFLAGS}
162 DEPENDSRCS= ${SRCS:M*.[cSC]} ${SRCS:M*.cxx} ${SRCS:M*.cpp} ${SRCS:M*.cc}
163 .if !empty(DEPENDSRCS)
164 DEPENDOBJS+= ${DEPENDSRCS:R:S,$,.o,}
166 .for __obj in ${DEPENDOBJS:O:u}
167 .if ${.MAKEFLAGS:M-V} == ""
168 .sinclude "${DEPENDFILE}.${__obj:${DEPEND_FILTER}}"
170 DEPENDFILES_OBJS+= ${DEPENDFILE}.${__obj:${DEPEND_FILTER}}
172 .endif # ${MK_FAST_DEPEND} == "yes"
173 .endif # defined(SRCS)
175 .if ${MK_DIRDEPS_BUILD} == "yes"
176 .include <meta.autodep.mk>
177 # this depend: bypasses that below
178 # the dependency helps when bootstrapping
179 depend: beforedepend ${DPSRCS} ${SRCS} afterdepend
181 afterdepend: beforedepend
186 depend: beforedepend ${DEPENDFILE} afterdepend
188 # Tell bmake not to look for generated files via .PATH
189 .NOPATH: ${DEPENDFILE} ${DEPENDFILES_OBJS}
191 # Different types of sources are compiled with slightly different flags.
192 # Split up the sources, and filter out headers and non-applicable flags.
193 MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
195 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
196 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*}
199 ${DEPENDFILE}: ${DPSRCS}
200 .if ${MK_FAST_DEPEND} == "no"
202 .if !empty(DPSRCS:M*.[cS])
203 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
204 ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
206 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
207 !empty(DPSRCS:M*.cxx)
208 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
210 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
215 .endif # ${MK_FAST_DEPEND} == "no"
216 .if target(_EXTRADEPEND)
218 ${DEPENDFILE}: _EXTRADEPEND
221 .ORDER: ${DEPENDFILE} afterdepend
223 depend: beforedepend afterdepend
225 .if !target(beforedepend)
228 .ORDER: beforedepend ${DEPENDFILE}
229 .ORDER: beforedepend afterdepend
231 .if !target(afterdepend)
236 .if !target(cleandepend)
239 .if ${CTAGS:T} == "gtags"
240 rm -f ${DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
245 rm -f ${DEPENDFILES} tags
250 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
251 _LDADD_FROM_DPADD= ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
252 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
253 # LDADD list due to unresolved symbols
254 _LDADD_CANONICALIZED= ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
256 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
258 @echo "DPADD -> ${_LDADD_FROM_DPADD}"
259 @echo "LDADD -> ${_LDADD_CANONICALIZED}"