11844Swollman#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
250476Speter# $FreeBSD$
323549Swosch#
423549Swosch# The include file <bsd.subdir.mk> contains the default targets
5139761Skrion# for building subdirectories.
623549Swosch#
723549Swosch# For all of the directories listed in the variable SUBDIRS, the
823549Swosch# specified directory will be visited and the target made. There is
923549Swosch# also a default target which allows the command "make subdir" where
1023549Swosch# subdir is any directory listed in the variable SUBDIRS.
1123549Swosch#
1223549Swosch#
1323549Swosch# +++ variables +++
1423549Swosch#
1595327Sobrien# DISTRIBUTION	Name of distribution. [base]
1623549Swosch#
1723549Swosch# SUBDIR	A list of subdirectories that should be built as well.
1823549Swosch#		Each of the targets will execute the same target in the
1923549Swosch#		subdirectories.
2023549Swosch#
2123549Swosch# +++ targets +++
2223549Swosch#
2323549Swosch#	distribute:
2423549Swosch# 		This is a variant of install, which will
2523549Swosch# 		put the stuff into the right "distribution".
2623549Swosch#
27200178Sed#	afterinstall, all, all-man, beforeinstall, checkdpadd, clean,
28200178Sed#	cleandepend, cleandir, cleanilinks depend, install, lint,
29200178Sed#	maninstall, manlint, obj, objlink, realinstall, regress, tags
3023549Swosch#
311638Srgrimes
3294940Sru.include <bsd.init.mk>
3323549Swosch
3499875SruDISTRIBUTION?=	base
3599875Sru.if !target(distribute)
3699875Srudistribute:
3799875Sru.for dist in ${DISTRIBUTION}
38133369Sharti	${_+_}cd ${.CURDIR}; \
3999875Sru	    ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
4099875Sru.endfor
4199875Sru.endif
4299875Sru
4395306Sru_SUBDIR: .USE
4499875Sru.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
45252048Ssjg	@${_+_}set -e; for entry in ${SUBDIR}; do \
4695306Sru		if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
47134903Simp			${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH} (${.TARGET:realinstall=install})"; \
4890311Sru			edir=$${entry}.${MACHINE_ARCH}; \
4990311Sru			cd ${.CURDIR}/$${edir}; \
5090311Sru		else \
51134903Simp			${ECHODIR} "===> ${DIRPRFX}$$entry (${.TARGET:realinstall=install})"; \
5290311Sru			edir=$${entry}; \
5390311Sru			cd ${.CURDIR}/$${edir}; \
5490311Sru		fi; \
5590311Sru		${MAKE} ${.TARGET:realinstall=install} \
5695306Sru		    DIRPRFX=${DIRPRFX}$$edir/; \
571638Srgrimes	done
5895306Sru.endif
591638Srgrimes
60146817Sru${SUBDIR}: .PHONY
61133369Sharti	${_+_}@if test -d ${.TARGET}.${MACHINE_ARCH}; then \
6253152Smarcel		cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \
631638Srgrimes	else \
641638Srgrimes		cd ${.CURDIR}/${.TARGET}; \
651638Srgrimes	fi; \
66146817Sru	${MAKE} all
671638Srgrimes
6895509Sru.for __target in all all-man checkdpadd clean cleandepend cleandir \
69200178Sed    cleanilinks depend distribute lint maninstall manlint obj objlink \
70200178Sed    realinstall regress tags ${SUBDIR_TARGETS}
71264303Sdim.ifdef SUBDIR_PARALLEL
72264303Sdim.for __dir in ${SUBDIR}
73264303Sdim${__target}: ${__target}_subdir_${__dir}
74264303Sdim${__target}_subdir_${__dir}: .MAKE
75264303Sdim	@${_+_}set -e; \
76264303Sdim		if test -d ${.CURDIR}/${__dir}.${MACHINE_ARCH}; then \
77264303Sdim			${ECHODIR} "===> ${DIRPRFX}${__dir}.${MACHINE_ARCH} (${__target:realinstall=install})"; \
78264303Sdim			edir=${__dir}.${MACHINE_ARCH}; \
79264303Sdim			cd ${.CURDIR}/$${edir}; \
80264303Sdim		else \
81264303Sdim			${ECHODIR} "===> ${DIRPRFX}${__dir} (${__target:realinstall=install})"; \
82264303Sdim			edir=${__dir}; \
83264303Sdim			cd ${.CURDIR}/$${edir}; \
84264303Sdim		fi; \
85264303Sdim		${MAKE} ${__target:realinstall=install} \
86264303Sdim		    DIRPRFX=${DIRPRFX}$$edir/
87264303Sdim.endfor
88264303Sdim.else
8995306Sru${__target}: _SUBDIR
90264303Sdim.endif
9115061Swosch.endfor
921638Srgrimes
9397769Sru.for __target in files includes
9496668Sru.for __stage in build install
9596668Sru${__stage}${__target}:
9696668Sru.if make(${__stage}${__target})
9796668Sru${__stage}${__target}: _SUBDIR
9896668Sru.endif
9996668Sru.endfor
10096668Sru${__target}:
101252048Ssjg	${_+_}set -e; cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
10296668Sru.endfor
10396668Sru
1041638Srgrimes.if !target(install)
1051638Srgrimes.if !target(beforeinstall)
1061638Srgrimesbeforeinstall:
1071638Srgrimes.endif
1081638Srgrimes.if !target(afterinstall)
1091638Srgrimesafterinstall:
1101638Srgrimes.endif
11199215Sruinstall: beforeinstall realinstall afterinstall
11299215Sru.ORDER: beforeinstall realinstall afterinstall
1131638Srgrimes.endif
114