summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Roth <martinroth@google.com>2016-01-13 20:52:44 -0700
committerMartin Roth <martinroth@google.com>2016-01-15 22:27:30 +0100
commit517d4a6a61adb15c6edf4675d1e72e474c56f924 (patch)
tree9c5829998c8e38b079e2171932d561d55a5894ad
parentcf0f6b8b2157571c41a7eb9eb46d6c57622fdda8 (diff)
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>
-rwxr-xr-xutil/xcompile/xcompile19
1 files changed, 19 insertions, 0 deletions
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 <<EOF
# platform agnostic and host tools
IASL:=${IASL}
HOSTCC?=${HOSTCC}
+CPUS?=${CORES}
EOF