1# The include file <bsd.subdir.mk> contains the default targets 2# for building subdirectories. 3# 4# For all of the directories listed in the variable SUBDIRS, the 5# specified directory will be visited and the target made. There is 6# also a default target which allows the command "make subdir" where 7# subdir is any directory listed in the variable SUBDIRS. 8# 9# 10# +++ variables +++ 11# 12# DISTRIBUTION Name of distribution. [base] 13# 14# SUBDIR A list of subdirectories that should be built as well. 15# Each of the targets will execute the same target in the 16# subdirectories. SUBDIR.yes and SUBDIR.yes.yes are 17# automatically appended to this list. 18# 19# +++ targets +++ 20# 21# distribute: 22# This is a variant of install, which will 23# put the stuff into the right "distribution". 24# 25# See SUBDIR_TARGETS for list of targets that will recurse. 26# 27# Targets defined in STANDALONE_SUBDIR_TARGETS will always be ran 28# with SUBDIR_PARALLEL and will not respect .WAIT or SUBDIR_DEPEND_ 29# values. 30# 31# SUBDIR_TARGETS and STANDALONE_SUBDIR_TARGETS can be appended to 32# via make.conf or src.conf. 33# 34 35.if !target(__<bsd.subdir.mk>__) 36__<bsd.subdir.mk>__: 37 38.if ${MK_AUTO_OBJ} == "no" 39_obj= obj 40.endif 41 42SUBDIR_TARGETS+= \ 43 all all-man analyze buildconfig buildfiles buildincludes \ 44 checkdpadd clean cleandepend cleandir cleanilinks \ 45 cleanobj depend distribute files includes installconfig \ 46 installdirs \ 47 installfiles installincludes print-dir realinstall \ 48 maninstall manlint ${_obj} objlink tags \ 49 50# Described above. 51STANDALONE_SUBDIR_TARGETS+= \ 52 all-man buildconfig buildfiles buildincludes check checkdpadd \ 53 clean cleandepend cleandir cleanilinks cleanobj files includes \ 54 installconfig installdirs installincludes installfiles print-dir \ 55 maninstall manlint obj objlink 56 57.include <bsd.init.mk> 58 59.if ${MK_META_MODE} == "yes" 60.MAKE.JOB.PREFIX= 61ECHODIR= : 62.endif 63 64.if make(print-dir) 65NEED_SUBDIR= 1 66ECHODIR= : 67.SILENT: 68.if ${RELDIR:U.} != "." 69print-dir: .PHONY 70 @echo ${RELDIR} 71.endif 72.endif 73 74.if ${MK_AUTO_OBJ} == "yes" && !target(obj) 75obj: .PHONY 76.endif 77 78.if !defined(NEED_SUBDIR) 79# .MAKE.DEPENDFILE==/dev/null is set by bsd.dep.mk to avoid reading 80# Makefile.depend 81.if ${.MAKE.LEVEL} == 0 && ${MK_DIRDEPS_BUILD} == "yes" && !empty(SUBDIR) && \ 82 ${.MAKE.DEPENDFILE} != "/dev/null" 83.include <meta.subdir.mk> 84# ignore this 85_SUBDIR: 86.endif 87.endif 88 89DISTRIBUTION?= base 90.if !target(distribute) 91distribute: .MAKE 92.for dist in ${DISTRIBUTION} 93 ${_+_}cd ${.CURDIR}; \ 94 ${MAKE} install installconfig -DNO_SUBDIR DISTBASE=/${dist} DESTDIR=${DISTDIR}/${dist} SHARED=copies 95.endfor 96.endif 97# Convenience targets to run 'build${target}' and 'install${target}' when 98# calling 'make ${target}'. 99.for __target in files includes 100.if !target(${__target}) 101${__target}: build${__target} install${__target} 102.ORDER: build${__target} install${__target} 103.endif 104.endfor 105 106# Make 'install' supports a before and after target. Actual install 107# hooks are placed in 'realinstall'. 108.if !target(install) 109.for __stage in before real after 110.if !target(${__stage}install) 111${__stage}install: 112.endif 113.endfor 114install: beforeinstall realinstall afterinstall 115.ORDER: beforeinstall realinstall afterinstall 116.endif 117.ORDER: all install 118 119# SUBDIR recursing may be disabled for MK_DIRDEPS_BUILD 120.if !target(_SUBDIR) 121 122.if defined(SUBDIR) || defined(SUBDIR.yes) || defined(SUBDIR.yes.yes) 123SUBDIR:=${SUBDIR} ${SUBDIR.yes} ${SUBDIR.yes.yes} 124SUBDIR:=${SUBDIR:u} 125.endif 126 127.if defined(SUBDIR.) 128.error ${.CURDIR}: Found variable SUBDIR. with value "${SUBDIR.}". This was \ 129 probably caused by using SUBDIR.$${MK_FOO} without including \ 130 <src.opts.mk> or by using an invalid $${MK_FOO} option. 131.endif 132 133# Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL. 134_SUBDIR_SH= \ 135 if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \ 136 dir=$${dir}.${MACHINE_ARCH}; \ 137 fi; \ 138 ${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \ 139 cd ${.CURDIR}/$${dir}; \ 140 ${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/ 141 142# This is kept for compatibility only. The normal handling of attaching to 143# SUBDIR_TARGETS will create a target for each directory. 144_SUBDIR: .USEBEFORE 145.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR) 146 @${_+_}target=${.TARGET:realinstall=install}; \ 147 for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done 148.endif 149 150# Create 'make subdir' targets to run the real 'all' target. 151.for __dir in ${SUBDIR:N.WAIT} 152${__dir}: all_subdir_${DIRPRFX}${__dir} .PHONY 153.endfor 154 155.for __target in ${SUBDIR_TARGETS} 156# Can ordering be skipped for this and SUBDIR_PARALLEL forced? 157.if ${STANDALONE_SUBDIR_TARGETS:M${__target}} 158_is_standalone_target= 1 159_subdir_filter= N.WAIT 160.else 161_is_standalone_target= 0 162_subdir_filter= 163.endif 164__subdir_targets= 165.for __dir in ${SUBDIR:${_subdir_filter}} 166.if ${__dir} == .WAIT 167__subdir_targets+= .WAIT 168.else 169__deps= 170.if ${_is_standalone_target} == 0 171.if defined(SUBDIR_PARALLEL) 172# Apply SUBDIR_DEPEND dependencies for SUBDIR_PARALLEL. 173.for __dep in ${SUBDIR_DEPEND_${__dir}} 174__deps+= ${__target}_subdir_${DIRPRFX}${__dep} 175.endfor 176.else 177# For non-parallel builds, directories depend on all targets before them. 178__deps:= ${__subdir_targets} 179.endif # defined(SUBDIR_PARALLEL) 180.endif # ${_is_standalone_target} == 0 181${__target}_subdir_${DIRPRFX}${__dir}: .PHONY .MAKE .SILENT ${__deps} 182 @${_+_}target=${__target:realinstall=install}; \ 183 dir=${__dir}; \ 184 ${_SUBDIR_SH}; 185__subdir_targets+= ${__target}_subdir_${DIRPRFX}${__dir} 186.endif # ${__dir} == .WAIT 187.endfor # __dir in ${SUBDIR} 188 189# Attach the subdir targets to the real target. 190# Only recurse on directly-called targets. I.e., don't recurse on dependencies 191# such as 'install' becoming {before,real,after}install, just recurse 192# 'install'. Despite that, 'realinstall' is special due to ordering issues 193# with 'afterinstall'. 194.if !defined(NO_SUBDIR) && (make(${__target}) || \ 195 (${__target} == realinstall && make(install))) 196${__target}: ${__subdir_targets} .PHONY 197.endif # make(${__target}) 198.endfor # __target in ${SUBDIR_TARGETS} 199 200.endif # !target(_SUBDIR) 201 202# Ensure all targets exist 203.for __target in ${SUBDIR_TARGETS} 204.if !target(${__target}) 205${__target}: 206.endif 207.endfor 208 209.endif 210