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*.[hly]}
81 .for _LSRC in ${SRCS:M*.l:N*/*}
82 .for _LC in ${_LSRC:R}.c
84 ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
85 .if !exists(${.OBJDIR}/${DEPENDFILE})
88 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
93 .for _YSRC in ${SRCS:M*.y:N*/*}
94 .for _YC in ${_YSRC:R}.c
95 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
97 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
98 .ORDER: ${_YC} y.tab.h
99 ${_YC} y.tab.h: ${_YSRC}
100 ${YACC} ${YFLAGS} ${.ALLSRC}
102 CLEANFILES+= y.tab.c y.tab.h
103 .elif !empty(YFLAGS:M-d)
104 .for _YH in ${_YC:R}.h
105 .ORDER: ${_YC} ${_YH}
106 ${_YC} ${_YH}: ${_YSRC}
107 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
113 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
115 .if !exists(${.OBJDIR}/${DEPENDFILE})
124 depend: beforedepend ${DEPENDFILE} afterdepend
126 # Tell bmake not to look for generated files via .PATH
127 .NOPATH: ${DEPENDFILE}
129 .if ${MK_FAST_DEPEND} == "no"
130 # Capture -include from CFLAGS.
131 # This could be simpler with bmake :tW but needs to support fmake for MFC.
132 _CFLAGS_INCLUDES= ${CFLAGS:Q:S/\\ /,/g:C/-include,/-include%/g:C/,/ /g:M-include*:C/%/ /g}
133 _CXXFLAGS_INCLUDES= ${CXXFLAGS:Q:S/\\ /,/g:C/-include,/-include%/g:C/,/ /g:M-include*:C/%/ /g}
134 # XXX: Temporary hack to workaround .depend files not tracking -include
135 .if !empty(_CFLAGS_INCLUDES)
136 ${OBJS} ${POBJS} ${SOBJS}: ${_CFLAGS_INCLUDES:M*.h}
138 .if !empty(_CXXFLAGS_INCLUDES)
139 ${OBJS} ${POBJS} ${SOBJS}: ${_CXXFLAGS_INCLUDES:M*.h}
142 # Different types of sources are compiled with slightly different flags.
143 # Split up the sources, and filter out headers and non-applicable flags.
144 MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
145 ${CFLAGS:M-ansi} ${_CFLAGS_INCLUDES}
146 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
147 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*} \
148 ${_CXXFLAGS_INCLUDES}
149 .endif # ${MK_FAST_DEPEND} == "no"
152 ${DEPENDFILE}: ${DPSRCS}
154 .if !empty(DPSRCS:M*.[cS])
155 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
156 ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
158 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
159 !empty(DPSRCS:M*.cxx)
160 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
162 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
164 .if target(_EXTRADEPEND)
166 ${DEPENDFILE}: _EXTRADEPEND
169 .ORDER: ${DEPENDFILE} afterdepend
171 depend: beforedepend afterdepend
173 .if !target(beforedepend)
176 .ORDER: beforedepend ${DEPENDFILE}
177 .ORDER: beforedepend afterdepend
179 .if !target(afterdepend)
184 .if !target(cleandepend)
187 .if ${CTAGS:T} == "gtags"
188 rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
193 rm -f ${DEPENDFILE} tags
198 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
199 _LDADD_FROM_DPADD= ${DPADD:C;^/usr/lib/lib(.*)\.a$;-l\1;}
200 _LDADD_CANONICALIZED= ${LDADD:S/$//}
202 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
204 @echo "DPADD -> ${_LDADD_FROM_DPADD}"
205 @echo "LDADD -> ${_LDADD_CANONICALIZED}"