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.
52 MKDEPCMD?= CC='${CC} ${DEPFLAGS}' mkdep
57 DEPENDFILES= ${DEPENDFILE}
58 .if ${MK_FAST_DEPEND} == "yes" && ${.MAKE.MODE:Unormal:Mmeta*} == ""
59 DEPENDFILES+= ${DEPENDFILE}.*
60 DEPEND_CFLAGS+= -MD -MP -MF${DEPENDFILE}.${.TARGET}
61 DEPEND_CFLAGS+= -MT${.TARGET}
62 CFLAGS+= ${DEPEND_CFLAGS}
63 DEPENDOBJS+= ${OBJS} ${POBJS} ${SOBJS}
64 .for __obj in ${DEPENDOBJS:O:u}
65 .if ${.MAKEFLAGS:M-V} == ""
66 .sinclude "${DEPENDFILE}.${__obj}"
68 DEPENDFILES_OBJS+= ${DEPENDFILE}.${__obj}
70 .endif # ${MK_FAST_DEPEND} == "yes"
72 # Keep `tags' here, before SRCS are mangled below for `depend'.
73 .if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
75 .if ${CTAGS:T} == "gtags"
76 @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
78 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
81 @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
82 ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
89 .if !exists(${.OBJDIR}/${DEPENDFILE})
90 .for _S in ${SRCS:N*.[dhly]}
96 .for _LSRC in ${SRCS:M*.l:N*/*}
97 .for _LC in ${_LSRC:R}.c
99 ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
100 .if !exists(${.OBJDIR}/${DEPENDFILE})
103 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
109 .for _YSRC in ${SRCS:M*.y:N*/*}
110 .for _YC in ${_YSRC:R}.c
111 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
113 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
114 .ORDER: ${_YC} y.tab.h
115 ${_YC} y.tab.h: ${_YSRC}
116 ${YACC} ${YFLAGS} ${.ALLSRC}
118 CLEANFILES+= y.tab.c y.tab.h
119 .elif !empty(YFLAGS:M-d)
120 .for _YH in ${_YC:R}.h
123 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
129 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
131 .if !exists(${.OBJDIR}/${DEPENDFILE})
137 # DTrace probe definitions
139 CFLAGS+= -I${.OBJDIR}
141 .for _DSRC in ${SRCS:M*.d:N*/*}
142 .for _D in ${_DSRC:R}
145 ${DTRACE} ${DTRACEFLAGS} -h -s ${.ALLSRC}
146 SRCS:= ${SRCS:S/^${_DSRC}$//}
148 CLEANFILES+= ${_D}.h ${_D}.o
149 ${_D}.o: ${_DSRC} ${OBJS:S/^${_D}.o$//}
150 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
152 CLEANFILES+= ${_D}.So ${_D}.po
153 ${_D}.So: ${_DSRC} ${SOBJS:S/^${_D}.So$//}
154 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
155 ${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
156 ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
160 beforedepend: ${DHDRS}
161 beforebuild: ${DHDRS}
164 .if ${MK_META_MODE} == "yes"
165 .include <meta.autodep.mk>
166 # this depend: bypasses that below
167 # the dependency helps when bootstrapping
168 depend: beforedepend ${DPSRCS} ${SRCS} afterdepend
170 afterdepend: beforedepend
175 depend: beforedepend ${DEPENDFILE} afterdepend
177 # Tell bmake not to look for generated files via .PATH
178 .NOPATH: ${DEPENDFILE} ${DEPENDFILES_OBJS}
180 # Different types of sources are compiled with slightly different flags.
181 # Split up the sources, and filter out headers and non-applicable flags.
182 MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
184 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
185 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*}
188 ${DEPENDFILE}: ${DPSRCS}
189 .if ${MK_FAST_DEPEND} == "no"
191 .if !empty(DPSRCS:M*.[cS])
192 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
193 ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
195 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
196 !empty(DPSRCS:M*.cxx)
197 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
199 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
204 .endif # ${MK_FAST_DEPEND} == "no"
205 .if target(_EXTRADEPEND)
207 ${DEPENDFILE}: _EXTRADEPEND
210 .ORDER: ${DEPENDFILE} afterdepend
212 depend: beforedepend afterdepend
214 .if !target(beforedepend)
217 .ORDER: beforedepend ${DEPENDFILE}
218 .ORDER: beforedepend afterdepend
220 .if !target(afterdepend)
225 .if !target(cleandepend)
228 .if ${CTAGS:T} == "gtags"
229 rm -f ${DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
234 rm -f ${DEPENDFILES} tags
239 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
240 _LDADD_FROM_DPADD= ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
241 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
242 # LDADD list due to unresolved symbols
243 _LDADD_CANONICALIZED= ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
245 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
247 @echo "DPADD -> ${_LDADD_FROM_DPADD}"
248 @echo "LDADD -> ${_LDADD_CANONICALIZED}"