bsd.subdir.mk revision 295646
1#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
2# $FreeBSD: head/share/mk/bsd.subdir.mk 295646 2016-02-16 02:14:15Z 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 SUBDIR_TARGETS for list of targets that will recurse.
29#
30# 	Targets defined in STANDALONE_SUBDIR_TARGETS will always be ran
31# 	with SUBDIR_PARALLEL and will not respect .WAIT or SUBDIR_DEPEND_
32# 	values.
33#
34# 	SUBDIR_TARGETS and STANDALONE_SUBDIR_TARGETS can be appended to
35# 	via make.conf or src.conf.
36#
37
38.if !target(__<bsd.subdir.mk>__)
39__<bsd.subdir.mk>__:
40
41SUBDIR_TARGETS+= \
42		all all-man buildconfig buildfiles buildincludes \
43		checkdpadd clean cleandepend cleandir cleanilinks \
44		cleanobj depend distribute files includes installconfig \
45		installfiles installincludes realinstall lint maninstall \
46		manlint obj objlink tags \
47
48# Described above.
49STANDALONE_SUBDIR_TARGETS+= \
50		obj check checkdpadd clean cleandepend cleandir \
51		cleanilinks cleanobj installconfig \
52
53.include <bsd.init.mk>
54
55.if !defined(NEED_SUBDIR)
56.if ${.MAKE.LEVEL} == 0 && ${MK_DIRDEPS_BUILD} == "yes" && !empty(SUBDIR) && !(make(clean*) || make(destroy*))
57.include <meta.subdir.mk>
58# ignore this
59_SUBDIR:
60.endif
61.endif
62
63DISTRIBUTION?=	base
64.if !target(distribute)
65distribute: .MAKE
66.for dist in ${DISTRIBUTION}
67	${_+_}cd ${.CURDIR}; \
68	    ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
69.endfor
70.endif
71
72# Convenience targets to run 'build${target}' and 'install${target}' when
73# calling 'make ${target}'.
74.for __target in files includes
75.if !target(${__target})
76${__target}:	build${__target} install${__target}
77.ORDER:		build${__target} install${__target}
78.endif
79.endfor
80
81# Make 'install' supports a before and after target.  Actual install
82# hooks are placed in 'realinstall'.
83.if !target(install)
84.for __stage in before real after
85.if !target(${__stage}install)
86${__stage}install:
87.endif
88.endfor
89install:	beforeinstall realinstall afterinstall
90.ORDER:		beforeinstall realinstall afterinstall
91.endif
92.ORDER: all install
93
94# SUBDIR recursing may be disabled for MK_DIRDEPS_BUILD
95.if !target(_SUBDIR)
96
97.if defined(SUBDIR)
98SUBDIR:=${SUBDIR} ${SUBDIR.yes}
99SUBDIR:=${SUBDIR:u}
100.endif
101
102# Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL.
103_SUBDIR_SH=	\
104		if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
105			dir=$${dir}.${MACHINE_ARCH}; \
106		fi; \
107		${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \
108		cd ${.CURDIR}/$${dir}; \
109		${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/
110
111_SUBDIR: .USEBEFORE
112.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
113	@${_+_}target=${.TARGET:realinstall=install}; \
114	    for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done
115.endif
116
117${SUBDIR:N.WAIT}: .PHONY .MAKE
118	${_+_}@target=all; \
119	    dir=${.TARGET}; \
120	    ${_SUBDIR_SH};
121
122.for __target in ${SUBDIR_TARGETS}
123# Only recurse on directly-called targets.  I.e., don't recurse on dependencies
124# such as 'install' becoming {before,real,after}install, just recurse
125# 'install'.  Despite that, 'realinstall' is special due to ordering issues
126# with 'afterinstall'.
127.if make(${__target}) || (${__target} == realinstall && make(install))
128# Can ordering be skipped for this and SUBDIR_PARALLEL forced?
129.if ${STANDALONE_SUBDIR_TARGETS:M${__target}}
130_is_standalone_target=	1
131SUBDIR:=	${SUBDIR:N.WAIT}
132.else
133_is_standalone_target=	0
134.endif
135.if defined(SUBDIR_PARALLEL) || ${_is_standalone_target} == 1
136__subdir_targets=
137.for __dir in ${SUBDIR}
138.if ${__dir} == .WAIT
139__subdir_targets+= .WAIT
140.else
141__subdir_targets+= ${__target}_subdir_${__dir}
142__deps=
143.if ${_is_standalone_target} == 0
144.for __dep in ${SUBDIR_DEPEND_${__dir}}
145__deps+= ${__target}_subdir_${__dep}
146.endfor
147.endif
148${__target}_subdir_${__dir}: .PHONY .MAKE ${__deps}
149.if !defined(NO_SUBDIR)
150	@${_+_}target=${__target:realinstall=install}; \
151	    dir=${__dir}; \
152	    ${_SUBDIR_SH};
153.endif
154.endif
155.endfor	# __dir in ${SUBDIR}
156${__target}: ${__subdir_targets}
157.else
158${__target}: _SUBDIR
159.endif	# SUBDIR_PARALLEL || _is_standalone_target
160.endif	# make(${__target})
161.endfor	# __target in ${SUBDIR_TARGETS}
162
163.endif	# !target(_SUBDIR)
164
165# Ensure all targets exist
166.for __target in ${SUBDIR_TARGETS}
167.if !target(${__target})
168${__target}:
169.endif
170.endfor
171
172.endif
173