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