bsd.dep.mk revision 1.43 1 # $NetBSD: bsd.dep.mk,v 1.43 2003/06/11 17:24:55 christos Exp $
2
3 ##### Basic targets
4 .PHONY: cleandepend
5 cleandir: cleandepend
6 realdepend: beforedepend .depend afterdepend
7 .ORDER: beforedepend .depend afterdepend
8
9 beforedepend .depend afterdepend: # ensure existence
10
11 ##### Default values
12 MKDEP?= mkdep
13
14 ##### Build rules
15 # some of the rules involve .h sources, so remove them from mkdep line
16
17 .if defined(SRCS)
18 __acpp_flags= -traditional-cpp
19 .NOPATH: .depend
20 .if empty(HOST_CYGWIN)
21 .depend: ${SRCS} ${DPSRCS}
22 @rm -f .depend
23 @files="${.ALLSRC:M*.s} ${.ALLSRC:M*.S}"; \
24 if [ "$$files" != " " ]; then \
25 echo ${MKDEP} -a ${MKDEPFLAGS} \
26 ${AFLAGS:M-[ID]*:Q} ${CPPFLAGS:Q} ${__acpp_flags} ${AINC:Q} \
27 $$files; \
28 ${MKDEP} -a ${MKDEPFLAGS} \
29 ${AFLAGS:M-[ID]*} ${CPPFLAGS} ${__acpp_flags} ${AINC} $$files; \
30 fi
31 @files="${.ALLSRC:M*.c}"; \
32 if [ "$$files" != "" ]; then \
33 echo ${MKDEP} -a ${MKDEPFLAGS} \
34 ${CFLAGS:M-[ID]*:Q} ${CPPFLAGS:Q} $$files; \
35 ${MKDEP} -a ${MKDEPFLAGS} \
36 ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \
37 fi
38 @files="${.ALLSRC:M*.m}"; \
39 if [ "$$files" != "" ]; then \
40 echo ${MKDEP} -a ${MKDEPFLAGS} \
41 ${OBJCFLAGS:M-[ID]*:Q} ${CPPFLAGS:Q} $$files; \
42 ${MKDEP} -a ${MKDEPFLAGS} \
43 ${OBJCFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \
44 fi
45 @files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx} ${.ALLSRC:M*.cpp"; \
46 if [ "$$files" != " " ]; then \
47 echo ${MKDEP} -a ${MKDEPFLAGS} \
48 ${CXXFLAGS:M-[ID]*:Q} ${CPPFLAGS:Q} $$files; \
49 ${MKDEP} -a ${MKDEPFLAGS} \
50 ${CXXFLAGS:M-[ID]*} ${DESTDIR:D-nostdinc++ ${CPPFLAG_ISYSTEM} ${DESTDIR}/usr/include/g++} ${CPPFLAGS} $$files; \
51 fi
52 .else
53 #
54 # Cygwin workarounds for limited environment & command line space
55 #
56
57 SRCS_S = ${SRCS:M*.[sS]} ${DPSRCS:M*.[sS]}
58 SRCS_C = ${SRCS:M*.c} ${DPSRCS:M*.c}
59 SRCS_M = ${SRCS:M*.m} ${DPSRCS:M*.m}
60 SRCS_X = ${SRCS:M*.C} ${DPSRCS:M*.C} \
61 ${SRCS:M*.cc} ${DPSRCS:M*.cc} \
62 ${SRCS:M*.cxx} ${DPSRCS:M*.cxx}
63
64 .depend: ${SRCS} ${DPSRCS} \
65 ${SRCS_S:C/(.*)/\1.dep/g:S/^.dep$//g} \
66 ${SRCS_C:C/(.*)/\1.dep/g:S/^.dep$//g} \
67 ${SRCS_M:C/(.*)/\1.dep/g:S/^.dep$//g} \
68 ${SRCS_X:C/(.*)/\1.dep/g:S/^.dep$//g}
69 @rm -f .depend
70 @cat ${.ALLSRC:M*.dep} > .depend
71
72 .for F in ${SRCS_S:O:u}
73 .NOPATH: ${F:C/(.*)/\1.dep/g}
74 ${F:C/(.*)/\1.dep/g}: ${F}
75 @echo ${MKDEP} -a -f $@ ${MKDEPFLAGS} \
76 ${AFLAGS:M-[ID]*:Q} ${CPPFLAGS:Q} ${__acpp_flags} ${AINC:Q} \
77 ${.ALLSRC}
78 @${MKDEP} -a -f $@ ${MKDEPFLAGS} ${AFLAGS:M-[ID]*} ${CPPFLAGS} \
79 ${__acpp_flags} ${AINC} ${.ALLSRC}
80 .endfor
81
82 .for F in ${SRCS_C:O:u}
83 .NOPATH: ${F:C/(.*)/\1.dep/g}
84 ${F:C/(.*)/\1.dep/g}: ${F}
85 @echo ${MKDEP} -a -f $@ ${MKDEPFLAGS} ${CFLAGS:M-[ID]*:Q} \
86 ${CPPFLAGS:Q} ${.ALLSRC}
87 @${MKDEP} -a -f $@ ${MKDEPFLAGS} ${CFLAGS:M-[ID]*} ${CPPFLAGS} \
88 ${.ALLSRC}
89 .endfor
90
91 .for F in ${SRCS_M:O:u}
92 .NOPATH: ${F:C/(.*)/\1.dep/g}
93 ${F:C/(.*)/\1.dep/g}: ${F}
94 @echo ${MKDEP} -a -f $@ ${MKDEPFLAGS} ${OBJCFLAGS:M-[ID]*:Q} \
95 ${CPPFLAGS:Q} ${.ALLSRC}
96 @${MKDEP} -a -f $@ ${MKDEPFLAGS} ${OBJCFLAGS:M-[ID]*} ${CPPFLAGS} \
97 ${.ALLSRC}
98 .endfor
99
100 .for F in ${SRCS_X:O:u}
101 .NOPATH: ${F:C/(.*)/\1.dep/g}
102 ${F:C/(.*)/\1.dep/g}: ${F}
103 @echo ${MKDEP} -a -f $@ ${MKDEPFLAGS} \
104 ${CXXFLAGS:M-[ID]*:Q} ${CPPFLAGS:Q} ${.ALLSRC}
105 @${MKDEP} -a -f $@ ${MKDEPFLAGS} ${CXXFLAGS:M-[ID]*} \
106 ${DESTDIR:D-nostdinc++ ${CPPFLAG_ISYSTEM} \
107 ${DESTDIR}/usr/include/g++} ${CPPFLAGS} ${.ALLSRC}
108 .endfor
109
110 .endif # Cygwin
111 .endif # defined(SRCS)
112
113 ##### Clean rules
114 cleandepend:
115 .if defined(SRCS)
116 rm -f .depend ${.CURDIR}/tags ${CLEANDEPEND}
117 .endif
118
119 ##### Custom rules
120 .if !target(tags)
121 tags: ${SRCS}
122 .if defined(SRCS)
123 -cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:N*.h} | \
124 sed "s;\${.CURDIR}/;;" > tags
125 .endif
126 .endif
127