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
58 # Keep `tags' here, before SRCS are mangled below for `depend'.
59 .if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
61 .if ${CTAGS:T} == "gtags"
62 @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
64 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
67 @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
68 ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
75 .if !exists(${.OBJDIR}/${DEPENDFILE})
76 .for _S in ${SRCS:N*.[dhly]}
82 .for _LSRC in ${SRCS:M*.l:N*/*}
83 .for _LC in ${_LSRC:R}.c
85 ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
86 .if !exists(${.OBJDIR}/${DEPENDFILE})
89 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
95 .for _YSRC in ${SRCS:M*.y:N*/*}
96 .for _YC in ${_YSRC:R}.c
97 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
99 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
100 .ORDER: ${_YC} y.tab.h
101 ${_YC} y.tab.h: ${_YSRC}
102 ${YACC} ${YFLAGS} ${.ALLSRC}
104 CLEANFILES+= y.tab.c y.tab.h
105 .elif !empty(YFLAGS:M-d)
106 .for _YH in ${_YC:R}.h
109 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
115 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
117 .if !exists(${.OBJDIR}/${DEPENDFILE})
123 # DTrace probe definitions
124 # libelf is currently needed for drti.o
128 CFLAGS+= -I${.OBJDIR}
130 .for _DSRC in ${SRCS:M*.d:N*/*}
131 .for _D in ${_DSRC:R}
134 ${DTRACE} -xnolibs -h -s ${.ALLSRC}
135 SRCS:= ${SRCS:S/^${_DSRC}$//}
137 CLEANFILES+= ${_D}.h ${_D}.o
138 ${_D}.o: ${_DSRC} ${OBJS:S/^${_D}.o$//}
139 ${DTRACE} -xnolibs -G -o ${.TARGET} -s ${.ALLSRC}
141 CLEANFILES+= ${_D}.So ${_D}.po
142 ${_D}.So: ${_DSRC} ${SOBJS:S/^${_D}.So$//}
143 ${DTRACE} -xnolibs -G -o ${.TARGET} -s ${.ALLSRC}
144 ${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
145 ${DTRACE} -xnolibs -G -o ${.TARGET} -s ${.ALLSRC}
149 beforedepend: ${DHDRS}
150 beforebuild: ${DHDRS}
155 depend: beforedepend ${DEPENDFILE} afterdepend
157 # Tell bmake not to look for generated files via .PATH
158 .NOPATH: ${DEPENDFILE}
160 # Different types of sources are compiled with slightly different flags.
161 # Split up the sources, and filter out headers and non-applicable flags.
162 MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
164 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
165 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*}
168 ${DEPENDFILE}: ${DPSRCS}
170 .if !empty(DPSRCS:M*.[cS])
171 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
172 ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
174 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
175 !empty(DPSRCS:M*.cxx)
176 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
178 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
180 .if target(_EXTRADEPEND)
182 ${DEPENDFILE}: _EXTRADEPEND
185 .ORDER: ${DEPENDFILE} afterdepend
187 depend: beforedepend afterdepend
189 .if !target(beforedepend)
192 .ORDER: beforedepend ${DEPENDFILE}
193 .ORDER: beforedepend afterdepend
195 .if !target(afterdepend)
200 .if !target(cleandepend)
203 .if ${CTAGS:T} == "gtags"
204 rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
209 rm -f ${DEPENDFILE} tags
214 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
215 _LDADD_FROM_DPADD= ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
216 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
217 # LDADD list due to unresolved symbols
218 _LDADD_CANONICALIZED= ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
220 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
222 @echo "DPADD -> ${_LDADD_FROM_DPADD}"
223 @echo "LDADD -> ${_LDADD_CANONICALIZED}"