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