Merge from vendor branch GROFF:
[dragonfly.git] / share / mk / bsd.dep.mk
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.7 2004/11/13 17:31:00 joerg Exp $
3 #
4 # The include file <bsd.dep.mk> handles Makefile dependencies.
5 #
6 #
7 # +++ variables +++
8 #
9 # CTAGS         A tags file generation program [gtags]
10 #
11 # CTAGSFLAGS    Options for ctags(1) [not set]
12 #
13 # DEPENDFILE    dependencies file [.depend]
14 #
15 # GTAGSFLAGS    Options for gtags(1) [-o]
16 #
17 # HTAGSFLAGS    Options for htags(1) [not set]
18 #
19 # MKDEP         Options for ${MKDEPCMD} [not set]
20 #
21 # MKDEPCMD      Makefile dependency list program [mkdep]
22
23 # SRCS          List of source files (c, c++, assembler)
24 #
25 #
26 # +++ targets +++
27 #
28 #       cleandepend:
29 #               Remove depend and tags file
30 #
31 #       depend:
32 #               Make the dependencies for the source files, and store
33 #               them in the file ${DEPENDFILE}.
34 #
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).
40
41 .if !target(__<bsd.init.mk>__)
42 .error bsd.dep.mk cannot be included directly.
43 .endif
44
45 CTAGS?=         gtags
46 CTAGSFLAGS?=
47 GTAGSFLAGS?=    -o
48 HTAGSFLAGS?=
49
50 MKDEPCMD?=      mkdep
51 DEPENDFILE?=    .depend
52
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
66
67 .if defined(SRCS)
68 CLEANFILES?=
69
70 .for _PSRC in ${SRCS:M*.patch}
71 .for _PC in ${_PSRC:T:C/(\.no_obj)?\.patch$//:S|,|/|g}
72
73 ${_PC}: ${CONTRIBDIR}/${_PC} ${_PSRC}
74         mkdir -p ${.TARGET:H}
75         patch -o ${.TARGET} -i ${.ALLSRC:M*.patch} ${CONTRIBDIR}/${.TARGET}
76
77 SRCS:=  ${SRCS:N${_PC}:S|${_PSRC}|${_PC}|}
78 CLEANFILES:=    ${CLEANFILES} ${_PC}
79 .endfor
80 .endfor
81  
82
83 .for _LSRC in ${SRCS:M*.l:N*/*}
84 .for _LC in ${_LSRC:S/.l/.c/}
85 ${_LC}: ${_LSRC}
86         ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
87 SRCS:=  ${SRCS:S/${_LSRC}/${_LC}/}
88 CLEANFILES:= ${CLEANFILES} ${_LC}
89 .endfor
90 .endfor
91
92 .for _YSRC in ${SRCS:M*.y:N*/*}
93 .for _YC in ${_YSRC:S/.y/.c/}
94 SRCS:=  ${SRCS:S/${_YSRC}/${_YC}/}
95 CLEANFILES:= ${CLEANFILES} ${_YC}
96 .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
97 .ORDER: ${_YC} y.tab.h
98 ${_YC} y.tab.h: ${_YSRC}
99         ${YACC} ${YFLAGS} ${.ALLSRC}
100         cp y.tab.c ${_YC}
101 SRCS:=  ${SRCS} y.tab.h
102 CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h
103 .elif !empty(YFLAGS:M-d)
104 .for _YH in ${_YC:S/.c/.h/}
105 .ORDER: ${_YC} ${_YH}
106 ${_YC} ${_YH}: ${_YSRC}
107         ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
108 SRCS:=  ${SRCS} ${_YH}
109 CLEANFILES:= ${CLEANFILES} ${_YH}
110 .endfor
111 .else
112 ${_YC}: ${_YSRC}
113         ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
114 .endif
115 .endfor
116 .endfor
117 .endif
118
119 .if !target(depend)
120 .if defined(SRCS)
121 depend: beforedepend ${DEPENDFILE} afterdepend
122
123 # Different types of sources are compiled with slightly different flags.
124 # Split up the sources, and filter out headers and non-applicable flags.
125 ${DEPENDFILE}: ${SRCS}
126         rm -f ${DEPENDFILE}
127 .if ${SRCS:M*.[sS]} != ""
128         ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
129             ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
130             ${AINC} \
131             ${.ALLSRC:M*.[sS]}
132 .endif
133 .if ${SRCS:M*.c} != ""
134         ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
135             ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
136             ${.ALLSRC:M*.c}
137 .endif
138 .if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cpp} != "" || \
139     ${SRCS:M*.cxx} != ""
140         ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
141             ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
142             ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
143 .endif
144 .if ${SRCS:M*.m} != ""
145         ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
146             ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \
147             ${OBJCFLAGS:M-Wno-import*} \
148             ${.ALLSRC:M*.m}
149 .endif
150 .if target(_EXTRADEPEND)
151 _EXTRADEPEND: .USE
152 ${DEPENDFILE}: _EXTRADEPEND
153 .endif
154
155 .ORDER: ${DEPENDFILE} afterdepend
156 .else
157 depend: beforedepend afterdepend
158 .endif
159 .if !target(beforedepend)
160 beforedepend:
161 .else
162 .ORDER: beforedepend ${DEPENDFILE}
163 .ORDER: beforedepend afterdepend
164 .endif
165 .if !target(afterdepend)
166 afterdepend:
167 .endif
168 .endif
169
170 .if !target(cleandepend)
171 cleandepend:
172 .if defined(SRCS)
173 .if ${CTAGS:T} == "ctags"
174         rm -f ${DEPENDFILE} tags
175 .elif ${CTAGS:T} == "gtags"
176         rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
177 .if defined(HTML)
178         rm -rf HTML
179 .endif
180 .endif
181 .endif
182 .endif
183
184 .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
185 checkdpadd:
186 .if ${OBJFORMAT} != aout
187         @ldadd=`echo \`for lib in ${DPADD} ; do \
188                 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
189         done \`` ; \
190         ldadd1=`echo ${LDADD}` ; \
191         if [ "$$ldadd" != "$$ldadd1" ] ; then \
192                 echo ${.CURDIR} ; \
193                 echo "DPADD -> $$ldadd" ; \
194                 echo "LDADD -> $$ldadd1" ; \
195         fi
196 .else
197         @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \
198         if [ "$$dpadd" != "${DPADD}" ] ; then \
199                 echo ${.CURDIR} ; \
200                 echo "LDADD -> $$dpadd" ; \
201                 echo "DPADD =  ${DPADD}" ; \
202         fi
203 .endif
204 .endif