| 1 | # Copyright 1999-2005 Gentoo Foundation |
1 | # Copyright 1999-2005 Gentoo Foundation |
| 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 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.173 2005/05/24 03:17:19 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.174 2005/05/24 05:10:19 vapier Exp $ |
| 4 | # |
4 | # |
| 5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
| 6 | # |
6 | # |
| 7 | # This eclass is for general purpose functions that most ebuilds |
7 | # This eclass is for general purpose functions that most ebuilds |
| 8 | # have to implement themselves. |
8 | # have to implement themselves. |
| … | |
… | |
| 366 | fi |
366 | fi |
| 367 | done |
367 | done |
| 368 | if [ "${SINGLE_PATCH}" = "no" ] |
368 | if [ "${SINGLE_PATCH}" = "no" ] |
| 369 | then |
369 | then |
| 370 | einfo "Done with patching" |
370 | einfo "Done with patching" |
| 371 | fi |
|
|
| 372 | } |
|
|
| 373 | |
|
|
| 374 | # This function check how many cpu's are present, and then set |
|
|
| 375 | # -j in MAKEOPTS accordingly. |
|
|
| 376 | # |
|
|
| 377 | # Thanks to nall <nall@gentoo.org> for this. |
|
|
| 378 | # |
|
|
| 379 | get_number_of_jobs() { |
|
|
| 380 | local jobs=0 |
|
|
| 381 | |
|
|
| 382 | if [ ! -r /proc/cpuinfo ] |
|
|
| 383 | then |
|
|
| 384 | return 1 |
|
|
| 385 | fi |
|
|
| 386 | |
|
|
| 387 | # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565. |
|
|
| 388 | if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ] |
|
|
| 389 | then |
|
|
| 390 | ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`" |
|
|
| 391 | ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`" |
|
|
| 392 | ADMINPARAM="${ADMINPARAM/-j}" |
|
|
| 393 | fi |
|
|
| 394 | |
|
|
| 395 | export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`" |
|
|
| 396 | |
|
|
| 397 | if [ "${ARCH}" = "amd64" -o "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \ |
|
|
| 398 | "${ARCH}" = "arm" -o "${ARCH}" = "mips" -o "${ARCH}" = "ia64" ] |
|
|
| 399 | then |
|
|
| 400 | # these archs will always have "[Pp]rocessor" |
|
|
| 401 | jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))" |
|
|
| 402 | |
|
|
| 403 | elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] |
|
|
| 404 | then |
|
|
| 405 | # sparc always has "ncpus active" |
|
|
| 406 | jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
|
|
| 407 | |
|
|
| 408 | elif [ "${ARCH}" = "alpha" ] |
|
|
| 409 | then |
|
|
| 410 | # alpha has "cpus active", but only when compiled with SMP |
|
|
| 411 | if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ] |
|
|
| 412 | then |
|
|
| 413 | jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
|
|
| 414 | else |
|
|
| 415 | jobs=2 |
|
|
| 416 | fi |
|
|
| 417 | |
|
|
| 418 | elif [ "${ARCH}" = "ppc" -o "${ARCH}" = "ppc64" ] |
|
|
| 419 | then |
|
|
| 420 | # ppc has "processor", but only when compiled with SMP |
|
|
| 421 | if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ] |
|
|
| 422 | then |
|
|
| 423 | jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))" |
|
|
| 424 | else |
|
|
| 425 | jobs=2 |
|
|
| 426 | fi |
|
|
| 427 | elif [ "${ARCH}" = "s390" ] |
|
|
| 428 | then |
|
|
| 429 | # s390 has "# processors : " |
|
|
| 430 | jobs="$((`grep "^\# processors" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
|
|
| 431 | else |
|
|
| 432 | jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))" |
|
|
| 433 | die "Unknown ARCH -- ${ARCH}!" |
|
|
| 434 | fi |
|
|
| 435 | |
|
|
| 436 | # Make sure the number is valid ... |
|
|
| 437 | if [ "${jobs}" -lt 1 ] |
|
|
| 438 | then |
|
|
| 439 | jobs=1 |
|
|
| 440 | fi |
|
|
| 441 | |
|
|
| 442 | if [ -n "${ADMINPARAM}" ] |
|
|
| 443 | then |
|
|
| 444 | if [ "${jobs}" -gt "${ADMINPARAM}" ] |
|
|
| 445 | then |
|
|
| 446 | einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge ..." |
|
|
| 447 | export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}" |
|
|
| 448 | else |
|
|
| 449 | einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge ..." |
|
|
| 450 | export MAKEOPTS="${MAKEOPTS} -j${jobs}" |
|
|
| 451 | fi |
|
|
| 452 | fi |
371 | fi |
| 453 | } |
372 | } |
| 454 | |
373 | |
| 455 | # Cheap replacement for when debianutils (and thus mktemp) |
374 | # Cheap replacement for when debianutils (and thus mktemp) |
| 456 | # does not exist on the users system |
375 | # does not exist on the users system |