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 is automatically appended
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 \
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 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>
70 .if ${RELDIR:U.} != "."
76 .if ${MK_AUTO_OBJ} == "yes" && !target(obj)
80 .if !defined(NEED_SUBDIR)
81 # .MAKE.DEPENDFILE==/dev/null is set by bsd.dep.mk to avoid reading
83 .if ${.MAKE.LEVEL} == 0 && ${MK_DIRDEPS_BUILD} == "yes" && !empty(SUBDIR) && \
84 ${.MAKE.DEPENDFILE} != "/dev/null"
85 .include <meta.subdir.mk>
92 .if !target(distribute)
94 .for dist in ${DISTRIBUTION}
95 ${_+_}cd ${.CURDIR}; \
96 ${MAKE} install installconfig -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
99 # Convenience targets to run 'build${target}' and 'install${target}' when
100 # calling 'make ${target}'.
101 .for __target in files includes
102 .if !target(${__target})
103 ${__target}: build${__target} install${__target}
104 .ORDER: build${__target} install${__target}
108 # Make 'install' supports a before and after target. Actual install
109 # hooks are placed in 'realinstall'.
111 .for __stage in before real after
112 .if !target(${__stage}install)
116 install: beforeinstall realinstall afterinstall
117 .ORDER: beforeinstall realinstall afterinstall
121 # SUBDIR recursing may be disabled for MK_DIRDEPS_BUILD
124 .if defined(SUBDIR) || defined(SUBDIR.yes)
125 SUBDIR:=${SUBDIR} ${SUBDIR.yes}
129 # Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL.
131 if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
132 dir=$${dir}.${MACHINE_ARCH}; \
134 ${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \
135 cd ${.CURDIR}/$${dir}; \
136 ${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/
138 # This is kept for compatibility only. The normal handling of attaching to
139 # SUBDIR_TARGETS will create a target for each directory.
141 .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
142 @${_+_}target=${.TARGET:realinstall=install}; \
143 for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done
146 # Create 'make subdir' targets to run the real 'all' target.
147 .for __dir in ${SUBDIR:N.WAIT}
148 ${__dir}: all_subdir_${DIRPRFX}${__dir} .PHONY
151 .for __target in ${SUBDIR_TARGETS}
152 # Can ordering be skipped for this and SUBDIR_PARALLEL forced?
153 .if ${STANDALONE_SUBDIR_TARGETS:M${__target}}
154 _is_standalone_target= 1
155 _subdir_filter= N.WAIT
157 _is_standalone_target= 0
161 .for __dir in ${SUBDIR:${_subdir_filter}}
162 .if ${__dir} == .WAIT
163 __subdir_targets+= .WAIT
166 .if ${_is_standalone_target} == 0
167 .if defined(SUBDIR_PARALLEL)
168 # Apply SUBDIR_DEPEND dependencies for SUBDIR_PARALLEL.
169 .for __dep in ${SUBDIR_DEPEND_${__dir}}
170 __deps+= ${__target}_subdir_${DIRPRFX}${__dep}
173 # For non-parallel builds, directories depend on all targets before them.
174 __deps:= ${__subdir_targets}
175 .endif # defined(SUBDIR_PARALLEL)
176 .endif # ${_is_standalone_target} == 0
177 ${__target}_subdir_${DIRPRFX}${__dir}: .PHONY .MAKE .SILENT ${__deps}
178 @${_+_}target=${__target:realinstall=install}; \
181 __subdir_targets+= ${__target}_subdir_${DIRPRFX}${__dir}
182 .endif # ${__dir} == .WAIT
183 .endfor # __dir in ${SUBDIR}
185 # Attach the subdir targets to the real target.
186 # Only recurse on directly-called targets. I.e., don't recurse on dependencies
187 # such as 'install' becoming {before,real,after}install, just recurse
188 # 'install'. Despite that, 'realinstall' is special due to ordering issues
189 # with 'afterinstall'.
190 .if !defined(NO_SUBDIR) && (make(${__target}) || \
191 (${__target} == realinstall && make(install)))
192 ${__target}: ${__subdir_targets} .PHONY
193 .endif # make(${__target})
194 .endfor # __target in ${SUBDIR_TARGETS}
196 .endif # !target(_SUBDIR)
198 # Ensure all targets exist
199 .for __target in ${SUBDIR_TARGETS}
200 .if !target(${__target})