bsd.*.mk: allow the setting of separate compile flags for files
[dragonfly.git] / share / mk / bsd.dep.mk
blob6ad6e12ec4edb8c0b69be655c36f8a2b7460b3ce
1 # $FreeBSD: src/share/mk/bsd.dep.mk,v 1.27.2.3 2002/12/23 16:33:37 ru Exp $
2 # $DragonFly: src/share/mk/bsd.dep.mk,v 1.9 2006/02/13 13:27:20 corecode Exp $
4 # The include file <bsd.dep.mk> handles Makefile dependencies.
7 # +++ variables +++
9 # CTAGS A tags file generation program [gtags]
11 # CTAGSFLAGS Options for ctags(1) [not set]
13 # DEPENDFILE dependencies file [.depend]
15 # GTAGSFLAGS Options for gtags(1) [-o]
17 # HTAGSFLAGS Options for htags(1) [not set]
19 # MKDEP Options for ${MKDEPCMD} [not set]
21 # MKDEPCMD Makefile dependency list program [mkdep]
23 # SRCS List of source files (c, c++, assembler)
26 # +++ targets +++
28 # cleandepend:
29 # Remove depend and tags file
31 # depend:
32 # Make the dependencies for the source files, and store
33 # them in the file ${DEPENDFILE}.
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).
41 .if !target(__<bsd.init.mk>__)
42 .error bsd.dep.mk cannot be included directly.
43 .endif
45 CTAGS?= gtags
46 CTAGSFLAGS?=
47 GTAGSFLAGS?= -o
48 HTAGSFLAGS?=
50 MKDEPCMD?= mkdep
51 DEPENDFILE?= .depend
53 # Keep `tags' here, before SRCS are mangled below for `depend'.
54 .if !target(tags) && defined(SRCS) && !defined(NOTAGS)
55 tags: ${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
67 .if defined(SRCS)
68 CLEANFILES?=
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}
74 SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
75 CLEANFILES:= ${CLEANFILES} ${_LC}
76 .endfor
77 .endfor
79 .for _YSRC in ${SRCS:M*.y:N*/*}
80 .for _YC in ${_YSRC:S/.y/.c/}
81 SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
82 CLEANFILES:= ${CLEANFILES} ${_YC}
83 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
84 .ORDER: ${_YC} y.tab.h
85 ${_YC} y.tab.h: ${_YSRC}
86 ${YACC} ${YFLAGS} ${.ALLSRC}
87 cp y.tab.c ${_YC}
88 SRCS:= ${SRCS} y.tab.h
89 CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h
90 .elif !empty(YFLAGS:M-d)
91 .for _YH in ${_YC:S/.c/.h/}
92 .ORDER: ${_YC} ${_YH}
93 ${_YC} ${_YH}: ${_YSRC}
94 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
95 SRCS:= ${SRCS} ${_YH}
96 CLEANFILES:= ${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 ${DEPENDFILE} afterdepend
110 # Different types of sources are compiled with slightly different flags.
111 # Split up the sources, and filter out headers and non-applicable flags.
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
122 _DEPENDFILES= .depend__ ${FLAGS_GROUPS:S/^/.depend_/g}
123 .ORDER: ${_DEPENDFILES}
125 ${DEPENDFILE}: ${_DEPENDFILES}
126 cat ${_DEPENDFILES} > ${.TARGET}
127 -rm -f ${_DEPENDFILES}
129 .for _FG in _ ${FLAGS_GROUPS}
130 .depend_${_FG}: ${${_FG}_FLAGS_FILES}
131 -rm -f ${.TARGET}
132 -> ${.TARGET}
133 .if ${${_FG}_FLAGS_FILES:M*.[sS]} != ""
134 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
135 ${${_FG}_FLAGS} \
136 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
137 ${AINC} \
138 ${.ALLSRC:M*.[sS]}
139 .endif
140 .if ${${_FG}_FLAGS_FILES:M*.c} != ""
141 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
142 ${${_FG}_FLAGS} \
143 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
144 ${CFLAGS:M-std=*} \
145 ${.ALLSRC:M*.c}
146 .endif
147 .if ${${_FG}_FLAGS_FILES:M*.cc} != "" || \
148 ${${_FG}_FLAGS_FILES:M*.C} != "" || \
149 ${${_FG}_FLAGS_FILES:M*.cpp} != "" || \
150 ${${_FG}_FLAGS_FILES:M*.cxx} != ""
151 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
152 ${${_FG}_FLAGS} \
153 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
154 ${CXXFLAGS:M-std=*} \
155 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
156 .endif
157 .if ${${_FG}_FLAGS_FILES:M*.m} != ""
158 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \
159 ${${_FG}_FLAGS} \
160 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \
161 ${OBJCFLAGS:M-Wno-import*} \
162 ${.ALLSRC:M*.m}
163 .endif
164 .endfor
166 .if target(_EXTRADEPEND)
167 _EXTRADEPEND: .USE
168 ${DEPENDFILE}: _EXTRADEPEND
169 .endif
171 .ORDER: ${DEPENDFILE} afterdepend
172 .else
173 depend: beforedepend afterdepend
174 .endif
175 .if !target(beforedepend)
176 beforedepend:
177 .else
178 .ORDER: beforedepend ${DEPENDFILE}
179 .ORDER: beforedepend afterdepend
180 .endif
181 .if !target(afterdepend)
182 afterdepend:
183 .endif
184 .endif
186 .if !target(cleandepend)
187 cleandepend:
188 .if defined(SRCS)
189 .if ${CTAGS:T} == "ctags"
190 rm -f ${DEPENDFILE} ${_DEPENDFILES} tags
191 .elif ${CTAGS:T} == "gtags"
192 rm -f ${DEPENDFILE} ${_DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
193 .if defined(HTML)
194 rm -rf HTML
195 .endif
196 .endif
197 .endif
198 .endif
200 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
201 checkdpadd:
202 .if ${OBJFORMAT} != aout
203 @ldadd=`echo \`for lib in ${DPADD} ; do \
204 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
205 done \`` ; \
206 ldadd1=`echo ${LDADD}` ; \
207 if [ "$$ldadd" != "$$ldadd1" ] ; then \
208 echo ${.CURDIR} ; \
209 echo "DPADD -> $$ldadd" ; \
210 echo "LDADD -> $$ldadd1" ; \
212 .else
213 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \
214 if [ "$$dpadd" != "${DPADD}" ] ; then \
215 echo ${.CURDIR} ; \
216 echo "LDADD -> $$dpadd" ; \
217 echo "DPADD = ${DPADD}" ; \
219 .endif
220 .endif