[PATCH 2/2] Add option to run bootstrap in parallel

Martin Erik Werner martinerikwerner at gmail.com
Fri Feb 19 13:07:26 UTC 2016


Using the -t|--threads <n> option, it is now possible to specify the
amount of threads to use when running autoreconf, for example:

  $ bootstrap -t 5

Since each file is autoreconf'd individually, this should not cause any
sequencing issues.

This reduces bootstrap runtime to about a half when using 5 threads on a
dual-core machine.
---
 bootstrap | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/bootstrap b/bootstrap
index 3434e51..00457ff 100755
--- a/bootstrap
+++ b/bootstrap
@@ -18,6 +18,7 @@ quiet="false"
 mode="autoreconf"
 force=0
 bsp_to_build=
+threads=1
 
 usage()
 {
@@ -29,6 +30,7 @@ usage()
   echo "	-h .. display this message and exit"
   echo "	-p .. regenerate preinstall.am files"
   echo "	-o <arch> .. only generate for given <arch>"
+  echo "	-t <n> .. use <n> threads to run autoreconf in parallel"
   echo "	-q .. quiet, don't display directories"
   echo "	-v .. verbose, pass -v to autotools"
   echo
@@ -101,6 +103,11 @@ case $1 in
   bsp_to_build=$2
   shift
   shift;;
+-t|--th|--thr|--thre|--thread|--threads)
+  test $# -gt 1 || usage
+  threads=$2
+  shift
+  shift;;
 -*) echo "unknown option $1"
   usage ;;
 *) echo "invalid parameter $1"
@@ -220,6 +227,11 @@ autoreconf)
   fi
 
   confs=`find . -name 'configure.ac' -print`
+  if test "$threads" -gt 1; then
+    # Since jobs can't be called from a subshell, use a tempfile to store output
+    trap 'rm -f "$jobs_tempfile"' EXIT
+    jobs_tempfile=$(mktemp)
+  fi
   for i in $confs; do
   if test -n "$bsp_to_build"; then
     case $i in
@@ -246,8 +258,21 @@ autoreconf)
     ${AUTORECONF} -i --no-recursive $verbose
     test -f Makefile.am && test -n "`grep 'stamp-h\.in' Makefile.in`" \
       && echo timestamp > stamp-h.in
-  )
+  ) &
+  if test "$threads" -gt 1; then
+    # Wait for amount of threads to drop below max
+    jobs >"$jobs_tempfile"
+    while test "$(wc -l "$jobs_tempfile")" -ge "$threads"; do
+      sleep 1
+      jobs >"$jobs_tempfile"
+    done
+    rm -f "$jobs_tempfile"
+    trap - EXIT
+  else
+    wait
+  fi
   done
+  wait
   ;;
 
 clean)
-- 
1.9.1




More information about the devel mailing list