From 517d4a6a61adb15c6edf4675d1e72e474c56f924 Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Wed, 13 Jan 2016 20:52:44 -0700 Subject: [PATCH] xcompile: Add core count to .xcompile I think these four methods should cover most operating systems, with many supporting several of the methods. If we don't find anything, we're not any worse off than we were before. The big issue would be if we get an incorrect value. Change-Id: I4a612d39e93173e9d6e0de892f5bebf716912b1a Signed-off-by: Martin Roth Reviewed-on: https://review.coreboot.org/12937 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi --- util/xcompile/xcompile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/util/xcompile/xcompile b/util/xcompile/xcompile index a1856e4232..d8779264ec 100755 --- a/util/xcompile/xcompile +++ b/util/xcompile/xcompile @@ -66,10 +66,29 @@ else die "no host compiler found" fi +# try to find the core count using various methods +CORES="$(getconf _NPROCESSORS_ONLN 2>/dev/null)" +if [ -z "$CORES" ]; then + NPROC=$(command -v nproc) + if [ -n "$NPROC" ]; then + CORES="$($NPROC)" + fi +fi +if [ -z "$CORES" ]; then + SYSCTL=$(command -v sysctl) + if [ -n "$SYSCTL" ]; then + CORES="$(${SYSCTL} -n hw.ncpu 2>/dev/null)" + fi +fi +if [ -z "$CORES" ] && [ -f /proc/cpuinfo ]; then + CORES="$(grep 'processor' /proc/cpuinfo 2>/dev/null | wc -l)" +fi + cat <