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