bsd.subdir.mk revision 289705
1#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
2# $FreeBSD: head/share/mk/bsd.subdir.mk 289705 2015-10-21 16:24:44Z bdrewery $
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. [base]
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. SUBDIR.yes is automatically appeneded
20#		to this list.
21#
22# +++ targets +++
23#
24#	distribute:
25# 		This is a variant of install, which will
26# 		put the stuff into the right "distribution".
27#
28# 	See ALL_SUBDIR_TARGETS for list of targets that will recurse.
29# 	Custom targets can be added to SUBDIR_TARGETS in src.conf.
30#
31
32.if !target(__<bsd.subdir.mk>__)
33__<bsd.subdir.mk>__:
34
35ALL_SUBDIR_TARGETS= all all-man buildconfig checkdpadd clean cleandepend \
36		    cleandir cleanilinks cleanobj depend distribute \
37		    installconfig lint maninstall manlint obj objlink \
38		    realinstall regress tags \
39		    ${SUBDIR_TARGETS}
40
41.include <bsd.init.mk>
42
43.if !defined(NEED_SUBDIR)
44.if ${.MAKE.LEVEL} == 0 && ${MK_META_MODE} == "yes" && !empty(SUBDIR) && !(make(clean*) || make(destroy*))
45.include <meta.subdir.mk>
46# ignore this
47_SUBDIR:
48.endif
49.endif
50.if !target(_SUBDIR)
51
52.if defined(SUBDIR)
53SUBDIR:=${SUBDIR} ${SUBDIR.yes}
54SUBDIR:=${SUBDIR:u}
55.endif
56
57DISTRIBUTION?=	base
58.if !target(distribute)
59distribute: .MAKE
60.for dist in ${DISTRIBUTION}
61	${_+_}cd ${.CURDIR}; \
62	    ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
63.endfor
64.endif
65
66# Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL.
67_SUBDIR_SH=	\
68		if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
69			dir=$${dir}.${MACHINE_ARCH}; \
70		fi; \
71		${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \
72		cd ${.CURDIR}/$${dir}; \
73		${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/
74
75_SUBDIR: .USEBEFORE
76.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
77	@${_+_}target=${.TARGET:S,realinstall,install,}; \
78	    for dir in ${SUBDIR:N.WAIT}; do ${_SUBDIR_SH}; done
79.endif
80
81${SUBDIR:N.WAIT}: .PHONY .MAKE
82	${_+_}@target=all; \
83	    dir=${.TARGET}; \
84	    ${_SUBDIR_SH};
85
86# Work around parsing of .if nested in .for by putting .WAIT string into a var.
87__wait= .WAIT
88.for __target in ${ALL_SUBDIR_TARGETS}
89.ifdef SUBDIR_PARALLEL
90__subdir_targets=
91.for __dir in ${SUBDIR}
92.if ${__wait} == ${__dir}
93__subdir_targets+= .WAIT
94.else
95__subdir_targets+= ${__target}_subdir_${__dir}
96__deps=
97.for __dep in ${SUBDIR_DEPEND_${__dir}}
98__deps+= ${__target}_subdir_${__dep}
99.endfor
100${__target}_subdir_${__dir}: .PHONY .MAKE ${__deps}
101.if !defined(NO_SUBDIR)
102	@${_+_}target=${__target:realinstall=install}; \
103	    dir=${__dir}; \
104	    ${_SUBDIR_SH};
105.endif
106.endif
107.endfor
108${__target}: ${__subdir_targets}
109.else
110${__target}: _SUBDIR
111.endif
112.endfor
113
114# This is to support 'make includes' calling 'make buildincludes' and
115# 'make installincludes' in the proper order, and to support these
116# targets as SUBDIR_TARGETS.
117.for __target in files includes
118.for __stage in build install
119${__stage}${__target}:
120.if make(${__stage}${__target})
121${__stage}${__target}: _SUBDIR
122.endif
123.endfor
124.if !target(${__target})
125${__target}: .MAKE
126	${_+_}cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
127.endif
128.endfor
129
130.endif
131
132.if !target(install)
133.if !target(beforeinstall)
134beforeinstall:
135.endif
136.if !target(afterinstall)
137afterinstall:
138.endif
139install: beforeinstall realinstall afterinstall
140.ORDER: beforeinstall realinstall afterinstall
141.endif
142
143.endif
144