159138Smsmith#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
259138Smsmith# $FreeBSD: stable/10/share/mk/bsd.subdir.mk 313790 2017-02-16 05:14:07Z ngie $
359138Smsmith#
459138Smsmith# The include file <bsd.subdir.mk> contains the default targets
559138Smsmith# for building subdirectories.
659138Smsmith#
759138Smsmith# For all of the directories listed in the variable SUBDIRS, the
859138Smsmith# specified directory will be visited and the target made. There is
959138Smsmith# also a default target which allows the command "make subdir" where
1059138Smsmith# subdir is any directory listed in the variable SUBDIRS.
1159138Smsmith#
1259138Smsmith#
1359138Smsmith# +++ variables +++
1459138Smsmith#
1559138Smsmith# DISTRIBUTION	Name of distribution. [base]
1659138Smsmith#
1759138Smsmith# SUBDIR	A list of subdirectories that should be built as well.
1859138Smsmith#		Each of the targets will execute the same target in the
1959138Smsmith#		subdirectories.
2059138Smsmith#
2159138Smsmith# +++ targets +++
2259138Smsmith#
2359138Smsmith#	distribute:
2459138Smsmith# 		This is a variant of install, which will
2559138Smsmith# 		put the stuff into the right "distribution".
2659138Smsmith#
2759138Smsmith#	afterinstall, all, all-man, beforeinstall, check, checkdpadd, clean,
2859138Smsmith#	cleandepend, cleandir, cleanilinks depend, install, lint,
2959138Smsmith#	maninstall, manlint, obj, objlink, realinstall, tags
3059138Smsmith#
3159138Smsmith
3259138Smsmith.if !target(__<bsd.subdir.mk>__)
3359138Smsmith__<bsd.subdir.mk>__:
3459138Smsmith
3559138Smsmith.include <bsd.init.mk>
3659138Smsmith
3759159SmsmithDISTRIBUTION?=	base
3859159Smsmith.if !target(distribute)
3959138Smsmithdistribute: .MAKE
4059138Smsmith.for dist in ${DISTRIBUTION}
4159138Smsmith	${_+_}cd ${.CURDIR}; \
4259138Smsmith	    ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
4359138Smsmith.endfor
4459138Smsmith.endif
4559138Smsmith
4659138Smsmith_SUBDIR: .USE .MAKE
4759138Smsmith.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
4859138Smsmith	@${_+_}for entry in ${SUBDIR:N.WAIT}; do \
4959138Smsmith		if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
5059138Smsmith			${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH} (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
5159138Smsmith			edir=$${entry}.${MACHINE_ARCH}; \
5259138Smsmith			cd ${.CURDIR}/$${edir}; \
5359138Smsmith		else \
5459138Smsmith			${ECHODIR} "===> ${DIRPRFX}$$entry (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
5559138Smsmith			edir=$${entry}; \
5659138Smsmith			cd ${.CURDIR}/$${edir}; \
5759138Smsmith		fi; \
5859138Smsmith		${MAKE} ${.TARGET:S,realinstall,install,:S,^_sub.,,} \
5959138Smsmith		    DIRPRFX=${DIRPRFX}$$edir/; \
6059138Smsmith	done
6159138Smsmith.endif
6259138Smsmith
6359138Smsmith${SUBDIR:N.WAIT}: .PHONY .MAKE
6459138Smsmith	${_+_}@if test -d ${.TARGET}.${MACHINE_ARCH}; then \
6559138Smsmith		cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \
6659138Smsmith	else \
6759138Smsmith		cd ${.CURDIR}/${.TARGET}; \
6859138Smsmith	fi; \
6959138Smsmith	${MAKE} all
7059138Smsmith
7159138Smsmith# Work around parsing of .if nested in .for by putting .WAIT string into a var.
7259138Smsmith__wait= .WAIT
7359138Smsmith.for __target in all all-man check checkdpadd clean cleandepend cleandir \
7459138Smsmith    cleanilinks depend distribute lint maninstall manlint obj objlink \
7559138Smsmith    realinstall tags ${SUBDIR_TARGETS}
7659138Smsmith.ifdef SUBDIR_PARALLEL
7759138Smsmith__subdir_targets=
7859138Smsmith.for __dir in ${SUBDIR}
7959138Smsmith.if ${__wait} == ${__dir}
8059138Smsmith__subdir_targets+= .WAIT
8159138Smsmith.else
8259138Smsmith__subdir_targets+= ${__target}_subdir_${__dir}
8359138Smsmith__deps=
8459138Smsmith.for __dep in ${SUBDIR_DEPEND_${__dir}}
8559138Smsmith__deps+= ${__target}_subdir_${__dep}
8659138Smsmith.endfor
8759138Smsmith${__target}_subdir_${__dir}: .PHONY .MAKE ${__deps}
8859138Smsmith.if !defined(NO_SUBDIR)
8959138Smsmith	@${_+_}if test -d ${.CURDIR}/${__dir}.${MACHINE_ARCH}; then \
9059138Smsmith			${ECHODIR} "===> ${DIRPRFX}${__dir}.${MACHINE_ARCH} (${__target:realinstall=install})"; \
9159138Smsmith			edir=${__dir}.${MACHINE_ARCH}; \
9259138Smsmith			cd ${.CURDIR}/$${edir}; \
9359138Smsmith		else \
9459138Smsmith			${ECHODIR} "===> ${DIRPRFX}${__dir} (${__target:realinstall=install})"; \
9559138Smsmith			edir=${__dir}; \
9659138Smsmith			cd ${.CURDIR}/$${edir}; \
9759138Smsmith		fi; \
9859138Smsmith		${MAKE} ${__target:realinstall=install} \
9959138Smsmith		    DIRPRFX=${DIRPRFX}$$edir/
10059138Smsmith.endif
10159138Smsmith.endif
10259138Smsmith.endfor
10359138Smsmith${__target}: ${__subdir_targets}
10459138Smsmith.else
10559138Smsmith${__target}: _sub.${__target}
10659138Smsmith_sub.${__target}: _SUBDIR
10759138Smsmith.endif
10859138Smsmith.endfor
10959138Smsmith
11059138Smsmith.for __target in files includes
11159138Smsmith.for __stage in build install
11259138Smsmith${__stage}${__target}:
11359138Smsmith.if make(${__stage}${__target})
11459138Smsmith${__stage}${__target}: _sub.${__stage}${__target}
11559138Smsmith_sub.${__stage}${__target}: _SUBDIR
11659138Smsmith.endif
11759138Smsmith.endfor
11859138Smsmith.if !target(${__target})
11959138Smsmith${__target}: .MAKE
12059138Smsmith	${_+_}cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
12159138Smsmith.endif
12259138Smsmith.endfor
12359138Smsmith
12459138Smsmith.if !target(install)
12559138Smsmith.if !target(beforeinstall)
12659138Smsmithbeforeinstall:
12759138Smsmith.endif
12859138Smsmith.if !target(afterinstall)
12959138Smsmithafterinstall:
13059138Smsmith.endif
13159138Smsmithinstall: beforeinstall realinstall afterinstall
13259138Smsmith.ORDER: beforeinstall realinstall afterinstall
13359138Smsmith.endif
13459138Smsmith
13559138Smsmith.endif
13659138Smsmith