bsd.dep.mk revision 35838
1#	$Id: bsd.dep.mk,v 1.20 1998/05/06 18:43:58 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 !target(depend)
35.if defined(SRCS)
36depend: beforedepend ${DEPENDFILE} afterdepend _SUBDIR
37
38# Different types of sources are compiled with slightly different flags.
39# Split up the sources, and filter out headers and non-applicable flags.
40${DEPENDFILE}: ${SRCS}
41	rm -f ${DEPENDFILE}
42.if ${SRCS:M*.[sS]} != ""
43	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
44	    ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
45	    ${AINC} \
46	    ${.ALLSRC:M*.[sS]}
47.endif
48.if ${SRCS:M*.c} != ""
49	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
50	    ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
51	    ${.ALLSRC:M*.c}
52.endif
53.if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cxx} != ""
54	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
55	    ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
56	    ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}
57.endif
58.if target(_EXTRADEPEND)
59	cd ${.CURDIR}; ${MAKE} _EXTRADEPEND
60.endif
61
62.ORDER: ${DEPENDFILE} afterdepend
63.else
64depend: beforedepend afterdepend _SUBDIR
65.endif
66.if !target(beforedepend)
67beforedepend:
68.else
69.ORDER: beforedepend ${DEPENDFILE}
70.ORDER: beforedepend afterdepend
71.endif
72.if !target(afterdepend)
73afterdepend:
74.endif
75.endif
76
77.if defined(SRCS)
78CLEANFILES?=
79
80.for _LSRC in ${SRCS:M*.l:N*/*}
81.for _LC in ${_LSRC:S/.l/.c/}
82${_LC}: ${_LSRC}
83	${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
84SRCS:=	${SRCS:S/${_LSRC}/${_LC}/}
85CLEANFILES:= ${CLEANFILES} ${_LC}
86.endfor
87.endfor
88
89.for _YSRC in ${SRCS:M*.y:N*/*}
90.for _YC in ${_YSRC:S/.y/.c/}
91SRCS:=	${SRCS:S/${_YSRC}/${_YC}/}
92CLEANFILES:= ${CLEANFILES} ${_YC}
93.if ${YFLAGS:M-d} != "" && ${SRCS:My.tab.h}
94.ORDER: ${_YC} y.tab.h
95${_YC} y.tab.h: ${_YSRC}
96	${YACC} ${YFLAGS} ${.ALLSRC}
97	cp y.tab.c ${_YC}
98SRCS:=	${SRCS} y.tab.h
99CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h
100.elif ${YFLAGS:M-d} != ""
101.for _YH in ${_YC:S/.c/.h/}
102.ORDER: ${_YC} ${_YH}
103${_YC} ${_YH}: ${_YSRC}
104	${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
105SRCS:=	${SRCS} ${_YH}
106CLEANFILES:= ${CLEANFILES} ${_YH}
107.endfor
108.else
109${_YC}: ${_YSRC}
110	${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
111.endif
112.endfor
113.endfor
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