]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.dep.mk
FAST_DEPEND: Move handling code below yacc/lex/dtrace code that modified SRCS.
[FreeBSD/FreeBSD.git] / share / mk / bsd.dep.mk
1 # $FreeBSD$
2 #
3 # The include file <bsd.dep.mk> handles Makefile dependencies.
4 #
5 #
6 # +++ variables +++
7 #
8 # CTAGS         A tags file generation program [gtags]
9 #
10 # CTAGSFLAGS    Options for ctags(1) [not set]
11 #
12 # DEPENDFILE    dependencies file [.depend]
13 #
14 # GTAGSFLAGS    Options for gtags(1) [-o]
15 #
16 # HTAGSFLAGS    Options for htags(1) [not set]
17 #
18 # MKDEP         Options for ${MKDEPCMD} [not set]
19 #
20 # MKDEPCMD      Makefile dependency list program [mkdep]
21 #
22 # SRCS          List of source files (c, c++, assembler)
23 #
24 # DPSRCS        List of source files which are needed for generating
25 #               dependencies, ${SRCS} are always part of it.
26 #
27 # +++ targets +++
28 #
29 #       cleandepend:
30 #               Remove depend and tags file
31 #
32 #       depend:
33 #               Make the dependencies for the source files, and store
34 #               them in the file ${DEPENDFILE}.
35 #
36 #       tags:
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
40 #               after gtags(1).
41
42 .if !target(__<bsd.init.mk>__)
43 .error bsd.dep.mk cannot be included directly.
44 .endif
45
46 CTAGS?=         gtags
47 CTAGSFLAGS?=
48 GTAGSFLAGS?=    -o
49 HTAGSFLAGS?=
50
51 _MKDEPCC:=      ${CC:N${CCACHE_BIN}}
52 # XXX: DEPFLAGS can come out once Makefile.inc1 properly passes down
53 # CXXFLAGS.
54 .if !empty(DEPFLAGS)
55 _MKDEPCC+=      ${DEPFLAGS}
56 .endif
57 MKDEPCMD?=      CC='${_MKDEPCC}' mkdep
58 DEPENDFILE?=    .depend
59 DEPENDFILES=    ${DEPENDFILE}
60
61 # Keep `tags' here, before SRCS are mangled below for `depend'.
62 .if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
63 tags: ${SRCS}
64 .if ${CTAGS:T} == "gtags"
65         @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
66 .if defined(HTML)
67         @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
68 .endif
69 .else
70         @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
71             ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
72 .endif
73 .endif
74
75 .if defined(SRCS)
76 CLEANFILES?=
77
78 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
79 .for _S in ${SRCS:N*.[dhly]}
80 ${_S:R}.o: ${_S}
81 .endfor
82 .endif
83
84 # Lexical analyzers
85 .for _LSRC in ${SRCS:M*.l:N*/*}
86 .for _LC in ${_LSRC:R}.c
87 ${_LC}: ${_LSRC}
88         ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
89 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
90 ${_LC:R}.o: ${_LC}
91 .endif
92 SRCS:=  ${SRCS:S/${_LSRC}/${_LC}/}
93 CLEANFILES+= ${_LC}
94 .endfor
95 .endfor
96
97 # Yacc grammars
98 .for _YSRC in ${SRCS:M*.y:N*/*}
99 .for _YC in ${_YSRC:R}.c
100 SRCS:=  ${SRCS:S/${_YSRC}/${_YC}/}
101 CLEANFILES+= ${_YC}
102 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
103 .ORDER: ${_YC} y.tab.h
104 ${_YC} y.tab.h: ${_YSRC}
105         ${YACC} ${YFLAGS} ${.ALLSRC}
106         cp y.tab.c ${_YC}
107 CLEANFILES+= y.tab.c y.tab.h
108 .elif !empty(YFLAGS:M-d)
109 .for _YH in ${_YC:R}.h
110 ${_YH}: ${_YC}
111 ${_YC}: ${_YSRC}
112         ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
113 SRCS+=  ${_YH}
114 CLEANFILES+= ${_YH}
115 .endfor
116 .else
117 ${_YC}: ${_YSRC}
118         ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
119 .endif
120 .if ${MK_FAST_DEPEND} == "yes" || !exists(${.OBJDIR}/${DEPENDFILE})
121 ${_YC:R}.o: ${_YC}
122 .endif
123 .endfor
124 .endfor
125
126 # DTrace probe definitions
127 .if ${SRCS:M*.d}
128 CFLAGS+=        -I${.OBJDIR}
129 .endif
130 .for _DSRC in ${SRCS:M*.d:N*/*}
131 .for _D in ${_DSRC:R}
132 DHDRS+= ${_D}.h
133 ${_D}.h: ${_DSRC}
134         ${DTRACE} ${DTRACEFLAGS} -h -s ${.ALLSRC}
135 SRCS:=  ${SRCS:S/^${_DSRC}$//}
136 OBJS+=  ${_D}.o
137 CLEANFILES+= ${_D}.h ${_D}.o
138 ${_D}.o: ${_DSRC} ${OBJS:S/^${_D}.o$//}
139         ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
140 .if defined(LIB)
141 CLEANFILES+= ${_D}.So ${_D}.po
142 ${_D}.So: ${_DSRC} ${SOBJS:S/^${_D}.So$//}
143         ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
144 ${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
145         ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
146 .endif
147 .endfor
148 .endfor
149 beforedepend: ${DHDRS}
150 beforebuild: ${DHDRS}
151
152
153 .if ${MK_FAST_DEPEND} == "yes" && ${.MAKE.MODE:Unormal:Mmeta*} == ""
154 DEPENDFILES+=   ${DEPENDFILE}.*
155 DEPEND_MP?=     -MP
156 # Handle OBJS=../somefile.o hacks.  Just replace '/' rather than use :T to
157 # avoid collisions.
158 DEPEND_FILTER=  C,/,_,g
159 DEPEND_CFLAGS+= -MD ${DEPEND_MP} -MF${DEPENDFILE}.${.TARGET:${DEPEND_FILTER}}
160 DEPEND_CFLAGS+= -MT${.TARGET}
161 CFLAGS+=        ${DEPEND_CFLAGS}
162 DEPENDSRCS=     ${SRCS:M*.[cSC]} ${SRCS:M*.cxx} ${SRCS:M*.cpp} ${SRCS:M*.cc}
163 .if !empty(DEPENDSRCS)
164 DEPENDOBJS+=    ${DEPENDSRCS:R:S,$,.o,}
165 .endif
166 .for __obj in ${DEPENDOBJS:O:u}
167 .if ${.MAKEFLAGS:M-V} == ""
168 .sinclude "${DEPENDFILE}.${__obj:${DEPEND_FILTER}}"
169 .endif
170 DEPENDFILES_OBJS+=      ${DEPENDFILE}.${__obj:${DEPEND_FILTER}}
171 .endfor
172 .endif  # ${MK_FAST_DEPEND} == "yes"
173 .endif  # defined(SRCS)
174
175 .if ${MK_DIRDEPS_BUILD} == "yes"
176 .include <meta.autodep.mk>
177 # this depend: bypasses that below
178 # the dependency helps when bootstrapping
179 depend: beforedepend ${DPSRCS} ${SRCS} afterdepend
180 beforedepend:
181 afterdepend: beforedepend
182 .endif
183
184 .if !target(depend)
185 .if defined(SRCS)
186 depend: beforedepend ${DEPENDFILE} afterdepend
187
188 # Tell bmake not to look for generated files via .PATH
189 .NOPATH: ${DEPENDFILE} ${DEPENDFILES_OBJS}
190
191 # Different types of sources are compiled with slightly different flags.
192 # Split up the sources, and filter out headers and non-applicable flags.
193 MKDEP_CFLAGS=   ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
194                 ${CFLAGS:M-ansi}
195 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
196                 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*}
197
198 DPSRCS+= ${SRCS}
199 ${DEPENDFILE}: ${DPSRCS}
200 .if ${MK_FAST_DEPEND} == "no"
201         rm -f ${DEPENDFILE}
202 .if !empty(DPSRCS:M*.[cS])
203         ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
204             ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
205 .endif
206 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
207     !empty(DPSRCS:M*.cxx)
208         ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
209             ${MKDEP_CXXFLAGS} \
210             ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
211 .else
212 .endif
213 .else
214         : > ${.TARGET}
215 .endif  # ${MK_FAST_DEPEND} == "no"
216 .if target(_EXTRADEPEND)
217 _EXTRADEPEND: .USE
218 ${DEPENDFILE}: _EXTRADEPEND
219 .endif
220
221 .ORDER: ${DEPENDFILE} afterdepend
222 .else
223 depend: beforedepend afterdepend
224 .endif
225 .if !target(beforedepend)
226 beforedepend:
227 .else
228 .ORDER: beforedepend ${DEPENDFILE}
229 .ORDER: beforedepend afterdepend
230 .endif
231 .if !target(afterdepend)
232 afterdepend:
233 .endif
234 .endif
235
236 .if !target(cleandepend)
237 cleandepend:
238 .if defined(SRCS)
239 .if ${CTAGS:T} == "gtags"
240         rm -f ${DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
241 .if defined(HTML)
242         rm -rf HTML
243 .endif
244 .else
245         rm -f ${DEPENDFILES} tags
246 .endif
247 .endif
248 .endif
249
250 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
251 _LDADD_FROM_DPADD=      ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
252 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
253 # LDADD list due to unresolved symbols
254 _LDADD_CANONICALIZED=   ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
255 checkdpadd:
256 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
257         @echo ${.CURDIR}
258         @echo "DPADD -> ${_LDADD_FROM_DPADD}"
259         @echo "LDADD -> ${_LDADD_CANONICALIZED}"
260 .endif
261 .endif