bsd.subdir.mk revision 266473
1#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
2# $FreeBSD: head/share/mk/bsd.subdir.mk 266473 2014-05-20 18:25:46Z sjg $
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.
20#
21# +++ targets +++
22#
23#	distribute:
24# 		This is a variant of install, which will
25# 		put the stuff into the right "distribution".
26#
27#	afterinstall, all, all-man, beforeinstall, checkdpadd, clean,
28#	cleandepend, cleandir, cleanilinks depend, install, lint,
29#	maninstall, manlint, obj, objlink, realinstall, regress, tags
30#
31
32.if !target(__<bsd.subdir.mk>__)
33__<bsd.subdir.mk>__:
34
35.include <bsd.init.mk>
36
37DISTRIBUTION?=	base
38.if !target(distribute)
39distribute: .MAKE
40.for dist in ${DISTRIBUTION}
41	${_+_}cd ${.CURDIR}; \
42	    ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
43.endfor
44.endif
45
46_SUBDIR: .USE .MAKE
47.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
48	@${_+_}set -e; for entry in ${SUBDIR:N.WAIT}; do \
49		if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \
50			${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH} (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
51			edir=$${entry}.${MACHINE_ARCH}; \
52			cd ${.CURDIR}/$${edir}; \
53		else \
54			${ECHODIR} "===> ${DIRPRFX}$$entry (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \
55			edir=$${entry}; \
56			cd ${.CURDIR}/$${edir}; \
57		fi; \
58		${MAKE} ${.TARGET:S,realinstall,install,:S,^_sub.,,} \
59		    DIRPRFX=${DIRPRFX}$$edir/; \
60	done
61.endif
62
63${SUBDIR:N.WAIT}: .PHONY .MAKE
64	${_+_}@if test -d ${.TARGET}.${MACHINE_ARCH}; then \
65		cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \
66	else \
67		cd ${.CURDIR}/${.TARGET}; \
68	fi; \
69	${MAKE} all
70
71# Work around parsing of .if nested in .for by putting .WAIT string into a var.
72__wait= .WAIT
73.for __target in all all-man checkdpadd clean cleandepend cleandir \
74    cleanilinks depend distribute lint maninstall manlint obj objlink \
75    realinstall regress tags ${SUBDIR_TARGETS}
76.ifdef SUBDIR_PARALLEL
77__subdir_targets=
78.for __dir in ${SUBDIR}
79.if ${__wait} == ${__dir}
80__subdir_targets+= .WAIT
81.else
82__subdir_targets+= ${__target}_subdir_${__dir}
83${__target}_subdir_${__dir}: .MAKE
84	@${_+_}set -e; \
85		if test -d ${.CURDIR}/${__dir}.${MACHINE_ARCH}; then \
86			${ECHODIR} "===> ${DIRPRFX}${__dir}.${MACHINE_ARCH} (${__target:realinstall=install})"; \
87			edir=${__dir}.${MACHINE_ARCH}; \
88			cd ${.CURDIR}/$${edir}; \
89		else \
90			${ECHODIR} "===> ${DIRPRFX}${__dir} (${__target:realinstall=install})"; \
91			edir=${__dir}; \
92			cd ${.CURDIR}/$${edir}; \
93		fi; \
94		${MAKE} ${__target:realinstall=install} \
95		    DIRPRFX=${DIRPRFX}$$edir/
96.endif
97.endfor
98${__target}: ${__subdir_targets}
99.else
100${__target}: _sub.${__target}
101_sub.${__target}: _SUBDIR
102.endif
103.endfor
104
105.for __target in files includes
106.for __stage in build install
107${__stage}${__target}:
108.if make(${__stage}${__target})
109${__stage}${__target}: _sub.${__stage}${__target}
110_sub.${__stage}${__target}: _SUBDIR
111.endif
112.endfor
113.if !target(${__target})
114${__target}: .MAKE
115	${_+_}set -e; cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target}
116.endif
117.endfor
118
119.if !target(install)
120.if !target(beforeinstall)
121beforeinstall:
122.endif
123.if !target(afterinstall)
124afterinstall:
125.endif
126install: beforeinstall realinstall afterinstall
127.ORDER: beforeinstall realinstall afterinstall
128.endif
129
130.endif
131