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>
71 .if ${RELDIR:U.} != "."
77 .if ${MK_AUTO_OBJ} == "yes" && !target(obj)
81 .if !defined(NEED_SUBDIR)
82 # .MAKE.DEPENDFILE==/dev/null is set by bsd.dep.mk to avoid reading
84 .if ${.MAKE.LEVEL} == 0 && ${MK_DIRDEPS_BUILD} == "yes" && !empty(SUBDIR) && \
85 ${.MAKE.DEPENDFILE} != "/dev/null"
86 .include <meta.subdir.mk>
93 .if !target(distribute)
95 .for dist in ${DISTRIBUTION}
96 ${_+_}cd ${.CURDIR}; \
97 ${MAKE} install installconfig -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
100 # Convenience targets to run 'build${target}' and 'install${target}' when
101 # calling 'make ${target}'.
102 .for __target in files includes
103 .if !target(${__target})
104 ${__target}: build${__target} install${__target}
105 .ORDER: build${__target} install${__target}
109 # Make 'install' supports a before and after target. Actual install
110 # hooks are placed in 'realinstall'.
112 .for __stage in before real after
113 .if !target(${__stage}install)
117 install: beforeinstall realinstall afterinstall
118 .ORDER: beforeinstall realinstall afterinstall
122 # SUBDIR recursing may be disabled for MK_DIRDEPS_BUILD
125 .if defined(SUBDIR) || defined(SUBDIR.yes) || defined(SUBDIR.yes.yes)
126 SUBDIR:=${SUBDIR} ${SUBDIR.yes} ${SUBDIR.yes.yes}
131 .error ${.CURDIR}: Found variable SUBDIR. with value "${SUBDIR.}". This was \
132 probably caused by using SUBDIR.$${MK_FOO} without including \
133 <src.opts.mk> or by using an invalid $${MK_FOO} option.
136 # Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL.
138 if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
139 dir=$${dir}.${MACHINE_ARCH}; \
141 ${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \
142 cd ${.CURDIR}/$${dir}; \
143 ${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/
145 # This is kept for compatibility only. The normal handling of attaching to
146 # SUBDIR_TARGETS will create a target for each directory.
148 .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
149 @${_+_}target=${.TARGET:realinstall=install}; \
150 for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done
153 # Create 'make subdir' targets to run the real 'all' target.
154 .for __dir in ${SUBDIR:N.WAIT}
155 ${__dir}: all_subdir_${DIRPRFX}${__dir} .PHONY
158 .for __target in ${SUBDIR_TARGETS}
159 # Can ordering be skipped for this and SUBDIR_PARALLEL forced?
160 .if ${STANDALONE_SUBDIR_TARGETS:M${__target}}
161 _is_standalone_target= 1
162 _subdir_filter= N.WAIT
164 _is_standalone_target= 0
168 .for __dir in ${SUBDIR:${_subdir_filter}}
169 .if ${__dir} == .WAIT
170 __subdir_targets+= .WAIT
173 .if ${_is_standalone_target} == 0
174 .if defined(SUBDIR_PARALLEL)
175 # Apply SUBDIR_DEPEND dependencies for SUBDIR_PARALLEL.
176 .for __dep in ${SUBDIR_DEPEND_${__dir}}
177 __deps+= ${__target}_subdir_${DIRPRFX}${__dep}
180 # For non-parallel builds, directories depend on all targets before them.
181 __deps:= ${__subdir_targets}
182 .endif # defined(SUBDIR_PARALLEL)
183 .endif # ${_is_standalone_target} == 0
184 ${__target}_subdir_${DIRPRFX}${__dir}: .PHONY .MAKE .SILENT ${__deps}
185 @${_+_}target=${__target:realinstall=install}; \
188 __subdir_targets+= ${__target}_subdir_${DIRPRFX}${__dir}
189 .endif # ${__dir} == .WAIT
190 .endfor # __dir in ${SUBDIR}
192 # Attach the subdir targets to the real target.
193 # Only recurse on directly-called targets. I.e., don't recurse on dependencies
194 # such as 'install' becoming {before,real,after}install, just recurse
195 # 'install'. Despite that, 'realinstall' is special due to ordering issues
196 # with 'afterinstall'.
197 .if !defined(NO_SUBDIR) && (make(${__target}) || \
198 (${__target} == realinstall && make(install)))
199 ${__target}: ${__subdir_targets} .PHONY
200 .endif # make(${__target})
201 .endfor # __target in ${SUBDIR_TARGETS}
203 .endif # !target(_SUBDIR)
205 # Ensure all targets exist
206 .for __target in ${SUBDIR_TARGETS}
207 .if !target(${__target})