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 appeneded 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 ALL_SUBDIR_TARGETS for list of targets that will recurse. 29# Custom targets can be added to SUBDIR_TARGETS in src.conf. 30# 31# Targets defined in STANDALONE_SUBDIR_TARGETS will always be ran 32# with SUBDIR_PARALLEL and will not respect .WAIT or SUBDIR_DEPEND_ 33# values. 34# 35 36.if !target(__<bsd.subdir.mk>__) 37__<bsd.subdir.mk>__: 38 39ALL_SUBDIR_TARGETS= all all-man buildconfig buildfiles buildincludes \ 40 checkdpadd clean cleandepend cleandir cleanilinks \ 41 cleanobj depend distribute files includes installconfig \ 42 installfiles installincludes realinstall lint maninstall \ 43 manlint obj objlink regress tags \ 44 ${SUBDIR_TARGETS} 45 46# Described above. 47STANDALONE_SUBDIR_TARGETS?= obj checkdpadd clean cleandepend cleandir \ 48 cleanilinks cleanobj 49 50.include <bsd.init.mk> 51 52.if !defined(NEED_SUBDIR) 53.if ${.MAKE.LEVEL} == 0 && ${MK_DIRDEPS_BUILD} == "yes" && !empty(SUBDIR) && !(make(clean*) || make(destroy*)) 54.include <meta.subdir.mk> 55# ignore this 56_SUBDIR: 57.endif 58.endif 59 60DISTRIBUTION?= base 61.if !target(distribute) 62distribute: .MAKE 63.for dist in ${DISTRIBUTION} 64 ${_+_}cd ${.CURDIR}; \ 65 ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies 66.endfor 67.endif 68 69# Convenience targets to run 'build${target}' and 'install${target}' when 70# calling 'make ${target}'. 71.for __target in files includes 72.if !target(${__target}) 73${__target}: build${__target} install${__target} 74.ORDER: build${__target} install${__target} 75.endif 76.endfor 77 78# Make 'install' supports a before and after target. Actual install 79# hooks are placed in 'realinstall'. 80.if !target(install) 81.for __stage in before real after 82.if !target(${__stage}install) 83${__stage}install: 84.endif 85.endfor 86install: beforeinstall realinstall afterinstall 87.ORDER: beforeinstall realinstall afterinstall 88.endif 89 90# SUBDIR recursing may be disabled for MK_DIRDEPS_BUILD 91.if !target(_SUBDIR) 92 93.if defined(SUBDIR) 94SUBDIR:=${SUBDIR} ${SUBDIR.yes} 95SUBDIR:=${SUBDIR:u} 96.endif 97 98# Subdir code shared among 'make <subdir>', 'make <target>' and SUBDIR_PARALLEL. 99_SUBDIR_SH= \ 100 if test -d ${.CURDIR}/$${dir}.${MACHINE_ARCH}; then \ 101 dir=$${dir}.${MACHINE_ARCH}; \ 102 fi; \ 103 ${ECHODIR} "===> ${DIRPRFX}$${dir} ($${target})"; \ 104 cd ${.CURDIR}/$${dir}; \ 105 ${MAKE} $${target} DIRPRFX=${DIRPRFX}$${dir}/ 106 107_SUBDIR: .USEBEFORE 108.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR) 109 @${_+_}target=${.TARGET:realinstall=install}; \ 110 for dir in ${SUBDIR:N.WAIT}; do ( ${_SUBDIR_SH} ); done 111.endif 112 113${SUBDIR:N.WAIT}: .PHONY .MAKE 114 ${_+_}@target=all; \ 115 dir=${.TARGET}; \ 116 ${_SUBDIR_SH}; 117 118.for __target in ${ALL_SUBDIR_TARGETS} 119# Only recurse on directly-called targets. I.e., don't recurse on dependencies 120# such as 'install' becoming {before,real,after}install, just recurse 121# 'install'. Despite that, 'realinstall' is special due to ordering issues 122# with 'afterinstall'. 123.if make(${__target}) || (${__target} == realinstall && make(install)) 124# Can ordering be skipped for this and SUBDIR_PARALLEL forced? 125.if ${STANDALONE_SUBDIR_TARGETS:M${__target}} 126_is_standalone_target= 1 127SUBDIR:= ${SUBDIR:N.WAIT} 128.else 129_is_standalone_target= 0 130.endif 131.if defined(SUBDIR_PARALLEL) || ${_is_standalone_target} == 1 132__subdir_targets= 133.for __dir in ${SUBDIR} 134.if ${__dir} == .WAIT 135__subdir_targets+= .WAIT 136.else 137__subdir_targets+= ${__target}_subdir_${__dir} 138__deps= 139.if ${_is_standalone_target} == 0 140.for __dep in ${SUBDIR_DEPEND_${__dir}} 141__deps+= ${__target}_subdir_${__dep} 142.endfor 143.endif 144${__target}_subdir_${__dir}: .PHONY .MAKE ${__deps} 145.if !defined(NO_SUBDIR) 146 @${_+_}target=${__target:realinstall=install}; \ 147 dir=${__dir}; \ 148 ${_SUBDIR_SH}; 149.endif 150.endif 151.endfor # __dir in ${SUBDIR} 152${__target}: ${__subdir_targets} 153.else 154${__target}: _SUBDIR 155.endif # SUBDIR_PARALLEL || _is_standalone_target 156.endif # make(${__target}) 157.endfor # __target in ${ALL_SUBDIR_TARGETS} 158 159.endif # !target(_SUBDIR) 160 161# Ensure all targets exist 162.for __target in ${ALL_SUBDIR_TARGETS} 163.if !target(${__target}) 164${__target}: 165.endif 166.endfor 167 168.endif 169