From 17bec8aab27f339d56ef78603799dfb8bce913a6 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sun, 3 Jul 2016 22:22:00 +0100 Subject: [PATCH] wmakeLnIncludeAll: Added -j option for parallel operation --- wmake/wmakeLnIncludeAll | 77 ++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/wmake/wmakeLnIncludeAll b/wmake/wmakeLnIncludeAll index 7c4c3fa8ac..4aedc1257f 100755 --- a/wmake/wmakeLnIncludeAll +++ b/wmake/wmakeLnIncludeAll @@ -39,10 +39,15 @@ usage() { while [ "$#" -ge 1 ]; do echo "$1"; shift; done cat< /dev/null 2>&1 \ + && shift && nCores=$1 + echo "$Script: enabled on $nCores cores" + ;; + # Parallel compilation on specified number of cores + -j*) + nCores=${1#-j} + echo "$Script: enabled on $nCores cores" + ;; + -*) + usage "unknown option: '$*'" + ;; + *) + break + ;; esac + shift done +FAIL=0 +echo "$Script: starting wmakeLnInclude processes" + # Default to searching from CWD [ "$#" -gt 0 ] || set -- . @@ -93,7 +115,20 @@ do then if grep -e '^ *LIB *=' "$MakeDir/files" >/dev/null 2>&1 then - wmakeLnInclude -update $topDir + # If running in parallel start wmakeLnInclude on nCores + # and more as the cores become free + if [ "$nCores" -gt 0 ] + then + joblist=($(jobs -p)) + while (( ${#joblist[*]} > $nCores )) + do + sleep 0.01 + joblist=($(jobs -p)) + done + wmakeLnInclude -update $topDir & + else + wmakeLnInclude -update $topDir + fi elif [ -d "$topDir/lnInclude" ] then echo "removing spurious $topDir/lnInclude" @@ -103,6 +138,22 @@ do done done +# If running in parallel wait until all wmakeLnInclude jobs are complete +if [ "$nCores" -gt 0 ] +then + for job in $(jobs -p) + do + echo $job + wait $job || let "FAIL+=1" + done + + if [ "$FAIL" == "0" ]; + then + echo "$Script: completed wmakeLnInclude processes" + else + echo "$Script: failed ($FAIL)" + fi +fi #------------------------------------------------------------------------------ # Cleanup local variables and functions