1 # from: @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91
4 # The include file <bsd.subdir.mk> contains the default targets
5 # for building subdirectories.
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.
15 # DISTRIBUTION Name of distribution. [base]
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 and SUBDIR.yes.yes are
20 # automatically appended to this list.
25 # This is a variant of install, which will
26 # put the stuff into the right "distribution".
28 # See SUBDIR_TARGETS for list of targets that will recurse.
30 # Targets defined in STANDALONE_SUBDIR_TARGETS will always be ran
31 # with SUBDIR_PARALLEL and will not respect .WAIT or SUBDIR_DEPEND_
34 # SUBDIR_TARGETS and STANDALONE_SUBDIR_TARGETS can be appended to
35 # via make.conf or src.conf.
38 .if !target(__<bsd.subdir.mk>__)
41 .if ${MK_AUTO_OBJ} == "no"
46 all all-man analyze buildconfig buildfiles buildincludes \
47 checkdpadd clean cleandepend cleandir cleanilinks \
48 cleanobj depend distribute files includes installconfig \
50 installfiles installincludes print-dir realinstall \
51 maninstall manlint ${_obj} objlink tags \
54 STANDALONE_SUBDIR_TARGETS+= \
55 all-man buildconfig buildfiles buildincludes check checkdpadd \
56 clean cleandepend cleandir cleanilinks cleanobj files includes \
57 installconfig installdirs installincludes installfiles print-dir \
58 maninstall manlint obj objlink
60 # It is safe to install in parallel when staging.
61 .if defined(NO_ROOT) || !empty(SYSROOT)
62 STANDALONE_SUBDIR_TARGETS+= realinstall
65 .include <bsd.init.mk>
67 .if ${MK_META_MODE} == "yes"
76 .if ${RELDIR:U.} != "."
82 .if ${MK_AUTO_OBJ} == "yes" && !target(obj)
86 .if !defined(NEED_SUBDIR)
87 # .MAKE.DEPENDFILE==/dev/null is set by bsd.dep.mk to avoid reading
89 .if ${.MAKE.LEVEL} == 0 && ${MK_DIRDEPS_BUILD} == "yes" && !empty(SUBDIR) && \
90 ${.MAKE.DEPENDFILE} != "/dev/null"
91 .include <meta.subdir.mk>
98 .if !target(distribute)
100 .for dist in ${DISTRIBUTION}
101 ${_+_}cd ${.CURDIR}; \
102 ${MAKE} install installconfig -DNO_SUBDIR DISTBASE=/${dist} DESTDIR=${DISTDIR}/${dist} SHARED=copies
105 # Convenience targets to run 'build${target}' and 'install${target}' when
106 # calling 'make ${target}'.
107 .for __target in files includes
108 .if !target(${__target})
109 ${__target}: build${__target} install${__target}
110 .ORDER: build${__target} install${__target}
114 # Make 'install' supports a before and after target. Actual install
115 # hooks are placed in 'realinstall'.
117 .for __stage in before real after
118 .if !target(${__stage}install)
122 install: beforeinstall realinstall afterinstall
123 .ORDER: beforeinstall realinstall afterinstall
127 # SUBDIR recursing may be disabled for MK_DIRDEPS_BUILD
130 .if defined(SUBDIR) || defined(SUBDIR.yes) || defined(SUBDIR.yes.yes)
131 SUBDIR:=${SUBDIR} ${SUBDIR.yes} ${SUBDIR.yes.yes}
136 .error ${.CURDIR}: Found variable SUBDIR. with value "${SUBDIR.}". This was \
137 probably caused by using SUBDIR.$${MK_FOO} without including \
138 <src.opts.mk> or by using an invalid $${MK_FOO} option.
141 # Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL.
143 if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
144 dir=$${dir}.${MACHINE_ARCH}; \
146 ${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \
147 cd ${.CURDIR}/$${dir}; \
148 ${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/
150 # This is kept for compatibility only. The normal handling of attaching to
151 # SUBDIR_TARGETS will create a target for each directory.
153 .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
154 @${_+_}target=${.TARGET:realinstall=install}; \
155 for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done
158 # Create 'make subdir' targets to run the real 'all' target.
159 .for __dir in ${SUBDIR:N.WAIT}
160 ${__dir}: all_subdir_${DIRPRFX}${__dir} .PHONY
163 .for __target in ${SUBDIR_TARGETS}
164 # Can ordering be skipped for this and SUBDIR_PARALLEL forced?
165 .if ${STANDALONE_SUBDIR_TARGETS:M${__target}}
166 _is_standalone_target= 1
167 _subdir_filter= N.WAIT
169 _is_standalone_target= 0
173 .for __dir in ${SUBDIR:${_subdir_filter}}
174 .if ${__dir} == .WAIT
175 __subdir_targets+= .WAIT
178 .if ${_is_standalone_target} == 0
179 .if defined(SUBDIR_PARALLEL)
180 # Apply SUBDIR_DEPEND dependencies for SUBDIR_PARALLEL.
181 .for __dep in ${SUBDIR_DEPEND_${__dir}}
182 __deps+= ${__target}_subdir_${DIRPRFX}${__dep}
185 # For non-parallel builds, directories depend on all targets before them.
186 __deps:= ${__subdir_targets}
187 .endif # defined(SUBDIR_PARALLEL)
188 .endif # ${_is_standalone_target} == 0
189 ${__target}_subdir_${DIRPRFX}${__dir}: .PHONY .MAKE .SILENT ${__deps}
190 @${_+_}target=${__target:realinstall=install}; \
193 __subdir_targets+= ${__target}_subdir_${DIRPRFX}${__dir}
194 .endif # ${__dir} == .WAIT
195 .endfor # __dir in ${SUBDIR}
197 # Attach the subdir targets to the real target.
198 # Only recurse on directly-called targets. I.e., don't recurse on dependencies
199 # such as 'install' becoming {before,real,after}install, just recurse
200 # 'install'. Despite that, 'realinstall' is special due to ordering issues
201 # with 'afterinstall'.
202 .if !defined(NO_SUBDIR) && (make(${__target}) || \
203 (${__target} == realinstall && make(install)))
204 ${__target}: ${__subdir_targets} .PHONY
205 .endif # make(${__target})
206 .endfor # __target in ${SUBDIR_TARGETS}
208 .endif # !target(_SUBDIR)
210 # Ensure all targets exist
211 .for __target in ${SUBDIR_TARGETS}
212 .if !target(${__target})