From 50413c23266926944c641a99bcd03461e5224a8b Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Tue, 2 May 2023 21:05:04 +0200 Subject: [PATCH] Toolchain: Replace inline nproc with get_number_of_processing_units() --- Toolchain/BuildCMake.sh | 15 +++------------ Toolchain/BuildClang.sh | 10 ++-------- Toolchain/BuildGDB.sh | 9 ++------- Toolchain/BuildIt.sh | 9 ++------- Toolchain/BuildMold.sh | 14 ++------------ Toolchain/BuildPython.sh | 5 ++--- Toolchain/BuildQemu.sh | 5 ++--- Toolchain/BuildRuby.sh | 5 ++--- 8 files changed, 17 insertions(+), 55 deletions(-) diff --git a/Toolchain/BuildCMake.sh b/Toolchain/BuildCMake.sh index 4371266010b..fabee41c418 100755 --- a/Toolchain/BuildCMake.sh +++ b/Toolchain/BuildCMake.sh @@ -14,18 +14,8 @@ PREFIX_DIR="$DIR/Local/cmake" BUILD_DIR="$DIR/Build/cmake" TARBALLS_DIR="$DIR/Tarballs" -NPROC="nproc" -SYSTEM_NAME="$(uname -s)" - -if [ "$SYSTEM_NAME" = "OpenBSD" ]; then - NPROC="sysctl -n hw.ncpuonline" -elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then - NPROC="sysctl -n hw.ncpu" -elif [ "$SYSTEM_NAME" = "Darwin" ]; then - NPROC="sysctl -n hw.ncpu" -fi - -[ -z "$MAKEJOBS" ] && MAKEJOBS=$($NPROC) +NPROC=$(get_number_of_processing_units) +[ -z "$MAKEJOBS" ] && MAKEJOBS=${NPROC} check_sha() { if [ $# -ne 2 ]; then @@ -36,6 +26,7 @@ check_sha() { FILE="${1}" EXPECTED_HASH="${2}" + SYSTEM_NAME="$(uname -s)" if [ "$SYSTEM_NAME" = "Darwin" ]; then SEEN_HASH="$(shasum -a 256 "${FILE}" | cut -d " " -f 1)" else diff --git a/Toolchain/BuildClang.sh b/Toolchain/BuildClang.sh index ce0c247e9af..0bfb581b085 100755 --- a/Toolchain/BuildClang.sh +++ b/Toolchain/BuildClang.sh @@ -19,7 +19,6 @@ ARCHS="$USERLAND_ARCHS aarch64" MD5SUM="md5sum" REALPATH="realpath" -NPROC="nproc" INSTALL="install" SED="sed" @@ -28,25 +27,20 @@ SYSTEM_NAME="$(uname -s)" if [ "$SYSTEM_NAME" = "OpenBSD" ]; then MD5SUM="md5 -q" REALPATH="readlink -f" - NPROC="sysctl -n hw.ncpuonline" export CC=egcc export CXX=eg++ export LDFLAGS=-Wl,-z,notext elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then MD5SUM="md5 -q" - NPROC="sysctl -n hw.ncpu" elif [ "$SYSTEM_NAME" = "Darwin" ]; then MD5SUM="md5 -q" - NPROC="sysctl -n hw.ncpu" REALPATH="grealpath" # GNU coreutils INSTALL="ginstall" # GNU coreutils SED="gsed" # GNU sed fi -if [ -z "$MAKEJOBS" ]; then - MAKEJOBS=$($NPROC) -fi - +NPROC=$(get_number_of_processing_units) +[ -z "$MAKEJOBS" ] && MAKEJOBS=${NPROC} if [ ! -d "$BUILD" ]; then mkdir -p "$BUILD" diff --git a/Toolchain/BuildGDB.sh b/Toolchain/BuildGDB.sh index fba89b0aa71..d8571d48c30 100755 --- a/Toolchain/BuildGDB.sh +++ b/Toolchain/BuildGDB.sh @@ -21,30 +21,25 @@ PREFIX="$DIR/Local/$ARCH-gdb" echo "Building GDB $GDB_VERSION for $TARGET" MD5SUM="md5sum" -NPROC="nproc" SYSTEM_NAME="$(uname -s)" if [ "$SYSTEM_NAME" = "OpenBSD" ]; then MD5SUM="md5 -q" - NPROC="sysctl -n hw.ncpuonline" export CC=egcc export CXX=eg++ export with_gmp=/usr/local export LDFLAGS=-Wl,-z,notext elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then MD5SUM="md5 -q" - NPROC="sysctl -n hw.ncpu" export with_gmp=/usr/local export with_mpfr=/usr/local elif [ "$SYSTEM_NAME" = "Darwin" ]; then MD5SUM="md5 -q" - NPROC="sysctl -n hw.ncpu" fi -if [ -z "$MAKEJOBS" ]; then - MAKEJOBS=$($NPROC) -fi +NPROC=$(get_number_of_processing_units) +[ -z "$MAKEJOBS" ] && MAKEJOBS=${NPROC} buildstep() { NAME=$1 diff --git a/Toolchain/BuildIt.sh b/Toolchain/BuildIt.sh index 8147127714b..1d0a12fedd1 100755 --- a/Toolchain/BuildIt.sh +++ b/Toolchain/BuildIt.sh @@ -21,7 +21,6 @@ SYSROOT="$BUILD/Root" MAKE="make" MD5SUM="md5sum" -NPROC="nproc" REALPATH="realpath" if command -v ginstall &>/dev/null; then @@ -41,7 +40,6 @@ export CXXFLAGS="-g0 -O2 -mtune=native" if [ "$SYSTEM_NAME" = "OpenBSD" ]; then MAKE=gmake MD5SUM="md5 -q" - NPROC="sysctl -n hw.ncpuonline" REALPATH="readlink -f" export CC=egcc export CXX=eg++ @@ -50,12 +48,10 @@ if [ "$SYSTEM_NAME" = "OpenBSD" ]; then elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then MAKE=gmake MD5SUM="md5 -q" - NPROC="sysctl -n hw.ncpu" export with_gmp=/usr/local export with_mpfr=/usr/local elif [ "$SYSTEM_NAME" = "Darwin" ]; then MD5SUM="md5 -q" - NPROC="sysctl -n hw.ncpu" fi # On at least OpenBSD, the path must exist to call realpath(3) on it @@ -270,9 +266,8 @@ popd rm -rf "$PREFIX" mkdir -p "$PREFIX" -if [ -z "$MAKEJOBS" ]; then - MAKEJOBS=$($NPROC) -fi +NPROC=$(get_number_of_processing_units) +[ -z "$MAKEJOBS" ] && MAKEJOBS=${NPROC} mkdir -p "$DIR/Build/$ARCH" diff --git a/Toolchain/BuildMold.sh b/Toolchain/BuildMold.sh index 2ca4a144cc1..a7b989d0d2b 100755 --- a/Toolchain/BuildMold.sh +++ b/Toolchain/BuildMold.sh @@ -11,18 +11,8 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" exit_if_running_as_root "Do not run BuildMold.sh as root, parts of your Toolchain directory will become root-owned" -NPROC="nproc" -SYSTEM_NAME="$(uname -s)" - -if [ "$SYSTEM_NAME" = "OpenBSD" ]; then - NPROC="sysctl -n hw.ncpuonline" -elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then - NPROC="sysctl -n hw.ncpu" -elif [ "$SYSTEM_NAME" = "Darwin" ]; then - NPROC="sysctl -n hw.ncpu" -fi - -[ -z "$MAKEJOBS" ] && MAKEJOBS=$($NPROC) +NPROC=$(get_number_of_processing_units) +[ -z "$MAKEJOBS" ] && MAKEJOBS=${NPROC} mkdir -p "$DIR"/Tarballs pushd "$DIR"/Tarballs diff --git a/Toolchain/BuildPython.sh b/Toolchain/BuildPython.sh index 8166a32835e..c0d48c31d0d 100755 --- a/Toolchain/BuildPython.sh +++ b/Toolchain/BuildPython.sh @@ -41,9 +41,8 @@ pushd "${TARBALLS_DIR}" fi popd -if [ -z "$MAKEJOBS" ]; then - MAKEJOBS=$(nproc) -fi +NPROC=$(get_number_of_processing_units) +[ -z "$MAKEJOBS" ] && MAKEJOBS=${NPROC} mkdir -p "${PREFIX_DIR}" mkdir -p "${BUILD_DIR}" diff --git a/Toolchain/BuildQemu.sh b/Toolchain/BuildQemu.sh index 354f619dd69..91d0c4a272e 100755 --- a/Toolchain/BuildQemu.sh +++ b/Toolchain/BuildQemu.sh @@ -55,9 +55,8 @@ popd mkdir -p "$PREFIX" mkdir -p "$DIR/Build/qemu" -if [ -z "$MAKEJOBS" ]; then - MAKEJOBS=$(nproc) -fi +NPROC=$(get_number_of_processing_units) +[ -z "$MAKEJOBS" ] && MAKEJOBS=${NPROC} EXTRA_ARGS="" if [[ $(uname) == "Darwin" ]] diff --git a/Toolchain/BuildRuby.sh b/Toolchain/BuildRuby.sh index 2d2b94765fc..1ac2988e892 100755 --- a/Toolchain/BuildRuby.sh +++ b/Toolchain/BuildRuby.sh @@ -41,9 +41,8 @@ pushd "${TARBALLS_DIR}" fi popd -if [ -z "$MAKEJOBS" ]; then - MAKEJOBS=$(nproc) -fi +NPROC=$(get_number_of_processing_units) +[ -z "$MAKEJOBS" ] && MAKEJOBS=${NPROC} mkdir -p "${PREFIX_DIR}" mkdir -p "${BUILD_DIR}"