diff --git a/Makefile b/Makefile index 6d72b2077..99edf91d5 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,7 @@ -# Parse -j from MAKEFLAGS for parallelism. -GERBIL_BUILD_CORES := $(or $(patsubst -j%,%,$(filter -j%,$(MAKEFLAGS))),1) - all: build build: - GERBIL_BUILD_CORES=$(GERBIL_BUILD_CORES) ./build.sh + GERBIL_BUILD_FLAGS="$(MAKEFLAGS)" ./build.sh install: ./install.sh diff --git a/doc/guide/README.md b/doc/guide/README.md index 65546d711..23e7208b7 100644 --- a/doc/guide/README.md +++ b/doc/guide/README.md @@ -46,9 +46,13 @@ cd into the `gerbil` directory. Gerbil takes quite a while to compile, if you wish it to build faster by utilizing multiple cores, you can: ``` -make -j +make -j ``` +Alternatively, you can set the `GERBIL_BUILD_CORES` environment +variable to the number of cores you want to use. + + If you are using the default configuration, you can build Gerbil simply with: ```bash $ ./configure && make && sudo make install diff --git a/docker/Dockerfile b/docker/Dockerfile index 3b3384efb..38115940d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -51,7 +51,7 @@ RUN cd /opt && git clone https://github.com/vyzo/gerbil gerbil-src RUN cd /opt/gerbil-src && git fetch -a && git fetch --tags && git checkout ${gerbil_version} \ && eval ./configure --prefix=/opt/gerbil --enable-shared=no ${configure_args} -RUN cd /opt/gerbil-src && make -j ${GERBIL_BUILD_CORES} && make install +RUN cd /opt/gerbil-src && make && make install FROM gerbil as final RUN rm -rf /opt/gerbil-src /src/leveldb /src/lmdb diff --git a/src/build.sh b/src/build.sh index 436295afa..b0628d4bb 100755 --- a/src/build.sh +++ b/src/build.sh @@ -6,6 +6,20 @@ cd $(dirname "$0") # Change to this directory # Assuming this script is run with: `cd $GERBIL_BASE/src && ./build.sh` #=============================================================================== +# utility to get number of cores from make -j +build_flags_cores() { + for x in $1; do + case $x in + -j*) + echo ${x##-j} + break + ;; + *) + ;; + esac + done +} + # Check for GERBIL_PREFIX being set # This is necessary for the bach build script to set the correct RUNPATH in the # gerbil binary. @@ -42,6 +56,18 @@ else fi export LD_LIBRARY_PATH +if [ "x${GERBIL_BUILD_FLAGS:-}" != "x" ]; then + num_cores=$(build_flags_cores "${GERBIL_BUILD_FLAGS}") + if [ "x${num_cores:-}" != "x" ]; then + GERBIL_BUILD_CORES=${num_cores} + export GERBIL_BUILD_CORES + fi +fi + +if [ "x${GERBIL_BUILD_CORES:-}" != "x" ]; then + echo "using ${GERBIL_BUILD_CORES} cores for the build" +fi + #=============================================================================== ## feedback feedback_err() {