1*0a6a1f1dSLionel Sambuc# $NetBSD: dotwait.mk,v 1.1 2014/08/21 13:44:51 apb Exp $ 2*0a6a1f1dSLionel Sambuc 3*0a6a1f1dSLionel SambucTHISMAKEFILE:= ${.PARSEDIR}/${.PARSEFILE} 4*0a6a1f1dSLionel Sambuc 5*0a6a1f1dSLionel SambucTESTS= simple recursive shared cycle 6*0a6a1f1dSLionel SambucPAUSE= sleep 1 7*0a6a1f1dSLionel Sambuc 8*0a6a1f1dSLionel Sambuc# Use a .for loop rather than dependencies here, to ensure 9*0a6a1f1dSLionel Sambuc# that the tests are run one by one, with parallelism 10*0a6a1f1dSLionel Sambuc# only within tests. 11*0a6a1f1dSLionel Sambuc# Ignore "--- target ---" lines printed by parallel make. 12*0a6a1f1dSLionel Sambucall: 13*0a6a1f1dSLionel Sambuc.for t in ${TESTS} 14*0a6a1f1dSLionel Sambuc @${.MAKE} -f ${THISMAKEFILE} -j4 $t | grep -v "^--- " 15*0a6a1f1dSLionel Sambuc.endfor 16*0a6a1f1dSLionel Sambuc 17*0a6a1f1dSLionel Sambuc# 18*0a6a1f1dSLionel Sambuc# Within each test, the names of the sub-targets follow these 19*0a6a1f1dSLionel Sambuc# conventions: 20*0a6a1f1dSLionel Sambuc# * If it's expected that two or more targets may be made in parallel, 21*0a6a1f1dSLionel Sambuc# then the target names will differ only in an alphabetic component 22*0a6a1f1dSLionel Sambuc# such as ".a" or ".b". 23*0a6a1f1dSLionel Sambuc# * If it's expected that two or more targets should be made in sequence 24*0a6a1f1dSLionel Sambuc# then the target names will differ in numeric components, such that 25*0a6a1f1dSLionel Sambuc# lexical ordering of the target names matches the expected order 26*0a6a1f1dSLionel Sambuc# in which the targets should be made. 27*0a6a1f1dSLionel Sambuc# 28*0a6a1f1dSLionel Sambuc# Targets may echo ${PARALLEL_TARG} to print a modified version 29*0a6a1f1dSLionel Sambuc# of their own name, in which alphabetic components like ".a" or ".b" 30*0a6a1f1dSLionel Sambuc# are converted to ".*". Two targets that are expected to 31*0a6a1f1dSLionel Sambuc# be made in parallel will thus print the same strings, so that the 32*0a6a1f1dSLionel Sambuc# output is independent of the order in which these targets are made. 33*0a6a1f1dSLionel Sambuc# 34*0a6a1f1dSLionel SambucPARALLEL_TARG= ${.TARGET:C/\.[a-z]/.*/g:Q} 35*0a6a1f1dSLionel Sambuc.DEFAULT: 36*0a6a1f1dSLionel Sambuc @echo ${PARALLEL_TARG}; ${PAUSE}; echo ${PARALLEL_TARG} 37*0a6a1f1dSLionel Sambuc_ECHOUSE: .USE 38*0a6a1f1dSLionel Sambuc @echo ${PARALLEL_TARG}; ${PAUSE}; echo ${PARALLEL_TARG} 39*0a6a1f1dSLionel Sambuc 40*0a6a1f1dSLionel Sambuc# simple: no recursion, no cycles 41*0a6a1f1dSLionel Sambucsimple: simple.1 .WAIT simple.2 42*0a6a1f1dSLionel Sambuc 43*0a6a1f1dSLionel Sambuc# recursive: all children of the left hand side of the .WAIT 44*0a6a1f1dSLionel Sambuc# must be made before any child of the right hand side. 45*0a6a1f1dSLionel Sambucrecursive: recursive.1.99 .WAIT recursive.2.99 46*0a6a1f1dSLionel Sambucrecursive.1.99: recursive.1.1.a recursive.1.1.b _ECHOUSE 47*0a6a1f1dSLionel Sambucrecursive.2.99: recursive.2.1.a recursive.2.1.b _ECHOUSE 48*0a6a1f1dSLionel Sambuc 49*0a6a1f1dSLionel Sambuc# shared: both shared.1.99 and shared.2.99 depend on shared.0. 50*0a6a1f1dSLionel Sambuc# shared.0 must be made first, even though it is a child of 51*0a6a1f1dSLionel Sambuc# the right hand side of the .WAIT. 52*0a6a1f1dSLionel Sambucshared: shared.1.99 .WAIT shared.2.99 53*0a6a1f1dSLionel Sambucshared.1.99: shared.0 _ECHOUSE 54*0a6a1f1dSLionel Sambucshared.2.99: shared.2.1 shared.0 _ECHOUSE 55*0a6a1f1dSLionel Sambuc 56*0a6a1f1dSLionel Sambuc# cycle: the cyclic dependency must not cause infinite recursion 57*0a6a1f1dSLionel Sambuc# leading to stack overflow and a crash. 58*0a6a1f1dSLionel Sambuccycle: cycle.1.99 .WAIT cycle.2.99 59*0a6a1f1dSLionel Sambuccycle.2.99: cycle.2.98 _ECHOUSE 60*0a6a1f1dSLionel Sambuccycle.2.98: cycle.2.97 _ECHOUSE 61*0a6a1f1dSLionel Sambuccycle.2.97: cycle.2.99 _ECHOUSE 62