bsd.dep.mk revision 35951
1#	$Id: bsd.dep.mk,v 1.21 1998/05/08 06:31:05 bde Exp $
2#
3# The include file <bsd.dep.mk> handles Makefile dependencies.
4#
5#
6# +++ variables +++
7#
8# DEPENDFILE	dependencies file [.depend]
9#
10# MKDEP		Options for ${MKDEPCMD} [not set]
11#
12# MKDEPCMD	Makefile dependency list program [mkdep]
13# 
14# SRCS          List of source files (c, c++, assembler)
15#
16#
17# +++ targets +++
18#
19#	cleandepend:
20#		Remove depend and tags file
21#
22#	depend:
23#		Make the dependencies for the source files, and store
24#		them in the file ${DEPENDFILE}.
25#
26#	tags:
27#		Create a (GLOBAL) gtags file for the source files.
28#		If HTML is defined, htags is also run after gtags.
29
30
31MKDEPCMD?=	mkdep
32DEPENDFILE?=	.depend
33
34.if defined(SRCS)
35CLEANFILES?=
36
37.for _LSRC in ${SRCS:M*.l:N*/*}
38.for _LC in ${_LSRC:S/.l/.c/}
39${_LC}: ${_LSRC}
40	${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
41SRCS:=	${SRCS:S/${_LSRC}/${_LC}/}
42CLEANFILES:= ${CLEANFILES} ${_LC}
43.endfor
44.endfor
45
46.for _YSRC in ${SRCS:M*.y:N*/*}
47.for _YC in ${_YSRC:S/.y/.c/}
48SRCS:=	${SRCS:S/${_YSRC}/${_YC}/}
49CLEANFILES:= ${CLEANFILES} ${_YC}
50.if ${YFLAGS:M-d} != "" && ${SRCS:My.tab.h}
51.ORDER: ${_YC} y.tab.h
52${_YC} y.tab.h: ${_YSRC}
53	${YACC} ${YFLAGS} ${.ALLSRC}
54	cp y.tab.c ${_YC}
55SRCS:=	${SRCS} y.tab.h
56CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h
57.elif ${YFLAGS:M-d} != ""
58.for _YH in ${_YC:S/.c/.h/}
59.ORDER: ${_YC} ${_YH}
60${_YC} ${_YH}: ${_YSRC}
61	${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
62SRCS:=	${SRCS} ${_YH}
63CLEANFILES:= ${CLEANFILES} ${_YH}
64.endfor
65.else
66${_YC}: ${_YSRC}
67	${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
68.endif
69.endfor
70.endfor
71.endif
72
73.if !target(depend)
74.if defined(SRCS)
75depend: beforedepend ${DEPENDFILE} afterdepend _SUBDIR
76
77# Different types of sources are compiled with slightly different flags.
78# Split up the sources, and filter out headers and non-applicable flags.
79${DEPENDFILE}: ${SRCS}
80	rm -f ${DEPENDFILE}
81.if ${SRCS:M*.[sS]} != ""
82	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
83	    ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
84	    ${AINC} \
85	    ${.ALLSRC:M*.[sS]}
86.endif
87.if ${SRCS:M*.c} != ""
88	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
89	    ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
90	    ${.ALLSRC:M*.c}
91.endif
92.if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cxx} != ""
93	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
94	    ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
95	    ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}
96.endif
97.if target(_EXTRADEPEND)
98	cd ${.CURDIR}; ${MAKE} _EXTRADEPEND
99.endif
100
101.ORDER: ${DEPENDFILE} afterdepend
102.else
103depend: beforedepend afterdepend _SUBDIR
104.endif
105.if !target(beforedepend)
106beforedepend:
107.else
108.ORDER: beforedepend ${DEPENDFILE}
109.ORDER: beforedepend afterdepend
110.endif
111.if !target(afterdepend)
112afterdepend:
113.endif
114.endif
115
116.if defined(NOTAGS)
117tags:
118.endif
119
120.if !target(tags)
121tags: ${SRCS} _SUBDIR
122	@cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR}
123.if defined(HTML)
124	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
125.endif
126.endif
127
128.if !target(cleandepend)
129cleandepend: _SUBDIR
130.if defined(SRCS)
131	rm -f ${DEPENDFILE} ${.OBJDIR}/GRTAGS ${.OBJDIR}/GSYMS ${.OBJDIR}/GTAGS
132.if defined(HTML)
133	rm -rf ${.OBJDIR}/HTML
134.endif
135.endif
136.endif
137