Skip to content

Commit

Permalink
[GCC toolchain builder] Provide means of throttling parallel builds.
Browse files Browse the repository at this point in the history
* README.md (Build Model>Prerequisites): Describe use of NUM_JOBS for
  building the toolchain.
* util/gcc-toolchain-builder/build-toolchain.sh (NUM_JOBS): New.
  (build binutils-gdb): Use NUM_JOBS to throttle parallel MAKE operation.
  (build gcc): Ditto.
  (build newlib): Ditto.
  • Loading branch information
zchamski committed Sep 28, 2023
1 parent 5ee1a34 commit 69bf64a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions util/gcc-toolchain-builder/build-toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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 -

Expand All @@ -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 -

Expand All @@ -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 -

Expand Down

0 comments on commit 69bf64a

Please sign in to comment.