xref: /freebsd/share/mk/bsd.dep.mk (revision 952d112864d8008aa87278a30a539d888a8493cd)
1#	$Id$
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 tags file for the source files.
28#
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
60.else
61${DEPENDFILE}: _SUBDIR
62.endif
63.if !target(beforedepend)
64beforedepend:
65.endif
66.if !target(afterdepend)
67afterdepend:
68.endif
69.endif
70
71.if !target(tags)
72.if defined(SRCS)
73tags: ${SRCS} _SUBDIR
74	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:N*.h} | \
75	    sed "s;\${.CURDIR}/;;" > tags
76.else
77tags: _SUBDIR
78.endif
79.endif
80
81.if defined(SRCS)
82.if !target(cleandepend)
83cleandepend: _SUBDIR
84	rm -f ${DEPENDFILE} tags
85.endif
86.endif
87
88_SUBDIR: .USE
89.if defined(SUBDIR) && !empty(SUBDIR)
90	@for entry in ${SUBDIR}; do \
91		(${ECHODIR} "===> ${DIRPRFX}$$entry"; \
92		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
93			cd ${.CURDIR}/$${entry}.${MACHINE}; \
94		else \
95			cd ${.CURDIR}/$${entry}; \
96		fi; \
97		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/} DIRPRFX=${DIRPRFX}$$entry/); \
98	done
99.endif
100