bsd.subdir.mk revision 289334
1# from: @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91 2# $FreeBSD: head/share/mk/bsd.subdir.mk 289334 2015-10-14 20:30:32Z bdrewery $ 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 32.if !target(__<bsd.subdir.mk>__) 33__<bsd.subdir.mk>__: 34 35ALL_SUBDIR_TARGETS= all all-man buildconfig checkdpadd clean cleandepend \ 36 cleandir cleanilinks cleanobj depend distribute \ 37 installconfig lint maninstall manlint obj objlink \ 38 realinstall regress tags \ 39 ${SUBDIR_TARGETS} 40 41.include <bsd.init.mk> 42 43.if !defined(NEED_SUBDIR) 44.if ${.MAKE.LEVEL} == 0 && ${MK_META_MODE} == "yes" && !empty(SUBDIR) && !(make(clean*) || make(destroy*)) 45.include <meta.subdir.mk> 46# ignore this 47_SUBDIR: 48.endif 49.endif 50.if !target(_SUBDIR) 51 52.if defined(SUBDIR) 53SUBDIR:=${SUBDIR} ${SUBDIR.yes} 54SUBDIR:=${SUBDIR:u} 55.endif 56 57DISTRIBUTION?= base 58.if !target(distribute) 59distribute: .MAKE 60.for dist in ${DISTRIBUTION} 61 ${_+_}cd ${.CURDIR}; \ 62 ${MAKE} install -DNO_SUBDIR DESTDIR=${DISTDIR}/${dist} SHARED=copies 63.endfor 64.endif 65 66_SUBDIR: .USE .MAKE 67.if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR) 68 @${_+_}for entry in ${SUBDIR:N.WAIT}; do \ 69 if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \ 70 ${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH} (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \ 71 edir=$${entry}.${MACHINE_ARCH}; \ 72 cd ${.CURDIR}/$${edir}; \ 73 else \ 74 ${ECHODIR} "===> ${DIRPRFX}$$entry (${.TARGET:S,realinstall,install,:S,^_sub.,,})"; \ 75 edir=$${entry}; \ 76 cd ${.CURDIR}/$${edir}; \ 77 fi; \ 78 ${MAKE} ${.TARGET:S,realinstall,install,:S,^_sub.,,} \ 79 DIRPRFX=${DIRPRFX}$$edir/; \ 80 done 81.endif 82 83${SUBDIR:N.WAIT}: .PHONY .MAKE 84 ${_+_}@if test -d ${.TARGET}.${MACHINE_ARCH}; then \ 85 cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \ 86 else \ 87 cd ${.CURDIR}/${.TARGET}; \ 88 fi; \ 89 ${MAKE} all 90 91# Work around parsing of .if nested in .for by putting .WAIT string into a var. 92__wait= .WAIT 93.for __target in ${ALL_SUBDIR_TARGETS} 94.ifdef SUBDIR_PARALLEL 95__subdir_targets= 96.for __dir in ${SUBDIR} 97.if ${__wait} == ${__dir} 98__subdir_targets+= .WAIT 99.else 100__subdir_targets+= ${__target}_subdir_${__dir} 101__deps= 102.for __dep in ${SUBDIR_DEPEND_${__dir}} 103__deps+= ${__target}_subdir_${__dep} 104.endfor 105${__target}_subdir_${__dir}: .MAKE ${__deps} 106.if !defined(NO_SUBDIR) 107 @${_+_}if test -d ${.CURDIR}/${__dir}.${MACHINE_ARCH}; then \ 108 ${ECHODIR} "===> ${DIRPRFX}${__dir}.${MACHINE_ARCH} (${__target:realinstall=install})"; \ 109 edir=${__dir}.${MACHINE_ARCH}; \ 110 cd ${.CURDIR}/$${edir}; \ 111 else \ 112 ${ECHODIR} "===> ${DIRPRFX}${__dir} (${__target:realinstall=install})"; \ 113 edir=${__dir}; \ 114 cd ${.CURDIR}/$${edir}; \ 115 fi; \ 116 ${MAKE} ${__target:realinstall=install} \ 117 DIRPRFX=${DIRPRFX}$$edir/ 118.endif 119.endif 120.endfor 121${__target}: ${__subdir_targets} 122.else 123${__target}: _sub.${__target} 124_sub.${__target}: _SUBDIR 125.endif 126.endfor 127 128# This is to support 'make includes' calling 'make buildincludes' and 129# 'make installincludes' in the proper order, and to support these 130# targets as SUBDIR_TARGETS. 131.for __target in files includes 132.for __stage in build install 133${__stage}${__target}: 134.if make(${__stage}${__target}) 135${__stage}${__target}: _sub.${__stage}${__target} 136_sub.${__stage}${__target}: _SUBDIR 137.endif 138.endfor 139.if !target(${__target}) 140${__target}: .MAKE 141 ${_+_}cd ${.CURDIR}; ${MAKE} build${__target}; ${MAKE} install${__target} 142.endif 143.endfor 144 145.endif 146 147.if !target(install) 148.if !target(beforeinstall) 149beforeinstall: 150.endif 151.if !target(afterinstall) 152afterinstall: 153.endif 154install: beforeinstall realinstall afterinstall 155.ORDER: beforeinstall realinstall afterinstall 156.endif 157 158.endif 159