bsd.dep.mk revision 1.77 1 # $NetBSD: bsd.dep.mk,v 1.77 2013/03/05 21:59:01 christos Exp $
2
3 ##### Basic targets
4 realdepend: beforedepend .depend afterdepend
5 .ORDER: beforedepend .depend afterdepend
6
7 beforedepend .depend afterdepend: # ensure existence
8
9 ##### Default values
10 MKDEP?= mkdep
11 MKDEP_SUFFIXES?= .o
12
13 ##### Build rules
14 # some of the rules involve .h sources, so remove them from mkdep line
15
16 .if defined(SRCS) && !empty(SRCS)
17 __acpp_flags= ${_ASM_TRADITIONAL_CPP}
18
19 .if defined(NODPSRCS)
20 .for f in ${SRCS} ${DPSRCS}
21 .if "${NODPSRCS:M${f}}" == ""
22 __DPSRCS.all+= ${f:C/\.(c|m|s|S|C|cc|cpp|cxx)$/.d/}
23 .endif
24 .endfor
25 beforedepend: ${DPSRCS}
26 .else
27 __DPSRCS.all+= ${SRCS:C/\.(c|m|s|S|C|cc|cpp|cxx)$/.d/} \
28 ${DPSRCS:C/\.(c|m|s|S|C|cc|cpp|cxx)$/.d/}
29 .endif
30 __DPSRCS.d= ${__DPSRCS.all:O:u:M*.d}
31 __DPSRCS.notd= ${__DPSRCS.all:O:u:N*.d}
32
33 .NOPATH: .depend ${__DPSRCS.d}
34
35 .if !empty(__DPSRCS.d) # {
36 ${__DPSRCS.d}: ${__DPSRCS.notd} ${DPSRCS}
37 .endif # }
38
39 MKDEPSUFFLAGS=-s ${MKDEP_SUFFIXES:Q}
40
41 .if defined(MKDEPINCLUDES) && ${MKDEPINCLUDES} != "no"
42 .STALE:
43 @echo Rebuilding dependency file: ${.ALLSRC}
44 @rm -f ${.ALLSRC}
45 @(cd ${.CURDIR} && ${MAKE} depend)
46 _MKDEP_MERGEFLAGS=-i
47 _MKDEP_FILEFLAGS=${MKDEPSUFFLAGS}
48 .else
49 _MKDEP_MERGEFLAGS=${MKDEPSUFFLAGS}
50 _MKDEP_FILEFLAGS=
51 .endif
52
53 .depend: ${__DPSRCS.d}
54 ${_MKTARGET_CREATE}
55 rm -f .depend
56 ${MKDEP} ${_MKDEP_MERGEFLAGS} -d -f ${.TARGET} ${__DPSRCS.d}
57
58 .SUFFIXES: .d .s .S .c .C .cc .cpp .cxx .m
59
60 .c.d:
61 ${_MKTARGET_CREATE}
62 ${MKDEP} -f ${.TARGET} ${_MKDEP_FILEFLAGS} -- ${MKDEPFLAGS} \
63 ${CFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \
64 ${CPPFLAGS} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
65
66 .m.d:
67 ${_MKTARGET_CREATE}
68 ${MKDEP} -f ${.TARGET} ${_MKDEP_FILEFLAGS} -- ${MKDEPFLAGS} \
69 ${OBJCFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \
70 ${CPPFLAGS} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
71
72 .s.d .S.d:
73 ${_MKTARGET_CREATE}
74 ${MKDEP} -f ${.TARGET} ${_MKDEP_FILEFLAGS} -- ${MKDEPFLAGS} \
75 ${AFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \
76 ${CPPFLAGS} ${CPPFLAGS.${.IMPSRC:T}} ${__acpp_flags} ${.IMPSRC}
77
78 .C.d .cc.d .cpp.d .cxx.d:
79 ${_MKTARGET_CREATE}
80 ${MKDEP} -f ${.TARGET} ${_MKDEP_FILEFLAGS} -- ${MKDEPFLAGS} \
81 ${CXXFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \
82 ${CPPFLAGS} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
83
84 .endif # defined(SRCS) && !empty(SRCS) # }
85
86 ##### Clean rules
87 .if defined(SRCS) && !empty(SRCS)
88 CLEANDIRFILES+= .depend ${__DPSRCS.d} ${.CURDIR}/tags ${CLEANDEPEND}
89 .endif
90
91 ##### Custom rules
92 .if !target(tags)
93 tags: ${SRCS}
94 .if defined(SRCS) && !empty(SRCS)
95 -cd "${.CURDIR}"; ctags -f /dev/stdout ${.ALLSRC:N*.h} | \
96 ${TOOL_SED} "s;\${.CURDIR}/;;" > tags
97 .endif
98 .endif
99
100 ##### Pull in related .mk logic
101 .include <bsd.clean.mk>
102