build - Support concurrent SUBDIR traversal, fix make depend bug
[dragonfly.git] / share / mk / bsd.dep.mk
CommitLineData
984263bc 1# $FreeBSD: src/share/mk/bsd.dep.mk,v 1.27.2.3 2002/12/23 16:33:37 ru Exp $
30af20ef 2# $DragonFly: src/share/mk/bsd.dep.mk,v 1.9 2006/02/13 13:27:20 corecode Exp $
984263bc
MD
3#
4# The include file <bsd.dep.mk> handles Makefile dependencies.
5#
6#
7# +++ variables +++
8#
9# CTAGS A tags file generation program [gtags]
10#
11# CTAGSFLAGS Options for ctags(1) [not set]
12#
13# DEPENDFILE dependencies file [.depend]
14#
15# GTAGSFLAGS Options for gtags(1) [-o]
16#
17# HTAGSFLAGS Options for htags(1) [not set]
18#
19# MKDEP Options for ${MKDEPCMD} [not set]
20#
21# MKDEPCMD Makefile dependency list program [mkdep]
22#
23# SRCS List of source files (c, c++, assembler)
24#
25#
26# +++ targets +++
27#
28# cleandepend:
29# Remove depend and tags file
30#
31# depend:
32# Make the dependencies for the source files, and store
33# them in the file ${DEPENDFILE}.
34#
35# tags:
36# In "ctags" mode, create a tags file for the source files.
37# In "gtags" mode, create a (GLOBAL) gtags file for the
38# source files. If HTML is defined, htags(1) is also run
39# after gtags(1).
40
41.if !target(__<bsd.init.mk>__)
42.error bsd.dep.mk cannot be included directly.
43.endif
44
45CTAGS?= gtags
46CTAGSFLAGS?=
47GTAGSFLAGS?= -o
48HTAGSFLAGS?=
49
50MKDEPCMD?= mkdep
51DEPENDFILE?= .depend
52
53# Keep `tags' here, before SRCS are mangled below for `depend'.
54.if !target(tags) && defined(SRCS) && !defined(NOTAGS)
55tags: ${SRCS}
56.if ${CTAGS:T} == "ctags"
57 @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
58 ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
59.elif ${CTAGS:T} == "gtags"
60 @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
61.if defined(HTML)
62 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
63.endif
64.endif
65.endif
66
67.if defined(SRCS)
68CLEANFILES?=
69
70.for _LSRC in ${SRCS:M*.l:N*/*}
71.for _LC in ${_LSRC:S/.l/.c/}
72${_LC}: ${_LSRC}
73 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
74SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
75CLEANFILES:= ${CLEANFILES} ${_LC}
76.endfor
77.endfor
78
79.for _YSRC in ${SRCS:M*.y:N*/*}
80.for _YC in ${_YSRC:S/.y/.c/}
81SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
82CLEANFILES:= ${CLEANFILES} ${_YC}
8d049a95 83.if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
984263bc
MD
84.ORDER: ${_YC} y.tab.h
85${_YC} y.tab.h: ${_YSRC}
86 ${YACC} ${YFLAGS} ${.ALLSRC}
87 cp y.tab.c ${_YC}
88SRCS:= ${SRCS} y.tab.h
89CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h
ff5b5f8a 90.elif !empty(YFLAGS:M-d)
984263bc
MD
91.for _YH in ${_YC:S/.c/.h/}
92.ORDER: ${_YC} ${_YH}
93${_YC} ${_YH}: ${_YSRC}
94 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
95SRCS:= ${SRCS} ${_YH}
96CLEANFILES:= ${CLEANFILES} ${_YH}
97.endfor
98.else
99${_YC}: ${_YSRC}
100 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
101.endif
102.endfor
103.endfor
104.endif
105
106.if !target(depend)
107.if defined(SRCS)
67be5538 108depend: beforedepend _dependincs ${DEPENDFILE} afterdepend
984263bc
MD
109
110# Different types of sources are compiled with slightly different flags.
111# Split up the sources, and filter out headers and non-applicable flags.
6d68f83f
SS
112# Separate flag groups out of the sources and treat them differently.
113# The special "_" group is for all files not in any group.
114__FLAGS=
115__FLAGS_FILES= ${SRCS}
116.for _FG in ${FLAGS_GROUPS}
117.for _FFILE in ${${_FG}_FLAGS_FILES}
118__FLAGS_FILES:= ${__FLAGS_FILES:N${_FFILE}}
119.endfor
120.endfor
121
f21f740a 122_DEPENDFILES= ${FLAGS_GROUPS:S/^/.depend_/g}
6d68f83f
SS
123.ORDER: ${_DEPENDFILES}
124
125${DEPENDFILE}: ${_DEPENDFILES}
6d68f83f 126
f0ca6fca
SS
127#
128# __FLAG_FILES is built from SRCS. That means it will contain
129# also .h files and other files that are not direct sources, but which
130# might be required to even run mkdep. This is important if those are
131# generated as well, like some forwarding headers.
132#
133# We'll have to pass these "sources" on to the other .depend_ file targets,
134# since otherwise they might be run before the generated sources are
135# generated. _ALL_DEPENDS captures all files in SRCS that are not handled
136# by the mkdep calls, i.e. all sources that are not being used directly
137# for the .depend* file.
138#
139_ALL_DEPENDS=${__FLAGS_FILES:N*.[sS]:N*.c:N*.cc:N*.C:N*.cpp:N*.cpp:N*.cxx:N*.m}
140
6d68f83f 141.for _FG in _ ${FLAGS_GROUPS}
f0ca6fca 142.depend${_FG:S/^/_/:N__}: ${${_FG}_FLAGS_FILES} ${_ALL_DEPENDS}
6d68f83f
SS
143 -rm -f ${.TARGET}
144 -> ${.TARGET}
145.if ${${_FG}_FLAGS_FILES:M*.[sS]} != ""
146 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
147 ${${_FG}_FLAGS} \
984263bc
MD
148 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
149 ${AINC} \
150 ${.ALLSRC:M*.[sS]}
151.endif
6d68f83f
SS
152.if ${${_FG}_FLAGS_FILES:M*.c} != ""
153 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
154 ${${_FG}_FLAGS} \
984263bc 155 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
1ce5d5aa 156 ${CFLAGS:M-std=*} \
984263bc
MD
157 ${.ALLSRC:M*.c}
158.endif
6d68f83f
SS
159.if ${${_FG}_FLAGS_FILES:M*.cc} != "" || \
160 ${${_FG}_FLAGS_FILES:M*.C} != "" || \
161 ${${_FG}_FLAGS_FILES:M*.cpp} != "" || \
162 ${${_FG}_FLAGS_FILES:M*.cxx} != ""
163 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
164 ${${_FG}_FLAGS} \
984263bc 165 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
1ce5d5aa 166 ${CXXFLAGS:M-std=*} \
984263bc
MD
167 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
168.endif
6d68f83f
SS
169.if ${${_FG}_FLAGS_FILES:M*.m} != ""
170 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
171 ${${_FG}_FLAGS} \
984263bc
MD
172 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \
173 ${OBJCFLAGS:M-Wno-import*} \
174 ${.ALLSRC:M*.m}
175.endif
f21f740a
SS
176.if !empty(${_FG:M_}) && !empty(_DEPENDFILES)
177 cat ${_DEPENDFILES} >> ${.TARGET}
178.endif
6d68f83f
SS
179.endfor
180
984263bc
MD
181.if target(_EXTRADEPEND)
182_EXTRADEPEND: .USE
183${DEPENDFILE}: _EXTRADEPEND
184.endif
185
97192cdc 186.ORDER: ${_DEPENDFILES} ${DEPENDFILE} afterdepend
984263bc 187.else
67be5538 188depend: beforedepend _dependincs afterdepend
984263bc
MD
189.endif
190.if !target(beforedepend)
191beforedepend:
192.else
97192cdc 193.ORDER: beforedepend ${_DEPENDFILES} ${DEPENDFILE}
984263bc
MD
194.ORDER: beforedepend afterdepend
195.endif
196.if !target(afterdepend)
197afterdepend:
198.endif
199.endif
200
201.if !target(cleandepend)
202cleandepend:
203.if defined(SRCS)
204.if ${CTAGS:T} == "ctags"
6d68f83f 205 rm -f ${DEPENDFILE} ${_DEPENDFILES} tags
984263bc 206.elif ${CTAGS:T} == "gtags"
6d68f83f 207 rm -f ${DEPENDFILE} ${_DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
984263bc
MD
208.if defined(HTML)
209 rm -rf HTML
210.endif
211.endif
212.endif
213.endif
214
215.if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
216checkdpadd:
217.if ${OBJFORMAT} != aout
218 @ldadd=`echo \`for lib in ${DPADD} ; do \
219 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
220 done \`` ; \
221 ldadd1=`echo ${LDADD}` ; \
222 if [ "$$ldadd" != "$$ldadd1" ] ; then \
223 echo ${.CURDIR} ; \
224 echo "DPADD -> $$ldadd" ; \
225 echo "LDADD -> $$ldadd1" ; \
226 fi
227.else
228 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \
229 if [ "$$dpadd" != "${DPADD}" ] ; then \
230 echo ${.CURDIR} ; \
231 echo "LDADD -> $$dpadd" ; \
232 echo "DPADD = ${DPADD}" ; \
233 fi
234.endif
235.endif
67be5538
MD
236
237.if defined(INCS) && make(depend)
238
239_dependincs: ${INCS} ${SRCS}
240
241.ORDER: _dependincs depend
242
243.else
244
245_dependincs:
246
247.endif