bsd.dep.mk revision 24861
1#	$Id: bsd.dep.mk,v 1.11 1997/04/09 16:10:23 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# some of the rules involve .h sources, so remove them from mkdep line
35.if !target(depend)
36depend: beforedepend ${DEPENDFILE} afterdepend _SUBDIR
37.if defined(SRCS)
38
39# .if defined ${SRCS:M*.[sS]} does not work
40__depend_s=	${SRCS:M*.[sS]}
41__depend_c=	${SRCS:M*.c}
42__depend_cc=	${SRCS:M*.cc} ${SRCS:M*.C} ${SRCS:M*.cxx}
43
44${DEPENDFILE}: ${SRCS}
45	rm -f ${DEPENDFILE}
46.if defined(__depend_s) && !empty(__depend_s)
47	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} ${CFLAGS:M-[ID]*} ${AINC} \
48		${.ALLSRC:M*.[sS]}
49.endif
50.if defined(__depend_c) && !empty(__depend_c)
51	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} ${CFLAGS:M-[ID]*} \
52		${.ALLSRC:M*.c}
53.endif
54.if defined(__depend_cc) && !empty(__depend_cc)
55	${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
56		${CXXFLAGS:M-nostd*} ${CXXFLAGS:M-[ID]*} \
57		${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}
58.endif
59.if target(_EXTRADEPEND)
60	cd ${.CURDIR}; ${MAKE} _EXTRADEPEND
61.endif
62
63.else
64${DEPENDFILE}: _SUBDIR
65.endif
66.if !target(beforedepend)
67beforedepend:
68.endif
69.if !target(afterdepend)
70afterdepend:
71.endif
72.endif
73
74.if defined(NOTAGS)
75tags:
76.endif
77
78.if !target(tags)
79tags: ${SRCS} _SUBDIR
80	@cd ${.CURDIR} && gtags ${GTAGSFLAGS}
81.if defined(HTML)
82	@cd ${.CURDIR} && htags ${HTAGSFLAGS}
83.endif
84.endif
85
86.if defined(SRCS)
87.if !target(cleandepend)
88cleandepend: _SUBDIR
89	rm -f ${DEPENDFILE}
90	rm -f ${.CURDIR}/GRTAGS ${.CURDIR}/GTAGS
91.if defined(HTML)
92	rm -rf ${.CURDIR}/HTML
93.endif
94.endif
95.endif
96
97_SUBDIR: .USE
98.if defined(SUBDIR) && !empty(SUBDIR)
99	@for entry in ${SUBDIR}; do \
100		(${ECHODIR} "===> ${DIRPRFX}$$entry"; \
101		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
102			cd ${.CURDIR}/$${entry}.${MACHINE}; \
103		else \
104			cd ${.CURDIR}/$${entry}; \
105		fi; \
106		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/} DIRPRFX=${DIRPRFX}$$entry/); \
107	done
108.endif
109