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

Diff of /eclass/eutils.eclass

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

Revision 1.168 Revision 1.179
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.168 2005/04/29 03:59:15 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.179 2005/05/28 05:50:29 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.
118EPATCH_SOURCE="${WORKDIR}/patch" 118EPATCH_SOURCE="${WORKDIR}/patch"
119# Default extension for patches 119# Default extension for patches
120EPATCH_SUFFIX="patch.bz2" 120EPATCH_SUFFIX="patch.bz2"
121# Default options for patch 121# Default options for patch
122# Set -g0 to keep RCS, ClearCase, Perforce and SCCS happy. Bug #24571 122# Set -g0 to keep RCS, ClearCase, Perforce and SCCS happy. Bug #24571
123EPATCH_OPTS="-g0" 123# Set --no-backup-if-mismatch so we don't leave '.orig' files behind.
124EPATCH_OPTS="-g0 --no-backup-if-mismatch"
124# List of patches not to apply. Not this is only file names, 125# List of patches not to apply. Not this is only file names,
125# and not the full path .. 126# and not the full path ..
126EPATCH_EXCLUDE="" 127EPATCH_EXCLUDE=""
127# Change the printed message for a single patch. 128# Change the printed message for a single patch.
128EPATCH_SINGLE_MSG="" 129EPATCH_SINGLE_MSG=""
130# Change the printed message for multiple patches.
131EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
129# Force applying bulk patches even if not following the style: 132# Force applying bulk patches even if not following the style:
130# 133#
131# ??_${ARCH}_foo.${EPATCH_SUFFIX} 134# ??_${ARCH}_foo.${EPATCH_SUFFIX}
132# 135#
133EPATCH_FORCE="no" 136EPATCH_FORCE="no"
237 ;; 240 ;;
238 esac 241 esac
239 242
240 if [ "${SINGLE_PATCH}" = "no" ] 243 if [ "${SINGLE_PATCH}" = "no" ]
241 then 244 then
242 einfo "Applying various patches (bugfixes/updates) ..." 245 einfo "${EPATCH_MULTI_MSG}"
243 fi 246 fi
244 for x in ${EPATCH_SOURCE} 247 for x in ${EPATCH_SOURCE}
245 do 248 do
246 # New ARCH dependant patch naming scheme ... 249 # New ARCH dependant patch naming scheme ...
247 # 250 #
248 # ???_arch_foo.patch 251 # ???_arch_foo.patch
249 # 252 #
250 if [ -f ${x} ] && \ 253 if [ -f ${x} ] && \
251 ([ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] || \ 254 ([ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "${x/_${ARCH}_}" != "${x}" ] || \
252 [ "${EPATCH_FORCE}" = "yes" ]) 255 [ "${EPATCH_FORCE}" = "yes" ])
253 then 256 then
254 local count=0 257 local count=0
255 local popts="${EPATCH_OPTS}" 258 local popts="${EPATCH_OPTS}"
256 local patchname=${x##*/} 259 local patchname=${x##*/}
366 then 369 then
367 einfo "Done with patching" 370 einfo "Done with patching"
368 fi 371 fi
369} 372}
370 373
371# This function return true if we are using the NPTL pthreads
372# implementation.
373#
374# <azarah@gentoo.org> (06 March 2003)
375#
376have_NPTL() {
377 cat > ${T}/test-nptl.c <<-"END"
378 #define _XOPEN_SOURCE
379 #include <unistd.h>
380 #include <stdio.h>
381
382 int main()
383 {
384 char buf[255];
385 char *str = buf;
386
387 confstr(_CS_GNU_LIBPTHREAD_VERSION, str, 255);
388 if (NULL != str) {
389 printf("%s\n", str);
390 if (NULL != strstr(str, "NPTL"))
391 return 0;
392 }
393
394 return 1;
395 }
396 END
397
398 einfon "Checking for _CS_GNU_LIBPTHREAD_VERSION support in glibc ..."
399 if gcc -o ${T}/nptl ${T}/test-nptl.c &> /dev/null
400 then
401 echo "yes"
402 einfon "Checking what PTHREADS implementation we have ..."
403 if ${T}/nptl
404 then
405 return 0
406 else
407 return 1
408 fi
409 else
410 echo "no"
411 fi
412
413 return 1
414}
415
416# This function check how many cpu's are present, and then set
417# -j in MAKEOPTS accordingly.
418#
419# Thanks to nall <nall@gentoo.org> for this.
420#
421get_number_of_jobs() {
422 local jobs=0
423
424 if [ ! -r /proc/cpuinfo ]
425 then
426 return 1
427 fi
428
429 # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565.
430 if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ]
431 then
432 ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`"
433 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`"
434 ADMINPARAM="${ADMINPARAM/-j}"
435 fi
436
437 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
438
439 if [ "${ARCH}" = "amd64" -o "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \
440 "${ARCH}" = "arm" -o "${ARCH}" = "mips" -o "${ARCH}" = "ia64" ]
441 then
442 # these archs will always have "[Pp]rocessor"
443 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))"
444
445 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
446 then
447 # sparc always has "ncpus active"
448 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
449
450 elif [ "${ARCH}" = "alpha" ]
451 then
452 # alpha has "cpus active", but only when compiled with SMP
453 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
454 then
455 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
456 else
457 jobs=2
458 fi
459
460 elif [ "${ARCH}" = "ppc" -o "${ARCH}" = "ppc64" ]
461 then
462 # ppc has "processor", but only when compiled with SMP
463 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
464 then
465 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
466 else
467 jobs=2
468 fi
469 elif [ "${ARCH}" = "s390" ]
470 then
471 # s390 has "# processors : "
472 jobs="$((`grep "^\# processors" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
473 else
474 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
475 die "Unknown ARCH -- ${ARCH}!"
476 fi
477
478 # Make sure the number is valid ...
479 if [ "${jobs}" -lt 1 ]
480 then
481 jobs=1
482 fi
483
484 if [ -n "${ADMINPARAM}" ]
485 then
486 if [ "${jobs}" -gt "${ADMINPARAM}" ]
487 then
488 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge ..."
489 export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}"
490 else
491 einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge ..."
492 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
493 fi
494 fi
495}
496
497# Cheap replacement for when debianutils (and thus mktemp) 374# Cheap replacement for when debianutils (and thus mktemp)
498# does not exist on the users system 375# does not exist on the users system
499# vapier@gentoo.org 376# vapier@gentoo.org
500# 377#
501# Takes just 1 optional parameter (the directory to create tmpfile in) 378# Takes just 1 optional parameter (the directory to create tmpfile in)
532# Joe Jezak <josejx@gmail.com> and usata@gentoo.org 409# Joe Jezak <josejx@gmail.com> and usata@gentoo.org
533# FBSD stuff: Aaron Walker <ka0ttic@gentoo.org> 410# FBSD stuff: Aaron Walker <ka0ttic@gentoo.org>
534# 411#
535# egetent(database, key) 412# egetent(database, key)
536egetent() { 413egetent() {
537 if useq ppc-macos ; then 414 if [[ "${USERLAND}" == "Darwin" ]] ; then
538 case "$2" in 415 case "$2" in
539 *[!0-9]*) # Non numeric 416 *[!0-9]*) # Non numeric
540 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }" 417 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
541 ;; 418 ;;
542 *) # Numeric 419 *) # Numeric
543 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }" 420 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
544 ;; 421 ;;
545 esac 422 esac
546 elif useq x86-fbsd ; then 423 elif [[ "${USERLAND}" == "BSD" ]] ; then
547 local action 424 local action
548 if [ "$1" == "passwd" ] 425 if [ "$1" == "passwd" ]
549 then 426 then
550 action="user" 427 action="user"
551 else 428 else
630 then 507 then
631 eerror "A shell was specified but it does not exist !" 508 eerror "A shell was specified but it does not exist !"
632 die "${eshell} does not exist" 509 die "${eshell} does not exist"
633 fi 510 fi
634 else 511 else
635 if [ "${USERLAND}" == "BSD" ] 512 if [[ "${USERLAND}" == "Darwin" ]]; then
636 then
637 eshell="/usr/bin/false" 513 eshell="/usr/bin/false"
514 elif [[ "${USERLAND}" == "BSD" ]]; then
515 eshell="/usr/sbin/nologin"
638 else 516 else
639 eshell="/bin/false" 517 eshell="/bin/false"
640 fi 518 fi
641 fi 519 fi
642 einfo " - Shell: ${eshell}" 520 einfo " - Shell: ${eshell}"
643 opts="${opts} -s ${eshell}" 521 opts="${opts} -s ${eshell}"
644 522
645 # handle homedir 523 # handle homedir
646 local ehome="$1"; shift 524 local ehome="$1"; shift
647 if [ -z "${ehome}" ] && [ "${eshell}" != "-1" ] 525 if [ -z "${ehome}" ] || [ "${eshell}" == "-1" ]
648 then 526 then
649 ehome="/dev/null" 527 ehome="/dev/null"
650 fi 528 fi
651 einfo " - Home: ${ehome}" 529 einfo " - Home: ${ehome}"
652 opts="${opts} -d ${ehome}" 530 opts="${opts} -d ${ehome}"
689 567
690 # handle extra and add the user 568 # handle extra and add the user
691 local eextra="$@" 569 local eextra="$@"
692 local oldsandbox="${SANDBOX_ON}" 570 local oldsandbox="${SANDBOX_ON}"
693 export SANDBOX_ON="0" 571 export SANDBOX_ON="0"
694 if useq ppc-macos 572 if [[ "${USERLAND}" == "Darwin" ]]
695 then 573 then
696 ### Make the user 574 ### Make the user
697 if [ -z "${eextra}" ] 575 if [ -z "${eextra}" ]
698 then 576 then
699 dscl . create /users/${euser} uid ${euid} 577 dscl . create /users/${euser} uid ${euid}
712 einfo "Extra options are not supported on macos yet" 590 einfo "Extra options are not supported on macos yet"
713 einfo "Please report the ebuild along with the info below" 591 einfo "Please report the ebuild along with the info below"
714 einfo "eextra: ${eextra}" 592 einfo "eextra: ${eextra}"
715 die "Required function missing" 593 die "Required function missing"
716 fi 594 fi
717 elif use x86-fbsd ; then 595 elif [[ "${USERLAND}" == "BSD" ]] ; then
718 if [ -z "${eextra}" ] 596 if [ -z "${eextra}" ]
719 then 597 then
720 pw useradd ${euser} ${opts} \ 598 pw useradd ${euser} ${opts} \
721 -c "added by portage for ${PN}" \ 599 -c "added by portage for ${PN}" \
722 die "enewuser failed" 600 die "enewuser failed"
782 then 660 then
783 if [ "${egid}" -gt 0 ] 661 if [ "${egid}" -gt 0 ]
784 then 662 then
785 if [ -z "`egetent group ${egid}`" ] 663 if [ -z "`egetent group ${egid}`" ]
786 then 664 then
787 if useq ppc-macos ; then 665 if [[ "${USERLAND}" == "Darwin" ]]; then
788 opts="${opts} ${egid}" 666 opts="${opts} ${egid}"
789 else 667 else
790 opts="${opts} -g ${egid}" 668 opts="${opts} -g ${egid}"
791 fi 669 fi
792 else 670 else
806 opts="${opts} ${eextra}" 684 opts="${opts} ${eextra}"
807 685
808 # add the group 686 # add the group
809 local oldsandbox="${SANDBOX_ON}" 687 local oldsandbox="${SANDBOX_ON}"
810 export SANDBOX_ON="0" 688 export SANDBOX_ON="0"
811 if useq ppc-macos ; then 689 if [[ "${USERLAND}" == "Darwin" ]]; then
812 if [ ! -z "${eextra}" ]; 690 if [ ! -z "${eextra}" ];
813 then 691 then
814 einfo "Extra options are not supported on macos yet" 692 einfo "Extra options are not supported on Darwin/OS X yet"
815 einfo "Please report the ebuild along with the info below" 693 einfo "Please report the ebuild along with the info below"
816 einfo "eextra: ${eextra}" 694 einfo "eextra: ${eextra}"
817 die "Required function missing" 695 die "Required function missing"
818 fi 696 fi
819 697
824 [ -z "`egetent group ${egid}`" ] && break 702 [ -z "`egetent group ${egid}`" ] && break
825 done 703 done
826 esac 704 esac
827 dscl . create /groups/${egroup} gid ${egid} 705 dscl . create /groups/${egroup} gid ${egid}
828 dscl . create /groups/${egroup} passwd '*' 706 dscl . create /groups/${egroup} passwd '*'
829 elif use x86-fbsd ; then 707 elif [[ "${USERLAND}" == "BSD" ]] ; then
830 case ${egid} in 708 case ${egid} in
831 *[!0-9]*) # Non numeric 709 *[!0-9]*) # Non numeric
832 for egid in `jot 898 101`; do 710 for egid in `jot 898 101`; do
833 [ -z "`egetent group ${egid}`" ] && break 711 [ -z "`egetent group ${egid}`" ] && break
834 done 712 done
981 *) 859 *)
982 type= 860 type=
983 ;; 861 ;;
984 esac 862 esac
985 fi 863 fi
986 864 if [ "${SLOT}" == "0" ] ; then
865 local desktop_name="${PN}"
866 else
867 local desktop_name="${PN}-${SLOT}"
868 fi
987 local desktop=${T}/${exec%% *}-${P}.desktop 869 local desktop=${T}/${exec%% *}-${desktop_name}.desktop
988 870
989echo "[Desktop Entry] 871echo "[Desktop Entry]
990Encoding=UTF-8 872Encoding=UTF-8
991Version=0.9.2 873Version=0.9.2
992Name=${name} 874Name=${name}
1471 local mline="" 1353 local mline=""
1472 local showedmsg=0 1354 local showedmsg=0
1473 1355
1474 for mline in $(mount | egrep -e '(iso|cdrom)' | awk '{print $3}') ; do 1356 for mline in $(mount | egrep -e '(iso|cdrom)' | awk '{print $3}') ; do
1475 [[ -d ${mline}/${dir} ]] || continue 1357 [[ -d ${mline}/${dir} ]] || continue
1476 [[ ! -z $(find ${mline}/${dir} -iname ${file} -maxdepth 1) ]] \ 1358 [[ ! -z $(find ${mline}/${dir} -maxdepth 1 -iname ${file}) ]] \
1477 && export CDROM_ROOT=${mline} 1359 && export CDROM_ROOT=${mline}
1478 done 1360 done
1479 1361
1480 if [[ -z ${CDROM_ROOT} ]] ; then 1362 if [[ -z ${CDROM_ROOT} ]] ; then
1481 echo 1363 echo
1569 while ((i--)) ; do 1451 while ((i--)) ; do
1570 ewarn "PLEASE UPDATE TO YOUR PACKAGE TO USE linux-info.eclass" 1452 ewarn "PLEASE UPDATE TO YOUR PACKAGE TO USE linux-info.eclass"
1571 done 1453 done
1572 export EUTILS_ECLASS_PORTAGE_ARCH="${ARCH}" 1454 export EUTILS_ECLASS_PORTAGE_ARCH="${ARCH}"
1573 case ${ARCH} in 1455 case ${ARCH} in
1574 x86) export ARCH="i386";; 1456 x86) export ARCH="i386";;
1575 amd64) export ARCH="x86_64";; 1457 amd64) export ARCH="x86_64";;
1576 hppa) export ARCH="parisc";; 1458 hppa) export ARCH="parisc";;
1577 mips) export ARCH="mips";; 1459 mips) export ARCH="mips";;
1578 sparc) export ARCH="$(tc-arch-kernel)";; # Yeah this is ugly, but it's even WORSE if you don't do this. linux-info.eclass's set_arch_to_kernel is fixed, but won't get used over this one! 1460 sparc) export ARCH="$(tc-arch-kernel)";; # Yeah this is ugly, but it's even WORSE if you don't do this. linux-info.eclass's set_arch_to_kernel is fixed, but won't get used over this one!
1579 *) export ARCH="${ARCH}";; 1461 *) export ARCH="${ARCH}";;
1580 esac 1462 esac
1581} 1463}
1582 1464
1583# set's ARCH back to what portage expects 1465# set's ARCH back to what portage expects
1584set_arch_to_portage() { 1466set_arch_to_portage() {
1691dopamd() { 1573dopamd() {
1692 [[ -z $1 ]] && die "dopamd requires at least one argument" 1574 [[ -z $1 ]] && die "dopamd requires at least one argument"
1693 1575
1694 use pam || return 0 1576 use pam || return 0
1695 1577
1696 insinto /etc/pam.d 1578 INSDESTTREE=/etc/pam.d \
1697 doins "$@" || die "failed to install $@" 1579 doins "$@" || die "failed to install $@"
1698} 1580}
1699# newpamd <old name> <new name> 1581# newpamd <old name> <new name>
1700# 1582#
1701# Install pam file <old name> as <new name> in /etc/pam.d 1583# Install pam file <old name> as <new name> in /etc/pam.d
1702newpamd() { 1584newpamd() {
1703 [[ $# -ne 2 ]] && die "newpamd requires two arguements" 1585 [[ $# -ne 2 ]] && die "newpamd requires two arguements"
1704 1586
1705 use pam || return 0 1587 use pam || return 0
1706 1588
1707 insinto /etc/pam.d 1589 INSDESTTREE=/etc/pam.d \
1708 newins "$1" "$2" || die "failed to install $1 as $2" 1590 newins "$1" "$2" || die "failed to install $1 as $2"
1709} 1591}
1710 1592
1711# make a wrapper script ... 1593# make a wrapper script ...
1712# NOTE: this was originally games_make_wrapper, but I noticed other places where 1594# NOTE: this was originally games_make_wrapper, but I noticed other places where

Legend:
Removed from v.1.168  
changed lines
  Added in v.1.179

  ViewVC Help
Powered by ViewVC 1.1.20