]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - share/mk/bsd.dep.mk
Fix mismerge in r294738. No MK_FAST_DEPEND on stable/9
[FreeBSD/stable/9.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}' mkdep
53 .else
54 MKDEPCMD?=      mkdep
55 .endif
56 DEPENDFILE?=    .depend
57
58 # Keep `tags' here, before SRCS are mangled below for `depend'.
59 .if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
60 tags: ${SRCS}
61 .if ${CTAGS:T} == "gtags"
62         @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
63 .if defined(HTML)
64         @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
65 .endif
66 .else
67         @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
68             ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
69 .endif
70 .endif
71
72 .if defined(SRCS)
73 CLEANFILES?=
74
75 .if !exists(${.OBJDIR}/${DEPENDFILE})
76 .for _S in ${SRCS:N*.[hly]}
77 ${_S:R}.o: ${_S}
78 .endfor
79 .endif
80
81 .for _LSRC in ${SRCS:M*.l:N*/*}
82 .for _LC in ${_LSRC:R}.c
83 ${_LC}: ${_LSRC}
84         ${LEX} ${LFLAGS} -o${.TARGET} ${.ALLSRC}
85 .if !exists(${.OBJDIR}/${DEPENDFILE})
86 ${_LC:R}.o: ${_LC}
87 .endif
88 SRCS:=  ${SRCS:S/${_LSRC}/${_LC}/}
89 CLEANFILES+= ${_LC}
90 .endfor
91 .endfor
92
93 .for _YSRC in ${SRCS:M*.y:N*/*}
94 .for _YC in ${_YSRC:R}.c
95 SRCS:=  ${SRCS:S/${_YSRC}/${_YC}/}
96 CLEANFILES+= ${_YC}
97 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
98 .ORDER: ${_YC} y.tab.h
99 ${_YC} y.tab.h: ${_YSRC}
100         ${YACC} ${YFLAGS} ${.ALLSRC}
101         cp y.tab.c ${_YC}
102 CLEANFILES+= y.tab.c y.tab.h
103 .elif !empty(YFLAGS:M-d)
104 .for _YH in ${_YC:R}.h
105 .ORDER: ${_YC} ${_YH}
106 ${_YC} ${_YH}: ${_YSRC}
107         ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
108 SRCS+=  ${_YH}
109 CLEANFILES+= ${_YH}
110 .endfor
111 .else
112 ${_YC}: ${_YSRC}
113         ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
114 .endif
115 .if !exists(${.OBJDIR}/${DEPENDFILE})
116 ${_YC:R}.o: ${_YC}
117 .endif
118 .endfor
119 .endfor
120 .endif
121
122 .if !target(depend)
123 .if defined(SRCS)
124 depend: beforedepend ${DEPENDFILE} afterdepend
125
126 # Tell bmake not to look for generated files via .PATH
127 .NOPATH: ${DEPENDFILE}
128
129 # Capture -include from CFLAGS.
130 # This could be simpler with bmake :tW but needs to support fmake for MFC.
131 _CFLAGS_INCLUDES= ${CFLAGS:Q:S/\\ /,/g:C/-include,/-include%/g:C/,/ /g:M-include*:C/%/ /g}
132 _CXXFLAGS_INCLUDES= ${CXXFLAGS:Q:S/\\ /,/g:C/-include,/-include%/g:C/,/ /g:M-include*:C/%/ /g}
133 # XXX: Temporary hack to workaround .depend files not tracking -include
134 .if !empty(_CFLAGS_INCLUDES)
135 ${OBJS} ${POBJS} ${SOBJS}: ${_CFLAGS_INCLUDES:M*.h}
136 .endif
137 .if !empty(_CXXFLAGS_INCLUDES)
138 ${OBJS} ${POBJS} ${SOBJS}: ${_CXXFLAGS_INCLUDES:M*.h}
139 .endif
140
141 # Different types of sources are compiled with slightly different flags.
142 # Split up the sources, and filter out headers and non-applicable flags.
143 MKDEP_CFLAGS=   ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
144                 ${CFLAGS:M-ansi} ${_CFLAGS_INCLUDES}
145 MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
146                 ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*} \
147                 ${_CXXFLAGS_INCLUDES}
148
149 DPSRCS+= ${SRCS}
150 ${DEPENDFILE}: ${DPSRCS}
151         rm -f ${DEPENDFILE}
152 .if !empty(DPSRCS:M*.[cS])
153         ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
154             ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
155 .endif
156 .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
157     !empty(DPSRCS:M*.cxx)
158         ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
159             ${MKDEP_CXXFLAGS} \
160             ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
161 .endif
162 .if target(_EXTRADEPEND)
163 _EXTRADEPEND: .USE
164 ${DEPENDFILE}: _EXTRADEPEND
165 .endif
166
167 .ORDER: ${DEPENDFILE} afterdepend
168 .else
169 depend: beforedepend afterdepend
170 .endif
171 .if !target(beforedepend)
172 beforedepend:
173 .else
174 .ORDER: beforedepend ${DEPENDFILE}
175 .ORDER: beforedepend afterdepend
176 .endif
177 .if !target(afterdepend)
178 afterdepend:
179 .endif
180 .endif
181
182 .if !target(cleandepend)
183 cleandepend:
184 .if defined(SRCS)
185 .if ${CTAGS:T} == "gtags"
186         rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
187 .if defined(HTML)
188         rm -rf HTML
189 .endif
190 .else
191         rm -f ${DEPENDFILE} tags
192 .endif
193 .endif
194 .endif
195
196 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
197 _LDADD_FROM_DPADD=      ${DPADD:C;^/usr/lib/lib(.*)\.a$;-l\1;}
198 _LDADD_CANONICALIZED=   ${LDADD:S/$//}
199 checkdpadd:
200 .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
201         @echo ${.CURDIR}
202         @echo "DPADD -> ${_LDADD_FROM_DPADD}"
203         @echo "LDADD -> ${_LDADD_CANONICALIZED}"
204 .endif
205 .endif