bsd.subdir.mk revision 44922
1#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
2#	$Id: bsd.subdir.mk,v 1.26 1999/03/14 20:41:14 markm Exp $
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, 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}/subdirlist)
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}; then \
65				${ECHODIR} \
66				    "===> ${DIRPRFX}$${entry}.${MACHINE}"; \
67				edir=$${entry}.${MACHINE}; \
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}; then \
83		cd ${.CURDIR}/${.TARGET}.${MACHINE}; \
84	else \
85		cd ${.CURDIR}/${.TARGET}; \
86	fi; \
87	${MAKE} all
88
89
90.for __target in all checkdpadd clean cleandepend cleandir depend lint \
91		 maninstall obj objlink regress tags
92.if !target(${__target})
93${__target}: _SUBDIRUSE
94.endif
95.endfor
96
97.if !target(install)
98.if !target(beforeinstall)
99beforeinstall:
100.endif
101.if !target(afterinstall)
102afterinstall:
103.endif
104install: afterinstall
105afterinstall: realinstall
106realinstall: beforeinstall _SUBDIRUSE
107.endif
108
109DISTRIBUTION?=	bin
110.if !target(afterdistribute)
111afterdistribute:
112.endif
113.if !target(distribute)
114distribute: _SUBDIRUSE
115.for dist in ${DISTRIBUTION}
116	cd ${.CURDIR} ; ${MAKE} afterdistribute DESTDIR=${DISTDIR}/${dist}
117.endfor
118.endif
119