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}' 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+= -D_DTRACE_VERSION=1 -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}/${_D}.h/}
137 CLEANFILES+= ${_D}.h ${_D}.o
138 ${_D}.o: ${_D}.h ${OBJS:S/${_D}.o//}
139 ${DTRACE} -xnolibs -G -o ${.TARGET} -s ${.CURDIR}/${_DSRC} \
142 CLEANFILES+= ${_D}.So ${_D}.po
143 ${_D}.So: ${_D}.h ${SOBJS:S/${_D}.So//}
144 ${DTRACE} -xnolibs -G -o ${.TARGET} -s ${.CURDIR}/${_DSRC} \
145 ${SOBJS:S/${_D}.So//}
146 ${_D}.po: ${_D}.h ${POBJS:S/${_D}.po//}
147 ${DTRACE} -xnolibs -G -o ${.TARGET} -s ${.CURDIR}/${_DSRC} \
148 ${POBJS:S/${_D}.po//}
152 beforedepend: ${DHDRS}
153 beforebuild: ${DHDRS}
158 depend: beforedepend ${DEPENDFILE} afterdepend
160 # Tell bmake not to look for generated files via .PATH
161 .NOPATH: ${DEPENDFILE}
163 # Different types of sources are compiled with slightly different flags.
164 # Split up the sources, and filter out headers and non-applicable flags.
165 MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
167 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
168 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*}
171 ${DEPENDFILE}: ${DPSRCS}
173 .if !empty(DPSRCS:M*.[cS])
174 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
175 ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
177 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
178 !empty(DPSRCS:M*.cxx)
179 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
181 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
183 .if target(_EXTRADEPEND)
185 ${DEPENDFILE}: _EXTRADEPEND
188 .ORDER: ${DEPENDFILE} afterdepend
190 depend: beforedepend afterdepend
192 .if !target(beforedepend)
195 .ORDER: beforedepend ${DEPENDFILE}
196 .ORDER: beforedepend afterdepend
198 .if !target(afterdepend)
203 .if !target(cleandepend)
206 .if ${CTAGS:T} == "gtags"
207 rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
212 rm -f ${DEPENDFILE} tags
217 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
218 _LDADD_FROM_DPADD= ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
219 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
220 # LDADD list due to unresolved symbols
221 _LDADD_CANONICALIZED= ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
223 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
225 @echo "DPADD -> ${_LDADD_FROM_DPADD}"
226 @echo "LDADD -> ${_LDADD_CANONICALIZED}"