installdeps: use -j$(nproc) not -j8 in info #146

Replace the hardcoded `make -j8` command in the build instructions with
a `-j` parameter that is the number of the host's CPUs minus one.

Subtracting 1 is done to reduce chances of overloading the host.

If the value is `1`, then don't print the `-j` flag at all.
This commit is contained in:
Rafael Kitover 2017-08-31 16:56:06 -07:00
parent 8b2e8f87d4
commit 1a27f81342
1 changed files with 37 additions and 2 deletions

View File

@ -28,12 +28,15 @@ main() {
case "$(uname -s)" in
Linux)
os=linux
linux_installdeps
;;
Darwin)
os=mac
osx_installdeps
;;
MINGW*|MSYS*)
os=windows
msys2_installdeps
;;
*)
@ -154,6 +157,38 @@ linux_installdeps() {
fi
}
# the -j flag for make parameter, empty if 1
jobs_flag() {
if [ $(num_cpus) -gt 1 ]; then
echo "-j$(num_cpus)"
fi
}
# number of CPUs to use for jobs, 1 less than total to not overload resources
num_cpus() {
if [ -n "$_num_cpus" ]; then
if [ $((_num_cpus - 1)) -lt 1 ]; then
echo 1
else
echo $((_num_cpus - 1))
fi
return 0
fi
# determine number of CPUs and cache it
if command -v nproc >/dev/null; then
_num_cpus=$(nproc)
elif [ $os = linux -o $os = windows ]; then
_num_cpus=$(grep '^processor *:' /proc/cpuinfo | wc -l)
elif [ $os = mac ]; then
_num_cpus=$(sysctl -n hw.ncpu)
fi
[ -z "$_num_cpus" ] && _num_cpus=1
num_cpus
}
check_cross() {
target=$(echo "$target" | tr 'A-Z' 'a-z')
@ -519,7 +554,7 @@ EOF
grep -Ev '^[ ]*MAKEFLAGS=' "$MAKEPKG_CONF" > "$tmp/makepkg.conf"
export MAKEFLAGS="-j$(($(cat /proc/cpuinfo | grep -E '^processor ' | wc -l)+1))"
export MAKEFLAGS=$(jobs_flag)
echo "MAKEFLAGS=\"$MAKEFLAGS\"" >> "$tmp/makepkg.conf"
export MAKEPKG_CONF="$tmp/makepkg.conf"
@ -731,7 +766,7 @@ build_instructions() {
$pre_build
mkdir -p build && cd build
$cmake .. $cmake_flags
make -j8
make $(jobs_flag)
$post_build
EOF