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>__)
42 all all-man analyze buildconfig buildfiles buildincludes \
43 checkdpadd clean cleandepend cleandir cleanilinks \
44 cleanobj depend distribute files includes installconfig \
45 installfiles installincludes print-dir realinstall lint \
46 maninstall manlint obj objlink tags \
49 STANDALONE_SUBDIR_TARGETS+= \
50 all-man buildconfig buildfiles buildincludes check checkdpadd \
51 clean cleandepend cleandir cleanilinks cleanobj files includes \
52 installconfig installincludes installfiles print-dir \
53 maninstall manlint obj objlink
55 # It is safe to install in parallel when staging.
57 STANDALONE_SUBDIR_TARGETS+= realinstall
60 .include <bsd.init.mk>
66 .if ${RELDIR:U.} != "."
72 .if !defined(NEED_SUBDIR)
73 # .MAKE.DEPENDFILE==/dev/null is set by bsd.dep.mk to avoid reading
75 .if ${.MAKE.LEVEL} == 0 && ${MK_DIRDEPS_BUILD} == "yes" && !empty(SUBDIR) && \
76 ${.MAKE.DEPENDFILE} != "/dev/null"
77 .include <meta.subdir.mk>
84 .if !target(distribute)
86 .for dist in ${DISTRIBUTION}
87 ${_+_}cd ${.CURDIR}; \
88 ${MAKE} install installconfig -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies
91 # Convenience targets to run 'build${target}' and 'install${target}' when
92 # calling 'make ${target}'.
93 .for __target in files includes
94 .if !target(${__target})
95 ${__target}: build${__target} install${__target}
96 .ORDER: build${__target} install${__target}
100 # Make 'install' supports a before and after target. Actual install
101 # hooks are placed in 'realinstall'.
103 .for __stage in before real after
104 .if !target(${__stage}install)
108 install: beforeinstall realinstall afterinstall
109 .ORDER: beforeinstall realinstall afterinstall
113 # SUBDIR recursing may be disabled for MK_DIRDEPS_BUILD
116 .if defined(SUBDIR) || defined(SUBDIR.yes)
117 SUBDIR:=${SUBDIR} ${SUBDIR.yes}
121 # Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL.
123 if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \
124 dir=$${dir}.${MACHINE_ARCH}; \
126 ${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \
127 cd ${.CURDIR}/$${dir}; \
128 ${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/
131 .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR)
132 @${_+_}target=${.TARGET:realinstall=install}; \
133 for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done
136 ${SUBDIR:N.WAIT}: .PHONY .MAKE
141 .for __target in ${SUBDIR_TARGETS}
142 # Only recurse on directly-called targets. I.e., don't recurse on dependencies
143 # such as 'install' becoming {before,real,after}install, just recurse
144 # 'install'. Despite that, 'realinstall' is special due to ordering issues
145 # with 'afterinstall'.
146 .if !defined(NO_SUBDIR) && (make(${__target}) || \
147 (${__target} == realinstall && make(install)))
148 # Can ordering be skipped for this and SUBDIR_PARALLEL forced?
149 .if ${STANDALONE_SUBDIR_TARGETS:M${__target}}
150 _is_standalone_target= 1
151 SUBDIR:= ${SUBDIR:N.WAIT}
153 _is_standalone_target= 0
155 .if defined(SUBDIR_PARALLEL) || ${_is_standalone_target} == 1
157 .for __dir in ${SUBDIR}
158 .if ${__dir} == .WAIT
159 __subdir_targets+= .WAIT
161 __subdir_targets+= ${__target}_subdir_${DIRPRFX}${__dir}
163 .if ${_is_standalone_target} == 0
164 .for __dep in ${SUBDIR_DEPEND_${__dir}}
165 __deps+= ${__target}_subdir_${DIRPRFX}${__dep}
168 ${__target}_subdir_${DIRPRFX}${__dir}: .PHONY .MAKE .SILENT ${__deps}
169 @${_+_}target=${__target:realinstall=install}; \
173 .endfor # __dir in ${SUBDIR}
174 ${__target}: ${__subdir_targets} .PHONY
176 ${__target}: _SUBDIR .PHONY
177 .endif # SUBDIR_PARALLEL || _is_standalone_target
178 .endif # make(${__target})
179 .endfor # __target in ${SUBDIR_TARGETS}
181 .endif # !target(_SUBDIR)
183 # Ensure all targets exist
184 .for __target in ${SUBDIR_TARGETS}
185 .if !target(${__target})