/[gentoo-x86]/eclass/eutils.eclass
Gentoo

Diff of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.12 Revision 1.17
1# Copyright 1999-2002 Gentoo Technologies, Inc. 1# Copyright 1999-2002 Gentoo Technologies, Inc.
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# Author: Martin Schlemmer <azarah@gentoo.org> 3# Author: Martin Schlemmer <azarah@gentoo.org>
4# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.12 2002/12/14 21:46:25 azarah Exp $ 4# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.17 2003/02/09 22:41:16 azarah Exp $
5# This eclass is for general purpose functions that most ebuilds 5# This eclass is for general purpose functions that most ebuilds
6# have to implement themselves. 6# have to implement themselves.
7# 7#
8# NB: If you add anything, please comment it! 8# NB: If you add anything, please comment it!
9 9
317# -j in MAKEOPTS accordingly. 317# -j in MAKEOPTS accordingly.
318# 318#
319# Thanks to nall <nall@gentoo.org> for this. 319# Thanks to nall <nall@gentoo.org> for this.
320# 320#
321get_number_of_jobs() { 321get_number_of_jobs() {
322 local jobs=0
323
322 if [ ! -r /proc/cpuinfo ] 324 if [ ! -r /proc/cpuinfo ]
323 then 325 then
324 return 1 326 return 1
325 fi 327 fi
326 328
329 # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565.
330 if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ]
331 then
332 ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`"
333 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`"
334 ADMINPARAM="${ADMINPARAM/-j}"
335 fi
336
327 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j[0-9]*::g'`" 337 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
328 338
329 if [ "${ARCH}" = "x86" ] 339 if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" ]
330 then 340 then
331 # x86 always has "processor" 341 # x86 and hppa always has "processor"
332 export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^processor /proc/cpuinfo` * 2))" 342 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
333 343
334 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] 344 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
335 then 345 then
336 # sparc always has "ncpus active" 346 # sparc always has "ncpus active"
337 export MAKEOPTS="${MAKEOPTS} -j$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" 347 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
338 348
339 elif [ "${ARCH}" = "alpha" ] 349 elif [ "${ARCH}" = "alpha" ]
340 then 350 then
341 # alpha has "cpus active", but only when compiled with SMP 351 # alpha has "cpus active", but only when compiled with SMP
342 if [ "`grep -c "^cpus active" /proc/cpuinfo`" = "1" ] 352 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
343 then 353 then
344 export MAKEOPTS="${MAKEOPTS} -j$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" 354 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
345 else 355 else
346 export MAKEOPTS="${MAKEOPTS} -j2" 356 jobs=2
347 fi 357 fi
348 358
349 elif [ "${ARCH}" = "ppc" ] 359 elif [ "${ARCH}" = "ppc" ]
350 then 360 then
351 # ppc has "processor", but only when compiled with SMP 361 # ppc has "processor", but only when compiled with SMP
352 if [ "`grep -c "^processor" /proc/cpuinfo`" = "1" ] 362 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
353 then 363 then
354 export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^processor /proc/cpuinfo` * 2))" 364 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
355 else 365 else
356 export MAKEOPTS="${MAKEOPTS} -j2" 366 jobs=2
357 fi 367 fi
368 elif [ "${ARCH}" = "mips" ]
369 then
370 # mips always has "processor"
371 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
372
358 else 373 else
359 export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^cpu /proc/cpuinfo` * 2))" 374 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
360 die "Unknown ARCH -- ${ARCH}!" 375 die "Unknown ARCH -- ${ARCH}!"
361 fi 376 fi
377
378 # Make sure the number is valid ...
379 if [ "${jobs}" -lt 1 ]
380 then
381 jobs=1
382 fi
383
384 if [ -n "${ADMINPARAM}" ]
385 then
386 if [ "${jobs}" -gt "${ADMINPARAM}" ]
387 then
388 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..."
389 export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}"
390 else
391 einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge..."
392 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
393 fi
394 fi
362} 395}
363 396

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.17

  ViewVC Help
Powered by ViewVC 1.1.20