bsd.dep.mk revision 105327
1# $FreeBSD: head/share/mk/bsd.dep.mk 105327 2002-10-17 13:48:13Z ru $
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#
25# +++ targets +++
26#
27#	cleandepend:
28#		Remove depend and tags file
29#
30#	depend:
31#		Make the dependencies for the source files, and store
32#		them in the file ${DEPENDFILE}.
33#
34#	tags:
35#		In "ctags" mode, create a tags file for the source files.
36#		In "gtags" mode, create a (GLOBAL) gtags file for the
37#		source files.  If HTML is defined, htags(1) is also run
38#		after gtags(1).
39
40.if !target(__<bsd.init.mk>__)
41.error bsd.dep.mk cannot be included directly.
42.endif
43
44CTAGS?=		gtags
45CTAGSFLAGS?=
46GTAGSFLAGS?=	-o
47HTAGSFLAGS?=
48
49.if ${CC} != "cc"
50MKDEPCMD?=	CC='${CC}' mkdep
51.else
52MKDEPCMD?=	mkdep
53.endif
54DEPENDFILE?=	.depend
55
56# Keep `tags' here, before SRCS are mangled below for `depend'.
57.if !target(tags) && defined(SRCS) && !defined(NOTAGS)
58tags: ${SRCS}
59.if ${CTAGS:T} == "ctags"
60	@${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
61	    ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
62.elif ${CTAGS:T} == "gtags"
63	@cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
64.if defined(HTML)
65	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
66.endif
67.endif
68.endif
69
70.if defined(SRCS)
71CLEANFILES?=
72
73.for _LSRC in ${SRCS:M*.l:N*/*}
74.for _LC in ${_LSRC:S/.l/.c/}
75${_LC}: ${_LSRC}
76	${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
77SRCS:=	${SRCS:S/${_LSRC}/${_LC}/}
78CLEANFILES:= ${CLEANFILES} ${_LC}
79.endfor
80.endfor
81
82.for _YSRC in ${SRCS:M*.y:N*/*}
83.for _YC in ${_YSRC:S/.y/.c/}
84SRCS:=	${SRCS:S/${_YSRC}/${_YC}/}
85CLEANFILES:= ${CLEANFILES} ${_YC}
86.if ${YFLAGS:M-d} != "" && ${SRCS:My.tab.h}
87.ORDER: ${_YC} y.tab.h
88${_YC} y.tab.h: ${_YSRC}
89	${YACC} ${YFLAGS} ${.ALLSRC}
90	cp y.tab.c ${_YC}
91SRCS:=	${SRCS} y.tab.h
92CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h
93.elif ${YFLAGS:M-d} != ""
94.for _YH in ${_YC:S/.c/.h/}
95.ORDER: ${_YC} ${_YH}
96${_YC} ${_YH}: ${_YSRC}
97	${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
98SRCS:=	${SRCS} ${_YH}
99CLEANFILES:= ${CLEANFILES} ${_YH}
100.endfor
101.else
102${_YC}: ${_YSRC}
103	${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
104.endif
105.endfor
106.endfor
107.endif
108
109.if !target(depend)
110.if defined(SRCS)
111depend: beforedepend ${DEPENDFILE} afterdepend
112
113# Different types of sources are compiled with slightly different flags.
114# Split up the sources, and filter out headers and non-applicable flags.
115${DEPENDFILE}: ${SRCS}
116	rm -f ${DEPENDFILE}
117.if ${SRCS:M*.[sS]} != ""
118	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
119	    ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
120	    ${AINC} \
121	    ${.ALLSRC:M*.[sS]}
122.endif
123.if ${SRCS:M*.c} != ""
124	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
125	    ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
126	    ${.ALLSRC:M*.c}
127.endif
128.if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cpp} != "" || \
129    ${SRCS:M*.cxx} != ""
130	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
131	    ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
132	    ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
133.endif
134.if ${SRCS:M*.m} != ""
135	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
136	    ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \
137	    ${OBJCFLAGS:M-Wno-import*} \
138	    ${.ALLSRC:M*.m}
139.endif
140.if target(_EXTRADEPEND)
141_EXTRADEPEND: .USE
142${DEPENDFILE}: _EXTRADEPEND
143.endif
144
145.ORDER: ${DEPENDFILE} afterdepend
146.else
147depend: beforedepend afterdepend
148.endif
149.if !target(beforedepend)
150beforedepend:
151.else
152.ORDER: beforedepend ${DEPENDFILE}
153.ORDER: beforedepend afterdepend
154.endif
155.if !target(afterdepend)
156afterdepend:
157.endif
158.endif
159
160.if !target(cleandepend)
161cleandepend:
162.if defined(SRCS)
163.if ${CTAGS:T} == "ctags"
164	rm -f ${DEPENDFILE} tags
165.elif ${CTAGS:T} == "gtags"
166	rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
167.if defined(HTML)
168	rm -rf HTML
169.endif
170.endif
171.endif
172.endif
173
174.if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
175checkdpadd:
176	@ldadd=`echo \`for lib in ${DPADD} ; do \
177		echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
178	done \`` ; \
179	ldadd1=`echo ${LDADD}` ; \
180	if [ "$$ldadd" != "$$ldadd1" ] ; then \
181		echo ${.CURDIR} ; \
182		echo "DPADD -> $$ldadd" ; \
183		echo "LDADD -> $$ldadd1" ; \
184	fi
185.endif
186