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>__: .NOTMAIN 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.if ${MK_DIRDEPS_BUILD} == "yes" 80# ignore this 81_SUBDIR: 82# .MAKE.DEPENDFILE==/dev/null is set by bsd.dep.mk to avoid reading 83# Makefile.depend 84.if ${.MAKE.LEVEL} == 0 && !empty(SUBDIR) && ${.MAKE.DEPENDFILE} != "/dev/null" 85.include <meta.subdir.mk> 86.endif 87.endif 88.endif 89 90DISTRIBUTION?= base 91.if !target(distribute) 92distribute: .MAKE 93.for dist in ${DISTRIBUTION} 94 ${_+_}cd ${.CURDIR}; \ 95 ${MAKE} install installconfig -DNO_SUBDIR DISTBASE=/${dist} DESTDIR=${DISTDIR}/${dist} SHARED=copies 96.endfor 97.endif 98# Convenience targets to run 'build${target}' and 'install${target}' when 99# calling 'make ${target}'. 100.for __target in files includes 101.if !target(${__target}) 102${__target}: build${__target} install${__target} 103.ORDER: build${__target} install${__target} 104.endif 105.endfor 106 107# Make 'install' supports a before and after target. Actual install 108# hooks are placed in 'realinstall'. 109.if !target(install) 110.for __stage in before real after 111.if !target(${__stage}install) 112${__stage}install: 113.endif 114.endfor 115install: beforeinstall realinstall afterinstall 116.ORDER: beforeinstall realinstall afterinstall 117.endif 118.ORDER: all install 119 120# SUBDIR recursing may be disabled for MK_DIRDEPS_BUILD 121.if !target(_SUBDIR) 122 123.if defined(SUBDIR) || defined(SUBDIR.yes) || defined(SUBDIR.yes.yes) 124SUBDIR:=${SUBDIR} ${SUBDIR.yes} ${SUBDIR.yes.yes} 125SUBDIR:=${SUBDIR:u} 126.endif 127 128.if defined(SUBDIR.) 129.error ${.CURDIR}: Found variable 'SUBDIR.' with value "${SUBDIR.}". This was\ 130 probably caused by using SUBDIR.$${MK_FOO} without including\ 131 <src.opts.mk> or by using an invalid $${MK_FOO} option. 132.endif 133 134# Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL. 135_SUBDIR_SH= \ 136 if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \ 137 dir=$${dir}.${MACHINE_ARCH}; \ 138 fi; \ 139 ${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \ 140 cd ${.CURDIR}/$${dir}; \ 141 ${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/ 142 143# This is kept for compatibility only. The normal handling of attaching to 144# SUBDIR_TARGETS will create a target for each directory. 145_SUBDIR: .USEBEFORE 146.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR) 147 @${_+_}target=${.TARGET:realinstall=install}; \ 148 for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done 149.endif 150 151# Create 'make subdir' targets to run the real 'all' target. 152.for __dir in ${SUBDIR:N.WAIT} 153${__dir}: all_subdir_${DIRPRFX}${__dir} .PHONY 154.endfor 155 156.for __target in ${SUBDIR_TARGETS} 157# Can ordering be skipped for this and SUBDIR_PARALLEL forced? 158.if ${STANDALONE_SUBDIR_TARGETS:M${__target}} 159_is_standalone_target= 1 160_subdir_filter= N.WAIT 161.else 162_is_standalone_target= 0 163_subdir_filter= 164.endif 165__subdir_targets= 166.for __dir in ${SUBDIR:${_subdir_filter}} 167.if ${__dir} == .WAIT 168__subdir_targets+= .WAIT 169.else 170__deps= 171.if ${_is_standalone_target} == 0 172.if defined(SUBDIR_PARALLEL) 173# Apply SUBDIR_DEPEND dependencies for SUBDIR_PARALLEL. 174.for __dep in ${SUBDIR_DEPEND_${__dir}} 175__deps+= ${__target}_subdir_${DIRPRFX}${__dep} 176.endfor 177.else 178# For non-parallel builds, directories depend on all targets before them. 179__deps:= ${__subdir_targets} 180.endif # defined(SUBDIR_PARALLEL) 181.endif # ${_is_standalone_target} == 0 182${__target}_subdir_${DIRPRFX}${__dir}: .PHONY .MAKE .SILENT ${__deps} 183 @${_+_}target=${__target:realinstall=install}; \ 184 dir=${__dir}; \ 185 ${_SUBDIR_SH}; 186__subdir_targets+= ${__target}_subdir_${DIRPRFX}${__dir} 187.endif # ${__dir} == .WAIT 188.endfor # __dir in ${SUBDIR} 189 190# Attach the subdir targets to the real target. 191# Only recurse on directly-called targets. I.e., don't recurse on dependencies 192# such as 'install' becoming {before,real,after}install, just recurse 193# 'install'. Despite that, 'realinstall' is special due to ordering issues 194# with 'afterinstall'. 195.if !defined(NO_SUBDIR) && (make(${__target}) || \ 196 (${__target} == realinstall && make(install))) 197${__target}: ${__subdir_targets} .PHONY 198.endif # make(${__target}) 199.endfor # __target in ${SUBDIR_TARGETS} 200 201.endif # !target(_SUBDIR) 202 203# Ensure all targets exist 204.for __target in ${SUBDIR_TARGETS} 205.if !target(${__target}) 206${__target}: 207.endif 208.endfor 209 210.endif 211