From 8087dd44327bdbaf1629e189635afe9a5233ea2d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 26 Nov 2018 09:41:28 +0200 Subject: Add support for --jobs|-j in build.sh script --- build.sh | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'build.sh') diff --git a/build.sh b/build.sh index b8dbb25..bcdff43 100755 --- a/build.sh +++ b/build.sh @@ -40,10 +40,12 @@ owd="$(pwd)" cxx= idir= +jobs= sudo= trust= timeout= make= +make_options= verbose= while test $# -ne 0; do @@ -54,6 +56,7 @@ while test $# -ne 0; do diag "Options:" diag " --install-dir Alternative installation directory." diag " --sudo Optional sudo program to use (pass false to disable)." + diag " --jobs|-j Number of jobs to perform in parallel." diag " --repo Alternative package repository location." diag " --trust Repository certificate fingerprint to trust." diag " --timeout Network operations timeout in seconds." @@ -66,15 +69,22 @@ while test $# -ne 0; do diag diag "$0 --install-dir /opt/build2 --sudo sudo g++" diag + diag "If --jobs|-j is unspecified, then the bootstrap step is performed" + diag "serially with the rest of the process using the number of available" + diag "hardware threads." + diag diag "The --trust option recognizes two special values: 'yes' (trust" diag "everything) and 'no' (trust nothing)." diag diag "The --make option can be used to bootstrap using GNU make. The" diag "first --make value should specify the make executable optionally" - diag "followed by additional make arguments, for example:" + diag "followed by additional make options, for example:" diag diag "$0 --make gmake --make -j8 g++" diag + diag "If --jobs|-j is specified, then its value is passed to make before" + diag "any additional options." + diag diag "If specified, override the default (-O3) compile" diag "options (config.cc.coptions) in the bpkg configuration used to build" diag "and install the final toolchain. For example, to build with the debug" @@ -96,6 +106,16 @@ while test $# -ne 0; do idir="$1" shift ;; + -j|--jobs) + shift + if test $# -eq 0; then + diag "error: number of jobs expected after --jobs|-j" + diag "$usage" + exit 1 + fi + jobs="-j $1" + shift + ;; --sudo) shift if test $# -eq 0; then @@ -143,7 +163,11 @@ while test $# -ne 0; do diag "$usage" exit 1 fi - make="$make $1" + if test -z "$make"; then + make="$1" + else + make_options="$make_options $1" + fi shift ;; --verbose) @@ -176,6 +200,18 @@ if test $# -eq 0; then set -- -O3 fi +# Merge jobs and make_options into make. +# +if test -n "$make"; then + if test -n "$jobs"; then + make="$make $jobs" + fi + + if test -n "$make_options"; then + make="$make$make_options" # Already has leading space. + fi +fi + # Only use default sudo for the default installation directory and only if # it wasn't specified by the user. # @@ -260,7 +296,7 @@ run build2/b-boot --version # Bootstrap, stage 2. # -run build2/b-boot $verbose config.cxx="$cxx" config.bin.lib=static build2/exe{b} +run build2/b-boot $verbose $jobs config.cxx="$cxx" config.bin.lib=static build2/exe{b} mv build2/b build2/b-boot run build2/b-boot --version @@ -276,7 +312,7 @@ config.install.root="$idir" \ config.install.data_root=root/stage \ config.install.sudo="$conf_sudo" -run build2/build2/b-boot $verbose install: build2/ bpkg/ +run build2/build2/b-boot $verbose $jobs install: build2/ bpkg/ run which b-stage run which bpkg-stage @@ -301,8 +337,8 @@ config.install.sudo="$conf_sudo" run bpkg-stage $verbose add "$BUILD2_REPO" run bpkg-stage $verbose $bpkg_fetch_ops fetch -run bpkg-stage $verbose $bpkg_build_ops build --for install --yes build2 bpkg bdep -run bpkg-stage $verbose install build2 bpkg bdep +run bpkg-stage $verbose $jobs $bpkg_build_ops build --for install --yes build2 bpkg bdep +run bpkg-stage $verbose $jobs install build2 bpkg bdep run which b run which bpkg @@ -315,7 +351,7 @@ run bdep --version # Clean up stage. # run cd "$owd" -run b $verbose uninstall: build2/ bpkg/ +run b $verbose $jobs uninstall: build2/ bpkg/ diag diag "Toolchain installation: $idir/bin" -- cgit v1.1