aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Ferrell <major@homeonderanged.org>2014-04-24 10:22:58 -0700
committerMark Ferrell <major@homeonderanged.org>2014-04-24 10:22:58 -0700
commit478a5aee19aaf1328b6f83ee8abcdf3dfa25a3af (patch)
tree1448e89184aff4313fbaf59e7b4dcfd740b4cab0
parentbec4500227ad670aaa8aa52104f14d84f90a0feb (diff)
Add a command for querying number of CPU's
* This is something of a stop-gap until we can come up w/ a unified interface for asking for this sort of information. Something again to a 'build-host' command which we can query arch, os, version, endian, num-cpus, etc.
-rwxr-xr-xbuild13
-rwxr-xr-xlibexec/build-num-cpus17
2 files changed, 25 insertions, 5 deletions
diff --git a/build b/build
index 45644f1..a990d33 100755
--- a/build
+++ b/build
@@ -315,11 +315,6 @@ export BUILDER_PATH PATH
# include our default config
test -f "${BUILDER_CFGDIR}/config" && include config
-# FIXME MAKE_OPTS should default to #CPUS + 1, until we can detect #CPUS, we
-# just set it to 2 for uni-processor systems.
-MAKE_OPTS="${MAKE_OPTS:--j2}"
-export MAKE_OPTS
-
# Default build target
# FIXME this should default to all/all
TARGET="${TARGET:-all/all}"
@@ -339,6 +334,14 @@ export ARCH
CHOST="${CHOST:-${CBUILD}}"
export CHOST
+MAKE_OPTS=
+if test -z "${MAKE_OPTS}"; then
+ num_cpus="$(build-num-cpus)"
+ MAKE_OPTS="-j$((${num_cpus} + 1))"
+ unset num_cpus
+fi
+export MAKE_OPTS
+
# if we aren't given an action then we do everything
ACTION="install"
if [ "$#" -gt "0" ]; then
diff --git a/libexec/build-num-cpus b/libexec/build-num-cpus
new file mode 100755
index 0000000..ab88f3f
--- /dev/null
+++ b/libexec/build-num-cpus
@@ -0,0 +1,17 @@
+#!/usr/bin/env build
+
+case "${CBUILD:-$(build-dumpmachine)}" in
+(*linux*) eval 'build_num_cpus() { nproc; }';;
+(*) die "unknown host '${CBUILD}'";;
+esac
+
+if test "${BUILDER_CALL_STACK}" = '__main__'; then
+ for arg; do
+ case "${arg}" in
+ (-h|-help|--help) echo 'usage: build num-cpus'; exit 0;;
+ esac
+ done
+ build_num_cpus "${@}"
+fi
+
+# vim: filetype=sh