From 478a5aee19aaf1328b6f83ee8abcdf3dfa25a3af Mon Sep 17 00:00:00 2001 From: Mark Ferrell Date: Thu, 24 Apr 2014 10:22:58 -0700 Subject: 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. --- build | 13 ++++++++----- libexec/build-num-cpus | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100755 libexec/build-num-cpus 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 -- cgit v1.2.3-18-g5258