diff --git a/README.md b/README.md index ad20a296a4..204170ca2b 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,14 @@ located under `util/gcc-toolchain-builder`. Please make sure beforehand that yo installed all the required *toolchain build* dependencies (see [the toolchain README file](file:util/gcc-toolchain-builder/README.md).) +To control the load of your host machine when building the toolchain, you can use +the environment variable `NUM_JOBS` to limit the number of concurrent jobs launched +by `make`: +- if left undefined, `NUM_JOBS` will default to 1, resulting in a sequential execution +of `make` jobs; +- when setting `NUM_JOBS` to an explicit value, it is recommended not to exceed 2/3 of +the total nuber of virtual cores available on your system. + ```sh # Set environment variable RISCV to the desired installation location. # The toolchain can be installed in any user-writable directory. diff --git a/util/gcc-toolchain-builder/build-toolchain.sh b/util/gcc-toolchain-builder/build-toolchain.sh index 15095e2b4b..edac6f0549 100644 --- a/util/gcc-toolchain-builder/build-toolchain.sh +++ b/util/gcc-toolchain-builder/build-toolchain.sh @@ -37,6 +37,12 @@ ROOT_DIR=$(dirname $(readlink -f $0)) # Builds of individual tools are performed under the matching # build/... subdirectories +# Provide a means of throttling parallel 'make' executions. +# Use a conservative setting to avoid overloading the host machine. +if [ -z "${NUM_JOBS}" ]; then + NUM_JOBS=1 +fi + # Helper function to print usage information. print_usage() { @@ -163,7 +169,7 @@ cd $ROOT_DIR/build/binutils-gdb { echo "Could not configure binutils-gdb, bailing out!" ; \ exit 2 ; } ; } && \ { [ -d gas/doc ] || mkdir -p gas/doc; } && \ - make -j all && make install || \ + make -j${NUM_JOBS} all && make install || \ { echo "*** Could not build binutils, bailing out!" ; exit 2; } cd - @@ -182,8 +188,8 @@ cd $ROOT_DIR/build/gcc ../../$GCC_DIR/configure $GCC_CONFIGURE_OPTS || \ { echo "Could not configure GCC, bailing out!" ; \ exit 2 ; } ; } && \ - make -j all || { rm -rf $TARGET && \ - make -j all ; } && make install || \ + make -j${NUM_JOBS} all || { rm -rf $TARGET && \ + make -j${NUM_JOBS} all ; } && make install || \ { echo "*** Could not build GCC (even after removing target dirs), bailing out!" ; exit 2; } cd - @@ -209,7 +215,7 @@ export CFLAGS="-mcmodel=medium" ../../$NEWLIB_DIR/configure $NEWLIB_CONFIGURE_OPTS || \ { echo "Could not configure newlib, bailing out!" ; \ exit 2 ; } ; } && \ - make -j all && make install || \ + make -j${NUM_JOBS} all && make install || \ { echo "*** Could not build newlib, bailing out!" ; exit 2; } cd -