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