bsd.subdir.mk revision 289282
1#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
2# $FreeBSD: head/share/mk/bsd.subdir.mk 289282 2015-10-14 02:37:30Z 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 buildfiles buildincludes \
36		    checkdpadd clean cleandepend cleandir cleanilinks \
37		    cleanobj config depend distribute files includes \
38		    installconfig installfiles installincludes lint \
39		    maninstall manlint obj objlink realinstall regress tags \
40		    ${SUBDIR_TARGETS}
41
42.include <bsd.init.mk>
43
44.if !defined(NEED_SUBDIR)
45.if ${.MAKE.LEVEL} == 0 && ${MK_META_MODE} == "yes" && !empty(SUBDIR) && !(make(clean*) || make(destroy*))
46.include <meta.subdir.mk>
47# ignore this
48_SUBDIR:
49.endif
50.endif
51.if !target(_SUBDIR)
52
53.if defined(SUBDIR)
54SUBDIR:=${SUBDIR} ${SUBDIR.yes}
55SUBDIR:=${SUBDIR:u}
56.endif
57
58DISTRIBUTION?=	base
59.if !target(distribute)
60distribute: .MAKE
61.for dist in ${DISTRIBUTION}
62	${_+_}cd ${.CURDIR}; \
63	    ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
64.endfor
65.endif
66
67_SUBDIR: .USE .MAKE
68.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
69	@${_+_}for entry in ${SUBDIR:N.WAIT}; do \
70		if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
71			${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH} (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
72			edir=$${entry}.${MACHINE_ARCH}; \
73			cd ${.CURDIR}/$${edir}; \
74		else \
75			${ECHODIR} "===> ${DIRPRFX}$$entry (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
76			edir=$${entry}; \
77			cd ${.CURDIR}/$${edir}; \
78		fi; \
79		${MAKE} ${.TARGET:S,realinstall,install,:S,^_sub.,,} \
80		    DIRPRFX=${DIRPRFX}$$edir/; \
81	done
82.endif
83
84${SUBDIR:N.WAIT}: .PHONY .MAKE
85	${_+_}@if test -d ${.TARGET}.${MACHINE_ARCH}; then \
86		cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \
87	else \
88		cd ${.CURDIR}/${.TARGET}; \
89	fi; \
90	${MAKE} all
91
92# Work around parsing of .if nested in .for by putting .WAIT string into a var.
93__wait= .WAIT
94.for __target in ${ALL_SUBDIR_TARGETS}
95.ifdef SUBDIR_PARALLEL
96__subdir_targets=
97.for __dir in ${SUBDIR}
98.if ${__wait} == ${__dir}
99__subdir_targets+= .WAIT
100.else
101__subdir_targets+= ${__target}_subdir_${__dir}
102__deps=
103.for __dep in ${SUBDIR_DEPEND_${__dir}}
104__deps+= ${__target}_subdir_${__dep}
105.endfor
106${__target}_subdir_${__dir}: .MAKE ${__deps}
107.if !defined(NO_SUBDIR)
108	@${_+_}if test -d ${.CURDIR}/${__dir}.${MACHINE_ARCH}; then \
109			${ECHODIR} "===> ${DIRPRFX}${__dir}.${MACHINE_ARCH} (${__target:realinstall=install})"; \
110			edir=${__dir}.${MACHINE_ARCH}; \
111			cd ${.CURDIR}/$${edir}; \
112		else \
113			${ECHODIR} "===> ${DIRPRFX}${__dir} (${__target:realinstall=install})"; \
114			edir=${__dir}; \
115			cd ${.CURDIR}/$${edir}; \
116		fi; \
117		${MAKE} ${__target:realinstall=install} \
118		    DIRPRFX=${DIRPRFX}$$edir/
119.endif
120.endif
121.endfor
122${__target}: ${__subdir_targets}
123.else
124${__target}: _sub.${__target}
125_sub.${__target}: _SUBDIR
126.endif
127.endfor
128
129.endif
130
131.if !target(install)
132.if !target(beforeinstall)
133beforeinstall:
134.endif
135.if !target(afterinstall)
136afterinstall:
137.endif
138install: beforeinstall realinstall afterinstall
139.ORDER: beforeinstall realinstall afterinstall
140.endif
141
142.endif
143