1 # from: @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91
3 # The include file <bsd.subdir.mk> contains the default targets
4 # for building subdirectories.
6 # For all of the directories listed in the variable SUBDIRS, the
7 # specified directory will be visited and the target made. There is
8 # also a default target which allows the command "make subdir" where
9 # subdir is any directory listed in the variable SUBDIRS.
14 # DISTRIBUTION Name of distribution. [base]
16 # SUBDIR A list of subdirectories that should be built as well.
17 # Each of the targets will execute the same target in the
18 # subdirectories. SUBDIR.yes and SUBDIR.yes.yes are
19 # automatically appended to this list.
24 # This is a variant of install, which will
25 # put the stuff into the right "distribution".
27 # See SUBDIR_TARGETS for list of targets that will recurse.
29 # Targets defined in STANDALONE_SUBDIR_TARGETS will always be ran
30 # with SUBDIR_PARALLEL and will not respect .WAIT or SUBDIR_DEPEND_
33 # SUBDIR_TARGETS and STANDALONE_SUBDIR_TARGETS can be appended to
34 # via make.conf or src.conf.
37 .if !target(__<bsd.subdir.mk>__)
40 .if ${MK_AUTO_OBJ} == "no"
45 all all-man analyze buildconfig buildfiles buildincludes \
46 checkdpadd clean cleandepend cleandir cleanilinks \
47 cleanobj depend distribute files includes installconfig \
49 installfiles installincludes print-dir realinstall \
50 maninstall manlint ${_obj} objlink tags \
53 STANDALONE_SUBDIR_TARGETS+= \
54 all-man buildconfig buildfiles buildincludes check checkdpadd \
55 clean cleandepend cleandir cleanilinks cleanobj files includes \
56 installconfig installdirs installincludes installfiles print-dir \
57 maninstall manlint obj objlink
59 # It is safe to install in parallel when staging.
60 .if defined(NO_ROOT) || !empty(SYSROOT)
61 STANDALONE_SUBDIR_TARGETS+= realinstall
64 .include <bsd.init.mk>
66 .if ${MK_META_MODE} == "yes"
75 .if ${RELDIR:U.} != "."
81 .if ${MK_AUTO_OBJ} == "yes" && !target(obj)
85 .if !defined(NEED_SUBDIR)
86 # .MAKE.DEPENDFILE==/dev/null is set by bsd.dep.mk to avoid reading
88 .if ${.MAKE.LEVEL} == 0 && ${MK_DIRDEPS_BUILD} == "yes" && !empty(SUBDIR) && \
89 ${.MAKE.DEPENDFILE} != "/dev/null"
90 .include <meta.subdir.mk>
97 .if !target(distribute)
99 .for dist in ${DISTRIBUTION}
100 ${_+_}cd ${.CURDIR}; \
101 ${MAKE} install installconfig -DNO_SUBDIR DISTBASE=/${dist} DESTDIR=${DISTDIR}/${dist} SHARED=copies
104 # Convenience targets to run 'build${target}' and 'install${target}' when
105 # calling 'make ${target}'.
106 .for __target in files includes
107 .if !target(${__target})
108 ${__target}: build${__target} install${__target}
109 .ORDER: build${__target} install${__target}
113 # Make 'install' supports a before and after target. Actual install
114 # hooks are placed in 'realinstall'.
116 .for __stage in before real after
117 .if !target(${__stage}install)
121 install: beforeinstall realinstall afterinstall
122 .ORDER: beforeinstall realinstall afterinstall
126 # SUBDIR recursing may be disabled for MK_DIRDEPS_BUILD
129 .if defined(SUBDIR) || defined(SUBDIR.yes) || defined(SUBDIR.yes.yes)
130 SUBDIR:=${SUBDIR} ${SUBDIR.yes} ${SUBDIR.yes.yes}
135 .error ${.CURDIR}: Found variable SUBDIR. with value "${SUBDIR.}". This was \
136 probably caused by using SUBDIR.$${MK_FOO} without including \
137 <src.opts.mk> or by using an invalid $${MK_FOO} option.
140 # Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL.
142 if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
143 dir=$${dir}.${MACHINE_ARCH}; \
145 ${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \
146 cd ${.CURDIR}/$${dir}; \
147 ${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/
149 # This is kept for compatibility only. The normal handling of attaching to
150 # SUBDIR_TARGETS will create a target for each directory.
152 .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
153 @${_+_}target=${.TARGET:realinstall=install}; \
154 for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done
157 # Create 'make subdir' targets to run the real 'all' target.
158 .for __dir in ${SUBDIR:N.WAIT}
159 ${__dir}: all_subdir_${DIRPRFX}${__dir} .PHONY
162 .for __target in ${SUBDIR_TARGETS}
163 # Can ordering be skipped for this and SUBDIR_PARALLEL forced?
164 .if ${STANDALONE_SUBDIR_TARGETS:M${__target}}
165 _is_standalone_target= 1
166 _subdir_filter= N.WAIT
168 _is_standalone_target= 0
172 .for __dir in ${SUBDIR:${_subdir_filter}}
173 .if ${__dir} == .WAIT
174 __subdir_targets+= .WAIT
177 .if ${_is_standalone_target} == 0
178 .if defined(SUBDIR_PARALLEL)
179 # Apply SUBDIR_DEPEND dependencies for SUBDIR_PARALLEL.
180 .for __dep in ${SUBDIR_DEPEND_${__dir}}
181 __deps+= ${__target}_subdir_${DIRPRFX}${__dep}
184 # For non-parallel builds, directories depend on all targets before them.
185 __deps:= ${__subdir_targets}
186 .endif # defined(SUBDIR_PARALLEL)
187 .endif # ${_is_standalone_target} == 0
188 ${__target}_subdir_${DIRPRFX}${__dir}: .PHONY .MAKE .SILENT ${__deps}
189 @${_+_}target=${__target:realinstall=install}; \
192 __subdir_targets+= ${__target}_subdir_${DIRPRFX}${__dir}
193 .endif # ${__dir} == .WAIT
194 .endfor # __dir in ${SUBDIR}
196 # Attach the subdir targets to the real target.
197 # Only recurse on directly-called targets. I.e., don't recurse on dependencies
198 # such as 'install' becoming {before,real,after}install, just recurse
199 # 'install'. Despite that, 'realinstall' is special due to ordering issues
200 # with 'afterinstall'.
201 .if !defined(NO_SUBDIR) && (make(${__target}) || \
202 (${__target} == realinstall && make(install)))
203 ${__target}: ${__subdir_targets} .PHONY
204 .endif # make(${__target})
205 .endfor # __target in ${SUBDIR_TARGETS}
207 .endif # !target(_SUBDIR)
209 # Ensure all targets exist
210 .for __target in ${SUBDIR_TARGETS}
211 .if !target(${__target})