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
107 .ORDER: ${_YC} ${_YH}
108 ${_YC} ${_YH}: ${_YSRC}
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 # Capture -include from CFLAGS.
164 # This could be simpler with bmake :tW but needs to support fmake for MFC.
165 _CFLAGS_INCLUDES= ${CFLAGS:Q:S/\\ /,/g:C/-include,/-include%/g:C/,/ /g:M-include*:C/%/ /g}
166 _CXXFLAGS_INCLUDES= ${CXXFLAGS:Q:S/\\ /,/g:C/-include,/-include%/g:C/,/ /g:M-include*:C/%/ /g}
168 # Different types of sources are compiled with slightly different flags.
169 # Split up the sources, and filter out headers and non-applicable flags.
170 MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
171 ${CFLAGS:M-ansi} ${_CFLAGS_INCLUDES}
172 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
173 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*} \
174 ${_CXXFLAGS_INCLUDES}
177 ${DEPENDFILE}: ${DPSRCS}
179 .if !empty(DPSRCS:M*.[cS])
180 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
181 ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
183 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
184 !empty(DPSRCS:M*.cxx)
185 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
187 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
189 .if target(_EXTRADEPEND)
191 ${DEPENDFILE}: _EXTRADEPEND
194 .ORDER: ${DEPENDFILE} afterdepend
196 depend: beforedepend afterdepend
198 .if !target(beforedepend)
201 .ORDER: beforedepend ${DEPENDFILE}
202 .ORDER: beforedepend afterdepend
204 .if !target(afterdepend)
209 .if !target(cleandepend)
212 .if ${CTAGS:T} == "gtags"
213 rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
218 rm -f ${DEPENDFILE} tags
223 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
224 _LDADD_FROM_DPADD= ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
225 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
226 # LDADD list due to unresolved symbols
227 _LDADD_CANONICALIZED= ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
229 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
231 @echo "DPADD -> ${_LDADD_FROM_DPADD}"
232 @echo "LDADD -> ${_LDADD_CANONICALIZED}"