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