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}.*
63 # Handle OBJS=../somefile.o hacks. Just replace '/' rather than use :T to
65 DEPEND_FILTER= C,/,_,g
66 DEPEND_CFLAGS+= -MD ${DEPEND_MP} -MF${DEPENDFILE}.${.TARGET:${DEPEND_FILTER}}
67 DEPEND_CFLAGS+= -MT${.TARGET}
68 CFLAGS+= ${DEPEND_CFLAGS}
69 DEPENDOBJS+= ${OBJS} ${POBJS} ${SOBJS}
70 .for __obj in ${DEPENDOBJS:O:u}
71 .if ${.MAKEFLAGS:M-V} == ""
72 .sinclude "${DEPENDFILE}.${__obj:${DEPEND_FILTER}}"
74 DEPENDFILES_OBJS+= ${DEPENDFILE}.${__obj:${DEPEND_FILTER}}
76 .endif # ${MK_FAST_DEPEND} == "yes"
78 # Keep `tags' here, before SRCS are mangled below for `depend'.
79 .if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
81 .if ${CTAGS:T} == "gtags"
82 @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
84 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
87 @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
88 ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
95 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
96 .for _S in ${SRCS:N*.[dhly]}
102 .for _LSRC in ${SRCS:M*.l:N*/*}
103 .for _LC in ${_LSRC:R}.c
105 ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
106 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
109 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
115 .for _YSRC in ${SRCS:M*.y:N*/*}
116 .for _YC in ${_YSRC:R}.c
117 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
119 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
120 .ORDER: ${_YC} y.tab.h
121 ${_YC} y.tab.h: ${_YSRC}
122 ${YACC} ${YFLAGS} ${.ALLSRC}
124 CLEANFILES+= y.tab.c y.tab.h
125 .elif !empty(YFLAGS:M-d)
126 .for _YH in ${_YC:R}.h
129 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
135 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
137 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
143 # DTrace probe definitions
145 CFLAGS+= -I${.OBJDIR}
147 .for _DSRC in ${SRCS:M*.d:N*/*}
148 .for _D in ${_DSRC:R}
151 ${DTRACE} ${DTRACEFLAGS} -h -s ${.ALLSRC}
152 SRCS:= ${SRCS:S/^${_DSRC}$//}
154 CLEANFILES+= ${_D}.h ${_D}.o
155 ${_D}.o: ${_DSRC} ${OBJS:S/^${_D}.o$//}
156 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
158 CLEANFILES+= ${_D}.So ${_D}.po
159 ${_D}.So: ${_DSRC} ${SOBJS:S/^${_D}.So$//}
160 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
161 ${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
162 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
166 beforedepend: ${DHDRS}
167 beforebuild: ${DHDRS}
170 .if ${MK_DIRDEPS_BUILD} == "yes"
171 .include <meta.autodep.mk>
172 # this depend: bypasses that below
173 # the dependency helps when bootstrapping
174 depend: beforedepend ${DPSRCS} ${SRCS} afterdepend
176 afterdepend: beforedepend
181 depend: beforedepend ${DEPENDFILE} afterdepend
183 # Tell bmake not to look for generated files via .PATH
184 .NOPATH: ${DEPENDFILE} ${DEPENDFILES_OBJS}
186 # Different types of sources are compiled with slightly different flags.
187 # Split up the sources, and filter out headers and non-applicable flags.
188 MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
190 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
191 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*}
194 ${DEPENDFILE}: ${DPSRCS}
195 .if ${MK_FAST_DEPEND} == "no"
197 .if !empty(DPSRCS:M*.[cS])
198 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
199 ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
201 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
202 !empty(DPSRCS:M*.cxx)
203 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
205 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
210 .endif # ${MK_FAST_DEPEND} == "no"
211 .if target(_EXTRADEPEND)
213 ${DEPENDFILE}: _EXTRADEPEND
216 .ORDER: ${DEPENDFILE} afterdepend
218 depend: beforedepend afterdepend
220 .if !target(beforedepend)
223 .ORDER: beforedepend ${DEPENDFILE}
224 .ORDER: beforedepend afterdepend
226 .if !target(afterdepend)
231 .if !target(cleandepend)
234 .if ${CTAGS:T} == "gtags"
235 rm -f ${DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
240 rm -f ${DEPENDFILES} tags
245 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
246 _LDADD_FROM_DPADD= ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
247 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
248 # LDADD list due to unresolved symbols
249 _LDADD_CANONICALIZED= ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
251 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
253 @echo "DPADD -> ${_LDADD_FROM_DPADD}"
254 @echo "LDADD -> ${_LDADD_CANONICALIZED}"