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