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 <martinroth@google.com>
Reviewed-on: https://review.coreboot.org/12937
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Martin Roth 2016-01-13 20:52:44 -07:00
parent cf0f6b8b21
commit 517d4a6a61
1 changed files with 19 additions and 0 deletions

View File

@ -66,10 +66,29 @@ else
die "no host compiler found" die "no host compiler found"
fi 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 <<EOF cat <<EOF
# platform agnostic and host tools # platform agnostic and host tools
IASL:=${IASL} IASL:=${IASL}
HOSTCC?=${HOSTCC} HOSTCC?=${HOSTCC}
CPUS?=${CORES}
EOF EOF