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 .if !empty(.MAKE.MODE:Mmeta) && empty(.MAKE.MODE:Mnofilemon)
78 # By default META_MODE is disabled in bmake if there is no OBJDIR
79 # unless .MAKE.MODE contains "curdirOk=[^0nNfF]"
80 .if defined(_meta_filemon) && ${.OBJDIR} == ${.CURDIR} && \
81 (empty(.MAKE.MODE:tl:Mcurdirok=*) || \
82 !empty(.MAKE.MODE:tl:Mcurdirok=[0NnFf]*))
86 # Skip reading .depend when not needed to speed up tree-walks and simple
87 # lookups. See _SKIP_BUILD logic in bsd.init.mk for more details.
88 # Also skip generating or including .depend.* files if in meta+filemon mode
89 # since it will track dependencies itself. OBJS_DEPEND_GUESS is still used.
90 .if defined(_SKIP_BUILD) || defined(_meta_filemon)
92 .if ${MK_DIRDEPS_BUILD} == "no" || make(analyze) || make(print-dir) || \
93 make(obj) || (!make(all) && (make(clean*) || make(destroy*)))
94 .MAKE.DEPENDFILE= /dev/null
101 .for _S in ${SRCS:N*.[dhly]}
102 OBJS_DEPEND_GUESS.${_S:R}.o+= ${_S}
106 .for _LSRC in ${SRCS:M*.l:N*/*}
107 .for _LC in ${_LSRC:R}.c
109 ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
110 OBJS_DEPEND_GUESS.${_LC:R}.o+= ${_LC}
111 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
117 .for _YSRC in ${SRCS:M*.y:N*/*}
118 .for _YC in ${_YSRC:R}.c
119 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
121 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
122 .ORDER: ${_YC} y.tab.h
124 ${_YC} y.tab.h: ${_YSRC}
125 ${YACC} ${YFLAGS} ${.ALLSRC}
127 CLEANFILES+= y.tab.c y.tab.h
128 .elif !empty(YFLAGS:M-d)
129 .for _YH in ${_YC:R}.h
130 .ORDER: ${_YC} ${_YH}
132 ${_YC} ${_YH}: ${_YSRC}
133 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
139 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
141 OBJS_DEPEND_GUESS.${_YC:R}.o+= ${_YC}
145 # DTrace probe definitions
147 CFLAGS+= -I${.OBJDIR}
149 .for _DSRC in ${SRCS:M*.d:N*/*}
150 .for _D in ${_DSRC:R}
153 ${DTRACE} ${DTRACEFLAGS} -h -s ${.ALLSRC}
154 SRCS:= ${SRCS:S/^${_DSRC}$//}
156 CLEANFILES+= ${_D}.h ${_D}.o
157 ${_D}.o: ${_DSRC} ${OBJS:S/^${_D}.o$//}
159 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
161 CLEANFILES+= ${_D}.pico ${_D}.po
162 ${_D}.pico: ${_DSRC} ${SOBJS:S/^${_D}.pico$//}
164 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
165 ${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
167 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC:N*.h}
173 .if ${MAKE_VERSION} < 20160220
176 # Handle OBJS=../somefile.o hacks. Just replace '/' rather than use :T to
178 DEPEND_FILTER= C,/,_,g
179 DEPENDSRCS= ${SRCS:M*.[cSC]} ${SRCS:M*.cxx} ${SRCS:M*.cpp} ${SRCS:M*.cc}
180 DEPENDSRCS+= ${DPSRCS:M*.[cSC]} ${SRCS:M*.cxx} ${SRCS:M*.cpp} ${SRCS:M*.cc}
181 .if !empty(DEPENDSRCS)
182 DEPENDOBJS+= ${DEPENDSRCS:R:S,$,.o,}
184 DEPENDFILES_OBJS= ${DEPENDOBJS:O:u:${DEPEND_FILTER}:C/^/${DEPENDFILE}./}
185 DEPEND_CFLAGS+= -MD ${DEPEND_MP} -MF${DEPENDFILE}.${.TARGET:${DEPEND_FILTER}}
186 DEPEND_CFLAGS+= -MT${.TARGET}
187 .if !defined(_meta_filemon)
188 .if defined(.PARSEDIR)
189 # Only add in DEPEND_CFLAGS for CFLAGS on files we expect from DEPENDOBJS
190 # as those are the only ones we will include.
191 DEPEND_CFLAGS_CONDITION= "${DEPENDOBJS:${DEPEND_FILTER}:M${.TARGET:${DEPEND_FILTER}}}" != ""
192 CFLAGS+= ${${DEPEND_CFLAGS_CONDITION}:?${DEPEND_CFLAGS}:}
194 CFLAGS+= ${DEPEND_CFLAGS}
196 .if !defined(_SKIP_READ_DEPEND)
197 .for __depend_obj in ${DEPENDFILES_OBJS}
198 .if ${MAKE_VERSION} < 20160220
199 .sinclude "${.OBJDIR}/${__depend_obj}"
201 .dinclude "${.OBJDIR}/${__depend_obj}"
204 .endif # !defined(_SKIP_READ_DEPEND)
205 .endif # !defined(_meta_filemon)
206 .endif # defined(SRCS)
208 .if ${MK_DIRDEPS_BUILD} == "yes" && ${.MAKE.DEPENDFILE} != "/dev/null"
209 # Prevent meta.autodep.mk from tracking "local dependencies".
211 .include <meta.autodep.mk>
212 # If using filemon then _EXTRADEPEND is skipped since it is not needed.
213 .if defined(_meta_filemon)
214 # this depend: bypasses that below
215 # the dependency helps when bootstrapping
216 depend: beforedepend ${DPSRCS} ${SRCS} afterdepend
218 afterdepend: beforedepend
222 # Guess some dependencies for when no ${DEPENDFILE}.OBJ is generated yet.
223 # For meta+filemon the .meta file is checked for since it is the dependency
225 .for __obj in ${DEPENDOBJS:O:u}
226 # If the obj has any '/', then replace with '_'. For meta files, this is
227 # mimicing what bmake's meta_name() does and adding in the full path
228 # as well to ensure that the expected meta file is read.
230 .if ${MAKE_VERSION} < 20171028
231 _meta_obj= ${.OBJDIR:C,/,_,g}_${__obj:C,/,_,g}.meta
233 _meta_obj= ${__obj:C,/,_,g}.meta
234 .endif # ${MAKE_VERSION} < 20171028
236 _meta_obj= ${__obj}.meta
237 .endif # ${__obj:M*/*}
238 _dep_obj= ${DEPENDFILE}.${__obj:${DEPEND_FILTER}}
239 .if (defined(_meta_filemon) && !exists(${.OBJDIR}/${_meta_obj})) || \
240 (!defined(_meta_filemon) && !exists(${.OBJDIR}/${_dep_obj}))
241 ${__obj}: ${OBJS_DEPEND_GUESS}
242 ${__obj}: ${OBJS_DEPEND_GUESS.${__obj}}
243 .elif defined(_meta_filemon)
244 # For meta mode we still need to know which file to depend on to avoid
245 # ambiguous suffix transformation rules from .PATH. Meta mode does not
246 # use .depend files. We really only need source files, not headers since
247 # they are typically in SRCS/beforebuild already. For target-specific
248 # guesses do include headers though since they may not be in SRCS.
249 ${__obj}: ${OBJS_DEPEND_GUESS:N*.h}
250 ${__obj}: ${OBJS_DEPEND_GUESS.${__obj}}
254 # Always run 'make depend' to generate dependencies early and to avoid the
255 # need for manually running it. The dirdeps build should only do this in
256 # sub-makes though since MAKELEVEL0 is for dirdeps calculations.
257 .if ${MK_DIRDEPS_BUILD} == "no" || ${.MAKE.LEVEL} > 0
263 depend: beforedepend ${DEPENDFILE} afterdepend
265 # Tell bmake not to look for generated files via .PATH
266 .NOPATH: ${DEPENDFILE} ${DEPENDFILES_OBJS}
268 # A .depend file will only be generated if there are commands in
269 # beforedepend/_EXTRADEPEND/afterdepend The _EXTRADEPEND target is
270 # ignored if using meta+filemon since it handles all dependencies. The other
271 # targets are kept as they be used for generating something. The target is
272 # kept to allow 'make depend' to generate files.
273 ${DEPENDFILE}: ${SRCS} ${DPSRCS}
274 .if exists(${.OBJDIR}/${DEPENDFILE}) || \
275 ((commands(beforedepend) || \
276 (!defined(_meta_filemon) && commands(_EXTRADEPEND)) || \
277 commands(afterdepend)) && !empty(.MAKE.MODE:Mmeta))
280 .if !defined(_meta_filemon) && target(_EXTRADEPEND)
282 ${DEPENDFILE}: _EXTRADEPEND
285 .ORDER: ${DEPENDFILE} afterdepend
287 depend: beforedepend afterdepend
289 .if !target(beforedepend)
292 .ORDER: beforedepend ${DEPENDFILE}
293 .ORDER: beforedepend afterdepend
295 .if !target(afterdepend)
301 .if ${CTAGS:T} == "gtags"
302 CLEANDEPENDFILES+= GPATH GRTAGS GSYMS GTAGS
304 CLEANDEPENDDIRS+= HTML
307 CLEANDEPENDFILES+= tags
310 .if !target(cleandepend)
312 .if !empty(CLEANDEPENDFILES)
313 rm -f ${CLEANDEPENDFILES}
315 .if !empty(CLEANDEPENDDIRS)
316 rm -rf ${CLEANDEPENDDIRS}
319 .ORDER: cleandepend all
320 .ORDER: cleandepend depend
322 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
323 _LDADD_FROM_DPADD= ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
324 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
325 # LDADD list due to unresolved symbols
326 _LDADD_CANONICALIZED= ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
328 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
330 @echo "DPADD -> ${_LDADD_FROM_DPADD}"
331 @echo "LDADD -> ${_LDADD_CANONICALIZED}"