3 # The include file <bsd.dep.mk> handles Makefile dependencies.
8 # CLEANDEPENDDIRS Additional directories to remove for the cleandepend
11 # CLEANDEPENDFILES Additional files to remove for the cleandepend target.
13 # CTAGS A tags file generation program [gtags]
15 # CTAGSFLAGS Options for ctags(1) [not set]
17 # DEPENDFILE dependencies file [.depend]
19 # GTAGSFLAGS Options for gtags(1) [-o]
21 # HTAGSFLAGS Options for htags(1) [not set]
23 # SRCS List of source files (c, c++, assembler)
25 # DPSRCS List of source files which are needed for generating
26 # dependencies, ${SRCS} are always part of it.
31 # remove ${CLEANDEPENDFILES}; remove ${CLEANDEPENDDIRS} and all
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.
53 .if ${MK_DIRDEPS_BUILD} == "no"
54 .MAKE.DEPENDFILE= ${DEPENDFILE}
56 CLEANDEPENDFILES+= ${DEPENDFILE} ${DEPENDFILE}.*
57 .if ${MK_META_MODE} == "yes"
58 CLEANDEPENDFILES+= *.meta
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}
75 # Skip reading .depend when not needed to speed up tree-walks
77 .if !empty(.MAKEFLAGS:M-V${_V_READ_DEPEND}) || make(obj) || make(clean*) || \
78 make(install*) || make(analyze)
80 .if ${MK_DIRDEPS_BUILD} == "no"
81 .MAKE.DEPENDFILE= /dev/null
88 .for _S in ${SRCS:N*.[dhly]}
89 OBJS_DEPEND_GUESS.${_S:R}.o+= ${_S}
93 .for _LSRC in ${SRCS:M*.l:N*/*}
94 .for _LC in ${_LSRC:R}.c
96 ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
97 OBJS_DEPEND_GUESS.${_LC:R}.o+= ${_LC}
98 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
104 .for _YSRC in ${SRCS:M*.y:N*/*}
105 .for _YC in ${_YSRC:R}.c
106 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
108 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
109 .ORDER: ${_YC} y.tab.h
111 ${_YC} y.tab.h: ${_YSRC}
112 ${YACC} ${YFLAGS} ${.ALLSRC}
114 CLEANFILES+= y.tab.c y.tab.h
115 .elif !empty(YFLAGS:M-d)
116 .for _YH in ${_YC:R}.h
117 .ORDER: ${_YC} ${_YH}
119 ${_YC} ${_YH}: ${_YSRC}
120 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
126 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
128 OBJS_DEPEND_GUESS.${_YC:R}.o+= ${_YC}
132 # DTrace probe definitions
134 CFLAGS+= -I${.OBJDIR}
136 .for _DSRC in ${SRCS:M*.d:N*/*}
137 .for _D in ${_DSRC:R}
140 ${DTRACE} ${DTRACEFLAGS} -h -s ${.ALLSRC}
141 SRCS:= ${SRCS:S/^${_DSRC}$//}
143 CLEANFILES+= ${_D}.h ${_D}.o
144 ${_D}.o: ${_DSRC} ${OBJS:S/^${_D}.o$//}
146 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
148 CLEANFILES+= ${_D}.So ${_D}.po
149 ${_D}.So: ${_DSRC} ${SOBJS:S/^${_D}.So$//}
151 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
152 ${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
154 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
160 .if !empty(.MAKE.MODE:Mmeta) && empty(.MAKE.MODE:Mnofilemon)
163 .if ${MAKE_VERSION} < 20160220
166 # Handle OBJS=../somefile.o hacks. Just replace '/' rather than use :T to
168 DEPEND_FILTER= C,/,_,g
169 DEPENDSRCS= ${SRCS:M*.[cSC]} ${SRCS:M*.cxx} ${SRCS:M*.cpp} ${SRCS:M*.cc}
170 .if !empty(DEPENDSRCS)
171 DEPENDOBJS+= ${DEPENDSRCS:R:S,$,.o,}
173 DEPENDFILES_OBJS= ${DEPENDOBJS:O:u:${DEPEND_FILTER}:C/^/${DEPENDFILE}./}
174 DEPEND_CFLAGS+= -MD ${DEPEND_MP} -MF${DEPENDFILE}.${.TARGET:${DEPEND_FILTER}}
175 DEPEND_CFLAGS+= -MT${.TARGET}
176 # Skip generating or including .depend.* files if in meta+filemon mode since
177 # it will track dependencies itself. OBJS_DEPEND_GUESS is still used though.
178 .if !defined(_meta_filemon)
179 .if defined(.PARSEDIR)
180 # Only add in DEPEND_CFLAGS for CFLAGS on files we expect from DEPENDOBJS
181 # as those are the only ones we will include.
182 DEPEND_CFLAGS_CONDITION= "${DEPENDOBJS:M${.TARGET:${DEPEND_FILTER}}}" != ""
183 CFLAGS+= ${${DEPEND_CFLAGS_CONDITION}:?${DEPEND_CFLAGS}:}
185 CFLAGS+= ${DEPEND_CFLAGS}
187 .if !defined(_SKIP_READ_DEPEND)
188 .for __depend_obj in ${DEPENDFILES_OBJS}
189 .if ${MAKE_VERSION} < 20160220
190 .sinclude "${.OBJDIR}/${__depend_obj}"
192 .dinclude "${.OBJDIR}/${__depend_obj}"
195 .endif # !defined(_SKIP_READ_DEPEND)
196 .endif # !defined(_meta_filemon)
197 .endif # defined(SRCS)
199 .if ${MK_DIRDEPS_BUILD} == "yes"
200 # Prevent meta.autodep.mk from tracking "local dependencies".
202 .include <meta.autodep.mk>
203 # If using filemon then _EXTRADEPEND is skipped since it is not needed.
204 .if empty(.MAKE.MODE:Mnofilemon)
205 # this depend: bypasses that below
206 # the dependency helps when bootstrapping
207 depend: beforedepend ${DPSRCS} ${SRCS} afterdepend
209 afterdepend: beforedepend
213 # Guess some dependencies for when no ${DEPENDFILE}.OBJ is generated yet.
214 # For meta+filemon the .meta file is checked for since it is the dependency
216 .for __obj in ${DEPENDOBJS:O:u}
217 .if (defined(_meta_filemon) && !exists(${.OBJDIR}/${__obj}.meta)) || \
218 (!defined(_meta_filemon) && !exists(${.OBJDIR}/${DEPENDFILE}.${__obj}))
219 ${__obj}: ${OBJS_DEPEND_GUESS}
220 ${__obj}: ${OBJS_DEPEND_GUESS.${__obj}}
221 .elif defined(_meta_filemon)
222 # For meta mode we still need to know which file to depend on to avoid
223 # ambiguous suffix transformation rules from .PATH. Meta mode does not
224 # use .depend files. We really only need source files, not headers.
225 ${__obj}: ${OBJS_DEPEND_GUESS:N*.h}
226 ${__obj}: ${OBJS_DEPEND_GUESS.${__obj}:N*.h}
230 # Always run 'make depend' to generate dependencies early and to avoid the
231 # need for manually running it. The dirdeps build should only do this in
232 # sub-makes though since MAKELEVEL0 is for dirdeps calculations.
233 .if ${MK_DIRDEPS_BUILD} == "no" || ${.MAKE.LEVEL} > 0
239 depend: beforedepend ${DEPENDFILE} afterdepend
241 # Tell bmake not to look for generated files via .PATH
242 .NOPATH: ${DEPENDFILE} ${DEPENDFILES_OBJS}
245 # A .depend file will only be generated if there are commands in
246 # beforedepend/_EXTRADEPEND/afterdepend. The target is kept
247 # to allow 'make depend' to generate files.
248 ${DEPENDFILE}: ${DPSRCS}
249 .if exists(${.OBJDIR}/${DEPENDFILE}) || \
250 ((commands(beforedepend) || commands(_EXTRADEPEND) || \
251 commands(afterdepend)) && !empty(.MAKE.MODE:Mmeta))
254 .if target(_EXTRADEPEND)
256 ${DEPENDFILE}: _EXTRADEPEND
259 .ORDER: ${DEPENDFILE} afterdepend
261 depend: beforedepend afterdepend
263 .if !target(beforedepend)
266 .ORDER: beforedepend ${DEPENDFILE}
267 .ORDER: beforedepend afterdepend
269 .if !target(afterdepend)
275 .if ${CTAGS:T} == "gtags"
276 CLEANDEPENDFILES+= GPATH GRTAGS GSYMS GTAGS
278 CLEANDEPENDDIRS+= HTML
281 CLEANDEPENDFILES+= tags
284 .if !target(cleandepend)
286 .if !empty(CLEANDEPENDFILES)
287 rm -f ${CLEANDEPENDFILES}
289 .if !empty(CLEANDEPENDDIRS)
290 rm -rf ${CLEANDEPENDDIRS}
294 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
295 _LDADD_FROM_DPADD= ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
296 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
297 # LDADD list due to unresolved symbols
298 _LDADD_CANONICALIZED= ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
300 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
302 @echo "DPADD -> ${_LDADD_FROM_DPADD}"
303 @echo "LDADD -> ${_LDADD_CANONICALIZED}"