From 67be553814c6242d4a801d26dc2f6e5ca4b1aa8a Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 29 Nov 2011 13:34:03 -0800 Subject: [PATCH] build - Support concurrent SUBDIR traversal, fix make depend bug * Support concurrent SUBDIR traversals during a make -j N. Create individual targets for each target/directory combination so Make will run them in parallel when possible. * SUBDIR_ORDERED, if it exists, indicates the subset of SUBDIR which must be ordered. Any directories not mentioned can run concurrently. * If SUBDIR_ORDERED does not exist at all then all directories default to being strongly ordered and will NOT run concurrently. * Try to make sure that all include files and generated source files are generated before running the depend core. --- share/mk/bsd.dep.mk | 16 +++++++++- share/mk/bsd.subdir.mk | 73 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/share/mk/bsd.dep.mk b/share/mk/bsd.dep.mk index 20f4931..9384cdf 100644 --- a/share/mk/bsd.dep.mk +++ b/share/mk/bsd.dep.mk @@ -105,7 +105,7 @@ ${_YC}: ${_YSRC} .if !target(depend) .if defined(SRCS) -depend: beforedepend ${DEPENDFILE} afterdepend +depend: beforedepend _dependincs ${DEPENDFILE} afterdepend # Different types of sources are compiled with slightly different flags. # Split up the sources, and filter out headers and non-applicable flags. @@ -185,7 +185,7 @@ ${DEPENDFILE}: _EXTRADEPEND .ORDER: ${_DEPENDFILES} ${DEPENDFILE} afterdepend .else -depend: beforedepend afterdepend +depend: beforedepend _dependincs afterdepend .endif .if !target(beforedepend) beforedepend: @@ -233,3 +233,15 @@ checkdpadd: fi .endif .endif + +.if defined(INCS) && make(depend) + +_dependincs: ${INCS} ${SRCS} + +.ORDER: _dependincs depend + +.else + +_dependincs: + +.endif diff --git a/share/mk/bsd.subdir.mk b/share/mk/bsd.subdir.mk index f17142b..02b9ae3 100644 --- a/share/mk/bsd.subdir.mk +++ b/share/mk/bsd.subdir.mk @@ -1,7 +1,3 @@ -# from: @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91 -# $FreeBSD: src/share/mk/bsd.subdir.mk,v 1.30.2.5 2002/07/22 14:21:51 ru Exp $ -# $DragonFly: src/share/mk/bsd.subdir.mk,v 1.4 2005/12/09 18:53:44 swildner Exp $ -# # The include file contains the default targets # for building subdirectories. # @@ -17,6 +13,11 @@ # Each of the targets will execute the same target in the # subdirectories. # +# SUBDIR_ORDERED A list of subdirectories which also must be included in +# in SUBDIR which have ordering requirements. If this +# Make variable does not exist then all subdirectories are +# assumed to be strictly ordered. +# # +++ targets +++ # # afterinstall, all, all-man, beforeinstall, checkdpadd, @@ -26,23 +27,55 @@ .include -_SUBDIR: .USE +# If SUBDIR_ORDERED not specified we default strongly ordering all +# subdirectories. +# +SUBDIR_ORDERED?= ${SUBDIR} + +__targets= \ + checkdpadd clean cleandepend cleandir cleanobj \ + obj objlink tags depend all all-man \ + maninstall realinstall \ + lint manlint regress \ + buildfiles buildincludes installfiles installincludes + +.for __target in ${__targets} + .if defined(SUBDIR) && !empty(SUBDIR) && !defined(NO_SUBDIR) - @for entry in ${SUBDIR}; do \ - if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \ - ${ECHODIR} "===> ${DIRPRFX}$${entry}.${MACHINE_ARCH}"; \ - edir=$${entry}.${MACHINE_ARCH}; \ + +_SUBDIR_${__target}: ${SUBDIR:S/^/_SUBDIR_${__target}_/} + +# Now create the command set for each subdirectory and target +# + +.for entry in ${SUBDIR} +_SUBDIR_${__target}_${entry}: + @(if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \ + ${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH}"; \ + edir=${entry}.${MACHINE_ARCH}; \ cd ${.CURDIR}/$${edir}; \ else \ - ${ECHODIR} "===> ${DIRPRFX}$$entry"; \ - edir=$${entry}; \ + ${ECHODIR} "===> ${DIRPRFX}${entry}"; \ + edir=${entry}; \ cd ${.CURDIR}/$${edir}; \ fi; \ - ${MAKE} ${.TARGET:realinstall=install} \ - DIRPRFX=${DIRPRFX}$$edir/; \ - done + ${MAKE} ${__target:realinstall=install} \ + DIRPRFX=${DIRPRFX}$$edir/;) + +.endfor + +# order subdirectories for each target, set up dependency +# +.ORDER: ${SUBDIR_ORDERED:S/^/_SUBDIR_${__target}_/} + +.else + +_SUBDIR_${__target}: .USE + .endif +.endfor + ${SUBDIR}:: @if test -d ${.TARGET}.${MACHINE_ARCH}; then \ cd ${.CURDIR}/${.TARGET}.${MACHINE_ARCH}; \ @@ -52,17 +85,15 @@ ${SUBDIR}:: ${MAKE} all -.for __target in all all-man checkdpadd clean cleandepend cleandir \ - depend lint maninstall manlint \ - obj objlink realinstall regress tags -${__target}: _SUBDIR +.for __target in ${__targets} +${__target}: _SUBDIR_${__target} .endfor .for __target in files includes .for __stage in build install ${__stage}${__target}: .if make(${__stage}${__target}) -${__stage}${__target}: _SUBDIR +${__stage}${__target}: _SUBDIR_${__stage}${__target} .endif .endfor ${__target}: @@ -80,6 +111,4 @@ install: beforeinstall realinstall afterinstall .ORDER: beforeinstall realinstall afterinstall .endif -.ORDER: clean cleandepend cleandir cleanobj \ - obj objlink tags depend all all-man \ - install maninstall realinstall +.ORDER: ${__targets:S/^/_SUBDIR_/} -- 1.7.7.2