bsd.subdir.mk revision 53152
1236769Sobrien#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
2236769Sobrien# $FreeBSD: head/share/mk/bsd.subdir.mk 53152 1999-11-14 13:54:44Z marcel $
3236769Sobrien#
4236769Sobrien# The include file <bsd.subdir.mk> contains the default targets
5236769Sobrien# for building subdirectories. 
6236769Sobrien#
7236769Sobrien# For all of the directories listed in the variable SUBDIRS, the
8236769Sobrien# specified directory will be visited and the target made. There is
9236769Sobrien# also a default target which allows the command "make subdir" where
10236769Sobrien# subdir is any directory listed in the variable SUBDIRS.
11236769Sobrien#
12236769Sobrien#
13236769Sobrien# +++ variables +++
14236769Sobrien#
15236769Sobrien# DISTRIBUTION	Name of distribution. [bin]
16236769Sobrien#
17236769Sobrien# SUBDIR	A list of subdirectories that should be built as well.
18236769Sobrien#		Each of the targets will execute the same target in the
19236769Sobrien#		subdirectories.
20236769Sobrien#
21236769Sobrien# SUBDIR_CHANGE A directory-tree that contains overrides for
22236769Sobrien#               corresponding build subdirs.
23236769Sobrien#		Each override is a file containing one subdirname per line:
24236769Sobrien#                  'subdirlist'  is a pure override
25236769Sobrien#		   'subdirdrop'  drops directories from the build
26236769Sobrien#		   'subdiradd'   adds directories to the build
27236769Sobrien#
28236769Sobrien# +++ targets +++
29236769Sobrien#
30236769Sobrien#	distribute:
31236769Sobrien# 		This is a variant of install, which will
32236769Sobrien# 		put the stuff into the right "distribution".
33236769Sobrien#
34236769Sobrien#	afterdistribute, afterinstall, all, beforeinstall, checkdpadd,
35236769Sobrien#	clean, cleandepend, cleandir, depend, install, lint, maninstall,
36236769Sobrien#	obj, objlink, realinstall, regress, tags
37236769Sobrien#
38236769Sobrien
39236769Sobrien.if !target(__initialized__)
40236769Sobrien__initialized__:
41236769Sobrien.if exists(${.CURDIR}/../Makefile.inc)
42236769Sobrien.include "${.CURDIR}/../Makefile.inc"
43236769Sobrien.endif
44236769Sobrien.endif  
45236769Sobrien
46236769Sobrien.MAIN: all
47236769Sobrien
48236769Sobrien.if defined(SUBDIR_CHANGE) && !empty(SUBDIR_CHANGE) && \
49236769Sobrien	exists(${SUBDIR_CHANGE}/${DIRPRFX}/subdirlist)
50236769SobrienSUBDIR!=cat ${SUBDIR_CHANGE}/${DIRPRFX}/subdirlist
51236769Sobrien.endif
52236769Sobrien
53236769Sobrien.if defined(SUBDIR_CHANGE) && !empty(SUBDIR_CHANGE) && \
54236769Sobrien	exists(${SUBDIR_CHANGE}/${DIRPRFX}/subdirlist)
55236769Sobrien_SUBDIR_EXTRA!=cat ${SUBDIR_CHANGE}/${DIRPRFX}/subdiradd
56236769Sobrien.endif
57236769Sobrien
58236769Sobrien_SUBDIRUSE: .USE
59236769Sobrien	@for entry in ${SUBDIR} ${_SUBDIR_EXTRA}; do \
60236769Sobrien		(if ! (test -f ${SUBDIR_CHANGE}/${DIRPRFX}/subdirdrop && \
61236769Sobrien			grep -w $${entry} \
62236769Sobrien			    ${SUBDIR_CHANGE}/${DIRPRFX}/subdirdrop \
63236769Sobrien				> /dev/null); then \
64236769Sobrien			if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
65236769Sobrien				${ECHODIR} \
66236769Sobrien				    "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH}"; \
67236769Sobrien				edir=$${entry}.${MACHINE_ARCH}; \
68236769Sobrien				cd ${.CURDIR}/$${edir}; \
69236769Sobrien			else \
70236769Sobrien				${ECHODIR} "===> ${DIRPRFX}$$entry"; \
71236769Sobrien				edir=$${entry}; \
72236769Sobrien				cd ${.CURDIR}/$${edir}; \
73236769Sobrien			fi; \
74236769Sobrien			${MAKE} ${.TARGET:realinstall=install} \
75236769Sobrien				SUBDIR_CHANGE=${SUBDIR_CHANGE} \
76236769Sobrien				DIRPRFX=${DIRPRFX}$$edir/; \
77236769Sobrien			fi; \
78236769Sobrien		); \
79236769Sobrien	done
80236769Sobrien
81236769Sobrien${SUBDIR}::
82236769Sobrien	@if test -d ${.TARGET}.${MACHINE_ARCH}; then \
83236769Sobrien		cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \
84236769Sobrien	else \
85236769Sobrien		cd ${.CURDIR}/${.TARGET}; \
86236769Sobrien	fi; \
87236769Sobrien	${MAKE} all
88236769Sobrien
89236769Sobrien
90236769Sobrien.for __target in all checkdpadd clean cleandepend cleandir depend lint \
91236769Sobrien		 maninstall obj objlink regress tags
92236769Sobrien.if !target(${__target})
93236769Sobrien${__target}: _SUBDIRUSE
94236769Sobrien.endif
95236769Sobrien.endfor
96236769Sobrien
97236769Sobrien.if !target(install)
98236769Sobrien.if !target(beforeinstall)
99236769Sobrienbeforeinstall:
100236769Sobrien.endif
101236769Sobrien.if !target(afterinstall)
102236769Sobrienafterinstall:
103236769Sobrien.endif
104236769Sobrieninstall: afterinstall
105236769Sobrienafterinstall: realinstall
106236769Sobrienrealinstall: beforeinstall _SUBDIRUSE
107236769Sobrien.endif
108236769Sobrien
109236769SobrienDISTRIBUTION?=	bin
110236769Sobrien.if !target(afterdistribute)
111236769Sobrienafterdistribute:
112236769Sobrien.endif
113236769Sobrien.if !target(distribute)
114236769Sobriendistribute: _SUBDIRUSE
115236769Sobrien.for dist in ${DISTRIBUTION}
116236769Sobrien	cd ${.CURDIR} ; ${MAKE} afterdistribute DESTDIR=${DISTDIR}/${dist}
117236769Sobrien.endfor
118236769Sobrien.endif
119236769Sobrien