From df7c1491e05aa3c9c830837a3171d6978701ce1f Mon Sep 17 00:00:00 2001 From: Martin Schlemmer Date: Sun, 1 Dec 2002 23:22:50 +0000 Subject: add get_number_of_jobs(), thanks to nall --- eclass/eutils.eclass | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'eclass/eutils.eclass') diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass index 77dc559ab6d1..28ec6c0e578a 100644 --- a/eclass/eutils.eclass +++ b/eclass/eutils.eclass @@ -1,7 +1,7 @@ # Copyright 1999-2002 Gentoo Technologies, Inc. # Distributed under the terms of the GNU General Public License v2 # Author: Martin Schlemmer -# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.9 2002/12/01 15:48:27 azarah Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.10 2002/12/01 23:22:50 azarah Exp $ # This eclass is for general purpose functions that most ebuilds # have to implement themselves. # @@ -311,3 +311,51 @@ epatch() { fi } +# This function check how many cpu's are present, and then set +# -j in MAKEOPTS accordingly. +# +# Thanks to nall for this. +# +get_number_of_jobs() { + if [ ! -r /proc/cpuinfo ] + then + return 1 + fi + + export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j[0-9]*::g'`" + + if [ "${ARCH}" = "x86" ] + then + # x86 always has "processor" + export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^processor /proc/cpuinfo` * 2))" + + elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] + then + # sparc always has "ncpus active" + export MAKEOPTS="${MAKEOPTS} -j$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" + + elif [ "${ARCH}" = "alpha" ] + then + # alpha has "cpus active", but only when compiled with SMP + if [ "`grep -c "^cpus active" /proc/cpuinfo`" = "1" ] + then + export MAKEOPTS="${MAKEOPTS} -j$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" + else + export MAKEOPTS="${MAKEOPTS} -j2" + fi + + elif [ "${ARCH}" = "ppc" ] + then + # ppc has "processor", but only when compiled with SMP + if [ "`grep -c "^processor" /proc/cpuinfo`" = "1" ] + then + export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^processor /proc/cpuinfo` * 2))" + else + export MAKEOPTS="${MAKEOPTS} -j2" + fi + else + export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^cpu /proc/cpuinfo` * 2))" + die "Unknown ARCH -- ${ARCH}!" + fi +} + -- cgit v1.2.3-65-gdbad