don't bother resolving onbld python module deps
[unleashed.git] / share / mk / autodep.mk
blobb55b6d0605c7bea648429603ac173dc1e7745ff2
2 # RCSid:
3 # $Id: autodep.mk,v 1.36 2016/04/05 15:58:37 sjg Exp $
5 # @(#) Copyright (c) 1999-2010, Simon J. Gerraty
7 # This file is provided in the hope that it will
8 # be of use. There is absolutely NO WARRANTY.
9 # Permission to copy, redistribute or otherwise
10 # use this file is hereby granted provided that
11 # the above copyright notice and this notice are
12 # left intact.
14 # Please send copies of changes and bug-fixes to:
15 # sjg@crufty.net
17 # This module provides automagic dependency generation along the
18 # lines suggested in the GNU make.info
19 # The depend target is mainly for backwards compatibility,
20 # dependencies are normally updated as part of compilation.
22 .if !target(__${.PARSEFILE}__)
23 __${.PARSEFILE}__:
25 DEPENDFILE?= .depend
26 .for d in ${DEPENDFILE:N.depend}
27 # bmake only groks .depend
28 .if ${MAKE_VERSION} < 20160218
29 .-include <$d>
30 .else
31 .dinclude <$d>
32 .endif
33 .endfor
35 # it does nothing if SRCS is not defined or is empty
36 .if defined(SRCS) && !empty(SRCS)
37 DEPSRCS?=${SRCS}
38 __depsrcs=${DEPSRCS:M*.c}
39 __depsrcs+=${DEPSRCS:M*.y}
40 __depsrcs+=${DEPSRCS:M*.l}
41 __depsrcs+=${DEPSRCS:M*.s}
42 __depsrcs+=${DEPSRCS:M*.S}
43 __depsrcs+=${DEPSRCS:M*.cc}
44 __depsrcs+=${DEPSRCS:M*.cpp}
45 __depsrcs+=${DEPSRCS:M*.C}
46 __depsrcs+=${DEPSRCS:M*.cxx}
47 __depsrcs+=${DEPSRCS:M*.pc}
49 .for s in ${__depsrcs}
50 ${s:T:R}.dep: $s
51 .endfor
53 __depsrcs:=${__depsrcs:T:R:S/$/.dep/g}
54 # we also need to handle makefiles where the .dep's from __depsrcs
55 # don't match those from OBJS
56 # we avoid using := here, since the modifier applied to OBJS
57 # can cause trouble if there are any undefined vars in OBJS.
58 __dependsrcsx?= ${__depsrcs} ${OBJS:S/.o/.dep/}
59 __dependsrcs= ${__dependsrcsx:O:u}
61 # clean up any .c files we may have generated
62 #__gensrcs:= ${DEPSRCS:M*.y} ${DEPSRCS:M*.l}
63 #CLEANFILES+= ${__gensrcs:T:R:S/$/.c/g}
65 # set this to -MMD to ignore /usr/include
66 # actually it ignores <> so may not be a great idea
67 CFLAGS_MD?=-MD
68 # -MF etc not available on all gcc versions.
69 # we "fix" the .o later
70 CFLAGS_MF?=-MF ${.TARGET:T:R}.dep -MT ${.TARGET:T:R}.o
71 CFLAGS+= ${CFLAGS_MD} ${CFLAGS_MF}
72 RM?= rm
74 # watch out for people who don't use CPPFLAGS
75 CPPFLAGS_MD=${CFLAGS:M-[IUD]*} ${CPPFLAGS}
76 CXXFLAGS_MD=${CXXFLAGS:M-[IUD]*} ${CPPFLAGS}
78 # just in case these need to be different
79 CC_MD?=${CC}
80 CXX_MD?=${CXX}
82 # should have been set by sys.mk
83 CXX_SUFFIXES?= .cc .cpp .cxx .C
85 # so we can do an explicit make depend, but not otherwise
86 .if make(depend)
87 .SUFFIXES: .dep
89 .if empty(CFLAGS_MD)
90 .y.dep:
91 @echo updating dependencies for $<
92 @${YACC} ${YFLAGS} $<
93 @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} y.tab.c | sed '/:/s/^/$@ /' > $@" || { ${RM} -f y.tab.c $@; false; }
94 @${RM} -f y.tab.c
96 .l.dep:
97 @echo updating dependencies for $<
98 ${LEX} ${LFLAGS} $<
99 @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} lex.yy.c | sed '/:/s/^/$@ /' > $@" || { ${RM} -f lex.yy.c $@; false; }
100 @${RM} -f lex.yy.c
102 .c.dep:
103 @echo updating dependencies for $<
104 @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; }
106 .s.dep .S.dep:
107 @echo updating dependencies for $<
108 @${SHELL} -ec "${CC_MD} -M ${CPPFLAGS_MD} ${AINC} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; }
110 ${CXX_SUFFIXES:%=%.dep}:
111 @echo updating dependencies for $<
112 @${SHELL} -ec "${CXX_MD} -M ${CXXFLAGS_MD} $< | sed '/:/s/^/$@ /' > $@" || { ${RM} -f $@; false; }
113 .else
114 .y.dep:
115 ${YACC} ${YFLAGS} $<
116 ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} y.tab.c > $@ || { ${RM} -f y.tab.c $@; false; }
117 ${RM} -f y.tab.c
119 .l.dep:
120 ${LEX} ${LFLAGS} $<
121 ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} lex.yy.c > $@ || { ${RM} -f lex.yy.c $@; false; }
122 ${RM} -f lex.yy.c
124 .c.dep:
125 ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} $< > $@ || { ${RM} -f $@; false; }
127 .s.dep .S.dep:
128 ${CC_MD} ${CFLAGS_MD:S/D//} ${CPPFLAGS_MD} ${AINC} $< > $@ || { ${RM} -f $@; false; }
130 ${CXX_SUFFIXES:%=%.dep}:
131 ${CXX_MD} ${CFLAGS_MD:S/D//} ${CXXFLAGS_MD} $< > $@ || { ${RM} -f $@; false; }
132 .endif
134 .if !target(depend)
135 depend: beforedepend ${DEPENDFILE} afterdepend _SUBDIRUSE
137 ${DEPENDFILE}: ${DEPSRCS} ${__dependsrcs}
138 .NOPATH: ${__dependsrcs}
139 .OPTIONAL: ${__dependsrcs}
140 .endif
141 .endif # make(depend)
143 .if empty(CFLAGS_MD)
144 # make sure the .dep's are generated/updated
145 ${PROG} ${_LIBS}: ${DEPENDFILE}
146 .endif
148 .ORDER: beforedepend ${DEPENDFILE} afterdepend
150 .if ${.OBJDIR} != ${.CURDIR}
151 __depfiles= *.dep
152 .else
153 __depfiles= ${__dependsrcs}
154 .endif
156 DEPCLEANFILES= ${DEPENDFILE} ${__depfiles} y.tab.dep *.tmp.dep
158 cleandir: cleanautodepend
159 cleanautodepend:
160 ${RM} -f ${DEPCLEANFILES}
162 CLEANFILES+= ${DEPCLEANFILES}
164 .if defined(__dependsrcs) && !empty(__dependsrcs)
165 .if make(depend) || !(make(clean*) || make(destroy*) || make(obj) || make(*install) || make(install-*))
166 # this ensures we do the right thing if only building a shared or
167 # profiled lib
168 OBJ_EXTENSIONS?=.o .po .so .So
169 MDLIB_SED= -e '/:/s,^\([^\.:]*\)\.[psS]*o,${OBJ_EXTENSIONS:S,^,\1,},'
170 .ifdef NOMD_SED
171 .ifdef LIB
172 MD_SED=sed ${MDLIB_SED}
173 .else
174 MD_SED=cat
175 .endif
176 .else
177 # arrange to put some variable names into ${DEPENDFILE}
178 .ifdef LIB
179 MD_SED=sed ${MDLIB_SED}
180 .else
181 MD_SED=sed
182 .endif
183 SUBST_DEPVARS+= SB TOP BACKING SRC SRCDIR BASE BASEDIR
184 .for v in ${SUBST_DEPVARS}
185 .if defined(${v}) && !empty(${v})
186 MD_SED+= -e 's,${$v},$${$v},'
187 .endif
188 .endfor
189 .endif
190 .if (${MD_SED} == "sed")
191 MD_SED=cat
192 .endif
194 # this will be done whenever make finishes successfully
195 .if ${MAKE_VERSION:U0:[1]:C/.*-//} < 20050530
196 .END:
197 .else
198 .END: ${DEPENDFILE}
199 # we do not want to trigger building .dep's just use them if they exist
200 ${DEPENDFILE}: ${__dependsrcs:@d@${exists($d):?$d:}@}
201 .endif
202 -@${MD_SED} ${__depfiles} > ${DEPENDFILE}.new 2> /dev/null && \
203 test -s ${DEPENDFILE}.new && mv ${DEPENDFILE}.new ${DEPENDFILE}; \
204 ${RM} -f ${DEPENDFILE}.new
205 .endif
206 .endif
207 .else
208 depend: beforedepend afterdepend _SUBDIRUSE
209 .endif
211 .if !target(beforedepend)
212 beforedepend:
213 .endif
214 .if !target(afterdepend)
215 afterdepend:
216 .endif
218 .endif