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