Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix make -j passing build cores #890

Merged
merged 7 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion doc/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <number-of-cores>
make -j<number-of-cores>
```

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
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down