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

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

  ViewVC Help
Powered by ViewVC 1.1.20