]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.dep.mk
FAST_DEPEND: Don't include depend files when using 'make -V'.
[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 .if ${CC} != "cc"
52 MKDEPCMD?=      CC='${CC} ${DEPFLAGS}' mkdep
53 .else
54 MKDEPCMD?=      mkdep
55 .endif
56 DEPENDFILE?=    .depend
57 DEPENDFILES=    ${DEPENDFILE}
58 .if ${MK_FAST_DEPEND} == "yes"
59 DEPENDFILES+=   ${DEPENDFILE}.*
60 DEPEND_CFLAGS+= -MD -MP -MF${DEPENDFILE}.${.TARGET}
61 DEPEND_CFLAGS+= -MT${.TARGET}
62 CFLAGS+=        ${DEPEND_CFLAGS}
63 DEPENDOBJS+=    ${OBJS} ${POBJS} ${SOBJS}
64 .for __obj in ${DEPENDOBJS:O:u}
65 .if ${.MAKEFLAGS:M-V} == ""
66 .sinclude "${DEPENDFILE}.${__obj}"
67 .endif
68 DEPENDFILES_OBJS+=      ${DEPENDFILE}.${__obj}
69 .endfor
70 .endif  # ${MK_FAST_DEPEND} == "yes"
71
72 # Keep `tags' here, before SRCS are mangled below for `depend'.
73 .if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
74 tags: ${SRCS}
75 .if ${CTAGS:T} == "gtags"
76         @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
77 .if defined(HTML)
78         @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
79 .endif
80 .else
81         @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
82             ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
83 .endif
84 .endif
85
86 .if defined(SRCS)
87 CLEANFILES?=
88
89 .if !exists(${.OBJDIR}/${DEPENDFILE})
90 .for _S in ${SRCS:N*.[dhly]}
91 ${_S:R}.o: ${_S}
92 .endfor
93 .endif
94
95 # Lexical analyzers
96 .for _LSRC in ${SRCS:M*.l:N*/*}
97 .for _LC in ${_LSRC:R}.c
98 ${_LC}: ${_LSRC}
99         ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
100 .if !exists(${.OBJDIR}/${DEPENDFILE})
101 ${_LC:R}.o: ${_LC}
102 .endif
103 SRCS:=  ${SRCS:S/${_LSRC}/${_LC}/}
104 CLEANFILES+= ${_LC}
105 .endfor
106 .endfor
107
108 # Yacc grammars
109 .for _YSRC in ${SRCS:M*.y:N*/*}
110 .for _YC in ${_YSRC:R}.c
111 SRCS:=  ${SRCS:S/${_YSRC}/${_YC}/}
112 CLEANFILES+= ${_YC}
113 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
114 .ORDER: ${_YC} y.tab.h
115 ${_YC} y.tab.h: ${_YSRC}
116         ${YACC} ${YFLAGS} ${.ALLSRC}
117         cp y.tab.c ${_YC}
118 CLEANFILES+= y.tab.c y.tab.h
119 .elif !empty(YFLAGS:M-d)
120 .for _YH in ${_YC:R}.h
121 ${_YH}: ${_YC}
122 ${_YC}: ${_YSRC}
123         ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
124 SRCS+=  ${_YH}
125 CLEANFILES+= ${_YH}
126 .endfor
127 .else
128 ${_YC}: ${_YSRC}
129         ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
130 .endif
131 .if !exists(${.OBJDIR}/${DEPENDFILE})
132 ${_YC:R}.o: ${_YC}
133 .endif
134 .endfor
135 .endfor
136
137 # DTrace probe definitions
138 .if ${SRCS:M*.d}
139 CFLAGS+=        -I${.OBJDIR}
140 .endif
141 .for _DSRC in ${SRCS:M*.d:N*/*}
142 .for _D in ${_DSRC:R}
143 DHDRS+= ${_D}.h
144 ${_D}.h: ${_DSRC}
145         ${DTRACE} ${DTRACEFLAGS} -h -s ${.ALLSRC}
146 SRCS:=  ${SRCS:S/^${_DSRC}$//}
147 OBJS+=  ${_D}.o
148 CLEANFILES+= ${_D}.h ${_D}.o
149 ${_D}.o: ${_DSRC} ${OBJS:S/^${_D}.o$//}
150         ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
151 .if defined(LIB)
152 CLEANFILES+= ${_D}.So ${_D}.po
153 ${_D}.So: ${_DSRC} ${SOBJS:S/^${_D}.So$//}
154         ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
155 ${_D}.po: ${_DSRC} ${POBJS:S/^${_D}.po$//}
156         ${DTRACE} ${DTRACEFLAGS} -G -o ${.TARGET} -s ${.ALLSRC}
157 .endif
158 .endfor
159 .endfor
160 beforedepend: ${DHDRS}
161 beforebuild: ${DHDRS}
162 .endif
163
164 .if ${MK_META_MODE} == "yes"
165 .include <meta.autodep.mk>
166 # this depend: bypasses that below
167 # the dependency helps when bootstrapping
168 depend: beforedepend ${DPSRCS} ${SRCS} afterdepend
169 beforedepend:
170 afterdepend: beforedepend
171 .endif
172
173 .if !target(depend)
174 .if defined(SRCS)
175 depend: beforedepend ${DEPENDFILE} afterdepend
176
177 # Tell bmake not to look for generated files via .PATH
178 .NOPATH: ${DEPENDFILE} ${DEPENDFILES_OBJS}
179
180 # Different types of sources are compiled with slightly different flags.
181 # Split up the sources, and filter out headers and non-applicable flags.
182 MKDEP_CFLAGS=   ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
183                 ${CFLAGS:M-ansi}
184 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
185                 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*}
186
187 DPSRCS+= ${SRCS}
188 ${DEPENDFILE}: ${DPSRCS}
189 .if ${MK_FAST_DEPEND} == "no"
190         rm -f ${DEPENDFILE}
191 .if !empty(DPSRCS:M*.[cS])
192         ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
193             ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
194 .endif
195 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
196     !empty(DPSRCS:M*.cxx)
197         ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
198             ${MKDEP_CXXFLAGS} \
199             ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
200 .else
201 .endif
202 .else
203         : > ${.TARGET}
204 .endif  # ${MK_FAST_DEPEND} == "no"
205 .if target(_EXTRADEPEND)
206 _EXTRADEPEND: .USE
207 ${DEPENDFILE}: _EXTRADEPEND
208 .endif
209
210 .ORDER: ${DEPENDFILE} afterdepend
211 .else
212 depend: beforedepend afterdepend
213 .endif
214 .if !target(beforedepend)
215 beforedepend:
216 .else
217 .ORDER: beforedepend ${DEPENDFILE}
218 .ORDER: beforedepend afterdepend
219 .endif
220 .if !target(afterdepend)
221 afterdepend:
222 .endif
223 .endif
224
225 .if !target(cleandepend)
226 cleandepend:
227 .if defined(SRCS)
228 .if ${CTAGS:T} == "gtags"
229         rm -f ${DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
230 .if defined(HTML)
231         rm -rf HTML
232 .endif
233 .else
234         rm -f ${DEPENDFILES} tags
235 .endif
236 .endif
237 .endif
238
239 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
240 _LDADD_FROM_DPADD=      ${DPADD:R:T:C;^lib(.*)$;-l\1;g}
241 # Ignore -Wl,--start-group/-Wl,--end-group as it might be required in the
242 # LDADD list due to unresolved symbols
243 _LDADD_CANONICALIZED=   ${LDADD:N:R:T:C;^lib(.*)$;-l\1;g:N-Wl,--[es]*-group}
244 checkdpadd:
245 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
246         @echo ${.CURDIR}
247         @echo "DPADD -> ${_LDADD_FROM_DPADD}"
248         @echo "LDADD -> ${_LDADD_CANONICALIZED}"
249 .endif
250 .endif