bsd.subdir.mk revision 34934
1#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
2#	$Id: bsd.subdir.mk,v 1.22 1998/03/26 16:02:44 eivind Exp $
3#
4# The include file <bsd.subdir.mk> contains the default targets
5# for building subdirectories. It has the same seven targets
6# as <bsd.prog.mk>:
7#	all, clean, cleandir, depend, install, lint, and tags.
8#
9# For all of the directories listed in the variable SUBDIRS, the
10# specified directory will be visited and the target made. There is
11# also a default target which allows the command "make subdir" where
12# subdir is any directory listed in the variable SUBDIRS.
13#
14#
15# +++ variables +++
16#
17# DISTRIBUTION	Name of distribution. [bin]
18#
19# SUBDIR	A list of subdirectories that should be built as well.
20#		Each of the targets will execute the same target in the
21#		subdirectories.
22#
23# SUBDIR_CHANGE A directory-tree that contains overrides for
24#               corresponding build subdirs.
25#		Each override is a file containing one subdirname per line:
26#                  'subdirlist'  is a pure override
27#		   'subdirdrop'  drops directories from the build
28#		   'subdiradd'   adds directories to the build
29#
30# +++ targets +++
31#
32#	distribute:
33# 		This is a variant of install, which will
34# 		put the stuff into the right "distribution".
35#
36#	afterdistribute, afterinstall, all, beforeinstall, checkdpadd,
37#	clean, cleandepend, cleandir, depend, install, lint, maninstall,
38#	obj, objlink, realinstall, regress, tags
39#
40
41
42.MAIN: all
43
44.if defined(SUBDIR_CHANGE) && !empty(SUBDIR_CHANGE) && \
45	exists(${SUBDIR_CHANGE}/${DIRPRFX}/subdirlist)
46SUBDIR!=cat ${SUBDIR_CHANGE}/${DIRPRFX}/subdirlist
47.endif
48
49.if defined(SUBDIR_CHANGE) && !empty(SUBDIR_CHANGE) && \
50	exists(${SUBDIR_CHANGE}/${DIRPRFX}/subdirlist)
51_SUBDIR_EXTRA!=cat ${SUBDIR_CHANGE}/${DIRPRFX}/subdiradd
52.endif
53
54_SUBDIRUSE: .USE
55	@for entry in ${SUBDIR} ${_SUBDIR_EXTRA}; do \
56		(if ! (test -f ${SUBDIR_CHANGE}/${DIRPRFX}/subdirdrop && \
57			grep -w $${entry} \
58			    ${SUBDIR_CHANGE}/${DIRPRFX}/subdirdrop \
59				> /dev/null); then \
60			if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
61				${ECHODIR} \
62				    "===> ${DIRPRFX}$${entry}.${MACHINE}"; \
63				edir=$${entry}.${MACHINE}; \
64				cd ${.CURDIR}/$${edir}; \
65			else \
66				${ECHODIR} "===> ${DIRPRFX}$$entry"; \
67				edir=$${entry}; \
68				cd ${.CURDIR}/$${edir}; \
69			fi; \
70			${MAKE} ${.TARGET:realinstall=install} \
71				SUBDIR_CHANGE=${SUBDIR_CHANGE} \
72				DIRPRFX=${DIRPRFX}$$edir/; \
73			fi; \
74		); \
75	done
76
77${SUBDIR}::
78	@if test -d ${.TARGET}.${MACHINE}; then \
79		cd ${.CURDIR}/${.TARGET}.${MACHINE}; \
80	else \
81		cd ${.CURDIR}/${.TARGET}; \
82	fi; \
83	${MAKE} all
84
85
86.for __target in all checkdpadd clean cleandepend cleandir depend lint \
87		 maninstall obj objlink regress tags
88.if !target(${__target})
89${__target}: _SUBDIRUSE
90.endif
91.endfor
92
93.if !target(install)
94.if !target(beforeinstall)
95beforeinstall:
96.endif
97.if !target(afterinstall)
98afterinstall:
99.endif
100install: afterinstall
101afterinstall: realinstall
102realinstall: beforeinstall _SUBDIRUSE
103.endif
104
105DISTRIBUTION?=	bin
106.if !target(afterdistribute)
107afterdistribute:
108.endif
109.if !target(distribute)
110distribute: _SUBDIRUSE
111.for dist in ${DISTRIBUTION}
112	cd ${.CURDIR} ; ${MAKE} afterdistribute DESTDIR=${DISTDIR}/${dist}
113.endfor
114.endif
115