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