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

Diff of /eclass/eutils.eclass

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

Revision 1.88 Revision 1.97
1# Copyright 1999-2004 Gentoo Technologies, Inc. 1# Copyright 1999-2004 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.88 2004/04/18 20:45:23 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.97 2004/08/31 09:05:24 lv 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.
13INHERITED="$INHERITED $ECLASS" 13INHERITED="$INHERITED $ECLASS"
14 14
15DEPEND="!bootstrap? ( sys-devel/patch )" 15DEPEND="!bootstrap? ( sys-devel/patch )"
16 16
17DESCRIPTION="Based on the ${ECLASS} eclass" 17DESCRIPTION="Based on the ${ECLASS} eclass"
18
19# This function simply returns the desired lib directory. With portage
20# 2.0.51, we now have support for installing libraries to lib32/lib64
21# to accomidate the needs of multilib systems. It's no longer a good idea
22# to assume all libraries will end up in lib. Replace any (sane) instances
23# where lib is named directly with $(get_libdir) if possible.
24#
25# Travis Tilley <lv@gentoo.org> (24 Aug 2004)
26get_libdir() {
27 if [ ! -z "${CONF_LIBDIR_OVERRIDE}" ] ; then
28 # if there is an override, we want to use that... always.
29 CONF_LIBDIR="${CONF_LIBDIR_OVERRIDE}"
30 elif portageq has_version / '<sys-apps/portage-2.0.51_pre20' ; then
31 # and if there isnt an override, and we're using a version of
32 # portage without CONF_LIBDIR support, force the use of lib. dolib
33 # and friends from portage 2.0.50 wont be too happy otherwise.
34 CONF_LIBDIR="lib"
35 fi
36 # and of course, default to lib if CONF_LIBDIR isnt set
37 echo ${CONF_LIBDIR:=lib}
38}
39
40# Sometimes you need to override the value returned by get_libdir. A good
41# example of this is xorg-x11, where lib32 isnt a supported configuration,
42# and where lib64 -must- be used on amd64 (for applications that need lib
43# to be 32bit, such as adobe acrobat). Note that this override also bypasses
44# portage version sanity checking.
45# get_libdir_override expects one argument, the result get_libdir should
46# return:
47#
48# get_libdir_override lib64
49#
50# Travis Tilley <lv@gentoo.org> (31 Aug 2004)
51get_libdir_override() {
52 CONF_LIBDIR="$1"
53 CONF_LIBDIR_OVERRIDE="$1"
54}
18 55
19# This function generate linker scripts in /usr/lib for dynamic 56# This function generate linker scripts in /usr/lib for dynamic
20# libs in /lib. This is to fix linking problems when you have 57# libs in /lib. This is to fix linking problems when you have
21# the .so in /lib, and the .a in /usr/lib. What happens is that 58# the .so in /lib, and the .a in /usr/lib. What happens is that
22# in some cases when linking dynamic, the .a in /usr/lib is used 59# in some cases when linking dynamic, the .a in /usr/lib is used
33# to point to the latest version of the library present. 70# to point to the latest version of the library present.
34# 71#
35# <azarah@gentoo.org> (26 Oct 2002) 72# <azarah@gentoo.org> (26 Oct 2002)
36# 73#
37gen_usr_ldscript() { 74gen_usr_ldscript() {
38
39 # Just make sure it exists 75 # Just make sure it exists
40 dodir /usr/lib 76 dodir /usr/$(get_libdir)
41 77
42 cat > ${D}/usr/lib/$1 <<"END_LDSCRIPT" 78 cat > ${D}/usr/$(get_libdir)/$1 <<"END_LDSCRIPT"
43/* GNU ld script 79/* GNU ld script
44 Because Gentoo have critical dynamic libraries 80 Because Gentoo have critical dynamic libraries
45 in /lib, and the static versions in /usr/lib, we 81 in /lib, and the static versions in /usr/lib, we
46 need to have a "fake" dynamic lib in /usr/lib, 82 need to have a "fake" dynamic lib in /usr/lib,
47 otherwise we run into linking problems. 83 otherwise we run into linking problems.
48 See bug #4411 on http://bugs.gentoo.org/ for 84 See bug #4411 on http://bugs.gentoo.org/ for
49 more info. */ 85 more info. */
50GROUP ( /lib/libxxx )
51END_LDSCRIPT 86END_LDSCRIPT
52 87
88 echo "GROUP ( /$(get_libdir)/libxxx )" >> ${D}/usr/$(get_libdir)/$1
53 dosed "s:libxxx:$1:" /usr/lib/$1 89 dosed "s:libxxx:$1:" /usr/$(get_libdir)/$1
54 90
55 return 0 91 return 0
56} 92}
57 93
58# Simple function to draw a line consisting of '=' the same length as $* 94# Simple function to draw a line consisting of '=' the same length as $*
144 local SINGLE_PATCH="no" 180 local SINGLE_PATCH="no"
145 local x="" 181 local x=""
146 182
147 if [ "$#" -gt 1 ] 183 if [ "$#" -gt 1 ]
148 then 184 then
149 eerror "Invalid arguments to epatch()" 185 local m=""
150 die "Invalid arguments to epatch()" 186 einfo "${#} patches to apply..."
187 for m in "$@" ; do
188 epatch "${m}"
189 done
190 return 0
151 fi 191 fi
152 192
153 if [ -n "$1" -a -f "$1" ] 193 if [ -n "$1" -a -f "$1" ]
154 then 194 then
155 SINGLE_PATCH="yes" 195 SINGLE_PATCH="yes"
478 touch ${tmp} 518 touch ${tmp}
479 echo ${tmp} 519 echo ${tmp}
480 fi 520 fi
481} 521}
482 522
523# Small wrapper for getent (Linux) and nidump (Mac OS X)
524# used in enewuser()/enewgroup()
525# Joe Jezak <josejx@gmail.com> and usata@gentoo.org
526#
527# egetent(database, key)
528egetent() {
529 if [ "${ARCH}" == "macos" ] ; then
530 case "$2" in
531 *[!0-9]*) # Non numeric
532 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
533 ;;
534 *) # Numeric
535 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
536 ;;
537 esac
538 else
539 getent $1 $2
540 fi
541}
542
483# Simplify/standardize adding users to the system 543# Simplify/standardize adding users to the system
484# vapier@gentoo.org 544# vapier@gentoo.org
485# 545#
486# enewuser(username, uid, shell, homedir, groups, extra options) 546# enewuser(username, uid, shell, homedir, groups, extra options)
487# 547#
501 eerror "No username specified !" 561 eerror "No username specified !"
502 die "Cannot call enewuser without a username" 562 die "Cannot call enewuser without a username"
503 fi 563 fi
504 564
505 # lets see if the username already exists 565 # lets see if the username already exists
506 if [ "${euser}" == "`getent passwd \"${euser}\" | cut -d: -f1`" ] 566 if [ "${euser}" == "`egetent passwd \"${euser}\" | cut -d: -f1`" ]
507 then 567 then
508 return 0 568 return 0
509 fi 569 fi
510 einfo "Adding user '${euser}' to your system ..." 570 einfo "Adding user '${euser}' to your system ..."
511 571
516 local euid="$1"; shift 576 local euid="$1"; shift
517 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] 577 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ]
518 then 578 then
519 if [ "${euid}" -gt 0 ] 579 if [ "${euid}" -gt 0 ]
520 then 580 then
521 if [ ! -z "`getent passwd ${euid}`" ] 581 if [ ! -z "`egetent passwd ${euid}`" ]
522 then 582 then
523 euid="next" 583 euid="next"
524 fi 584 fi
525 else 585 else
526 eerror "Userid given but is not greater than 0 !" 586 eerror "Userid given but is not greater than 0 !"
529 else 589 else
530 euid="next" 590 euid="next"
531 fi 591 fi
532 if [ "${euid}" == "next" ] 592 if [ "${euid}" == "next" ]
533 then 593 then
534 for euid in `seq 101 999` ; do 594 local pwrange
595 if [ "${ARCH}" == "macos" ] ; then
596 pwrange="`jot 898 101`"
597 else
598 pwrange="`seq 101 999`"
599 fi
600 for euid in ${pwrange} ; do
535 [ -z "`getent passwd ${euid}`" ] && break 601 [ -z "`egetent passwd ${euid}`" ] && break
536 done 602 done
537 fi 603 fi
538 opts="${opts} -u ${euid}" 604 opts="${opts} -u ${euid}"
539 einfo " - Userid: ${euid}" 605 einfo " - Userid: ${euid}"
540 606
568 then 634 then
569 local oldifs="${IFS}" 635 local oldifs="${IFS}"
570 export IFS="," 636 export IFS=","
571 for g in ${egroups} 637 for g in ${egroups}
572 do 638 do
573 if [ -z "`getent group \"${g}\"`" ] 639 if [ -z "`egetent group \"${g}\"`" ]
574 then 640 then
575 eerror "You must add group ${g} to the system first" 641 eerror "You must add group ${g} to the system first"
576 die "${g} is not a valid GID" 642 die "${g} is not a valid GID"
577 fi 643 fi
578 done 644 done
585 651
586 # handle extra and add the user 652 # handle extra and add the user
587 local eextra="$@" 653 local eextra="$@"
588 local oldsandbox="${SANDBOX_ON}" 654 local oldsandbox="${SANDBOX_ON}"
589 export SANDBOX_ON="0" 655 export SANDBOX_ON="0"
656 if [ "${ARCH}" == "macos" ];
657 then
658 ### Make the user
590 if [ -z "${eextra}" ] 659 if [ -z "${eextra}" ]
591 then 660 then
661 dscl . create /users/${euser} uid ${euid}
662 dscl . create /users/${euser} shell ${eshell}
663 dscl . create /users/${euser} home ${ehome}
664 dscl . create /users/${euser} realname "added by portage for ${PN}"
665 ### Add the user to the groups specified
666 for g in ${egroups}
667 do
668 dscl . merge /groups/${g} users ${euser}
669 done
670 else
671 einfo "Extra options are not supported on macos yet"
672 einfo "Please report the ebuild along with the info below"
673 einfo "eextra: ${eextra}"
674 die "Required function missing"
675 fi
676 else
677 if [ -z "${eextra}" ]
678 then
592 useradd ${opts} ${euser} \ 679 useradd ${opts} ${euser} \
593 -c "added by portage for ${PN}" \ 680 -c "added by portage for ${PN}" \
594 || die "enewuser failed" 681 || die "enewuser failed"
595 else 682 else
596 einfo " - Extra: ${eextra}" 683 einfo " - Extra: ${eextra}"
597 useradd ${opts} ${euser} ${eextra} \ 684 useradd ${opts} ${euser} ${eextra} \
598 || die "enewuser failed" 685 || die "enewuser failed"
686 fi
599 fi 687 fi
600 export SANDBOX_ON="${oldsandbox}" 688 export SANDBOX_ON="${oldsandbox}"
601 689
602 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ] 690 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ]
603 then 691 then
625 eerror "No group specified !" 713 eerror "No group specified !"
626 die "Cannot call enewgroup without a group" 714 die "Cannot call enewgroup without a group"
627 fi 715 fi
628 716
629 # see if group already exists 717 # see if group already exists
630 if [ "${egroup}" == "`getent group \"${egroup}\" | cut -d: -f1`" ] 718 if [ "${egroup}" == "`egetent group \"${egroup}\" | cut -d: -f1`" ]
631 then 719 then
632 return 0 720 return 0
633 fi 721 fi
634 einfo "Adding group '${egroup}' to your system ..." 722 einfo "Adding group '${egroup}' to your system ..."
635 723
640 local egid="$1"; shift 728 local egid="$1"; shift
641 if [ ! -z "${egid}" ] 729 if [ ! -z "${egid}" ]
642 then 730 then
643 if [ "${egid}" -gt 0 ] 731 if [ "${egid}" -gt 0 ]
644 then 732 then
645 if [ -z "`getent group ${egid}`" ] 733 if [ -z "`egetent group ${egid}`" ]
646 then 734 then
735 if [ "${ARCH}" == "macos" ] ; then
736 opts="${opts} ${egid}"
737 else
647 opts="${opts} -g ${egid}" 738 opts="${opts} -g ${egid}"
739 fi
648 else 740 else
649 egid="next available; requested gid taken" 741 egid="next available; requested gid taken"
650 fi 742 fi
651 else 743 else
652 eerror "Groupid given but is not greater than 0 !" 744 eerror "Groupid given but is not greater than 0 !"
662 opts="${opts} ${eextra}" 754 opts="${opts} ${eextra}"
663 755
664 # add the group 756 # add the group
665 local oldsandbox="${SANDBOX_ON}" 757 local oldsandbox="${SANDBOX_ON}"
666 export SANDBOX_ON="0" 758 export SANDBOX_ON="0"
759 if [ "${ARCH}" == "macos" ];
760 then
761 if [ ! -z "${eextra}" ];
762 then
763 einfo "Extra options are not supported on macos yet"
764 einfo "Please report the ebuild along with the info below"
765 einfo "eextra: ${eextra}"
766 die "Required function missing"
767 fi
768
769 # If we need the next available
770 case ${egid} in
771 *[!0-9]*) # Non numeric
772 for egid in `jot 898 101`; do
773 [ -z "`egetent group ${egid}`" ] && break
774 done
775 esac
776 dscl . create /groups/${egroup} gid ${egid}
777 dscl . create /groups/${egroup} passwd '*'
778 else
667 groupadd ${opts} ${egroup} || die "enewgroup failed" 779 groupadd ${opts} ${egroup} || die "enewgroup failed"
780 fi
668 export SANDBOX_ON="${oldsandbox}" 781 export SANDBOX_ON="${oldsandbox}"
669} 782}
670 783
671# Simple script to replace 'dos2unix' binaries 784# Simple script to replace 'dos2unix' binaries
672# vapier@gentoo.org 785# vapier@gentoo.org
693# name: the name that will show up in the menu 806# name: the name that will show up in the menu
694# icon: give your little like a pretty little icon ... 807# icon: give your little like a pretty little icon ...
695# this can be relative (to /usr/share/pixmaps) or 808# this can be relative (to /usr/share/pixmaps) or
696# a full path to an icon 809# a full path to an icon
697# type: what kind of application is this ? for categories: 810# type: what kind of application is this ? for categories:
698# http://www.freedesktop.org/standards/menu/draft/menu-spec/menu-spec.html 811# http://www.freedesktop.org/standards/menu-spec/
699# path: if your app needs to startup in a specific dir 812# path: if your app needs to startup in a specific dir
700make_desktop_entry() { 813make_desktop_entry() {
701 [ -z "$1" ] && eerror "You must specify the executable" && return 1 814 [ -z "$1" ] && eerror "You must specify the executable" && return 1
702 815
703 local exec="${1}" 816 local exec="${1}"
943 tail -n +${skip} ${src} | bzip2 -dc | tar --no-same-owner -xf - 1056 tail -n +${skip} ${src} | bzip2 -dc | tar --no-same-owner -xf -
944 ;; 1057 ;;
945 gzip*) 1058 gzip*)
946 tail -n +${skip} ${src} | tar --no-same-owner -xzf - 1059 tail -n +${skip} ${src} | tar --no-same-owner -xzf -
947 ;; 1060 ;;
1061 compress*)
1062 tail -n +${skip} ${src} | gunzip | tar --no-same-owner -xf -
1063 ;;
948 *) 1064 *)
1065 eerror "Unknown filetype \"${filetype}\" ?"
949 false 1066 false
950 ;; 1067 ;;
951 esac 1068 esac
952 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})" 1069 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
953} 1070}
1173 einfo "or hit CTRL+C to abort the emerge." 1290 einfo "or hit CTRL+C to abort the emerge."
1174 read 1291 read
1175 fi 1292 fi
1176 done 1293 done
1177} 1294}
1295
1296# Make sure that LINGUAS only contains languages that
1297# a package can support
1298#
1299# usage: strip-linguas <allow LINGUAS>
1300# strip-linguas -i <directories of .po files>
1301# strip-linguas -u <directories of .po files>
1302#
1303# The first form allows you to specify a list of LINGUAS.
1304# The -i builds a list of po files found in all the
1305# directories and uses the intersection of the lists.
1306# The -u builds a list of po files found in all the
1307# directories and uses the union of the lists.
1308strip-linguas() {
1309 local ls newls
1310 if [ "$1" == "-i" ] || [ "$1" == "-u" ] ; then
1311 local op="$1"; shift
1312 ls=" $(find "$1" -name '*.po' -printf '%f ') "; shift
1313 local d f
1314 for d in "$@" ; do
1315 if [ "${op}" == "-u" ] ; then
1316 newls="${ls}"
1317 else
1318 newls=""
1319 fi
1320 for f in $(find "$d" -name '*.po' -printf '%f ') ; do
1321 if [ "${op}" == "-i" ] ; then
1322 [ "${ls/ ${f} /}" != "${ls}" ] && newls="${newls} ${f}"
1323 else
1324 [ "${ls/ ${f} /}" == "${ls}" ] && newls="${newls} ${f}"
1325 fi
1326 done
1327 ls="${newls}"
1328 done
1329 ls="${ls//.po}"
1330 else
1331 ls="$@"
1332 fi
1333
1334 ls=" ${ls} "
1335 newls=""
1336 for f in ${LINGUAS} ; do
1337 if [ "${ls/ ${f} /}" != "${ls}" ] ; then
1338 nl="${newls} ${f}"
1339 else
1340 ewarn "Sorry, but ${PN} does not support the ${f} LINGUA"
1341 fi
1342 done
1343 if [ -z "${newls}" ] ; then
1344 unset LINGUAS
1345 else
1346 export LINGUAS="${newls}"
1347 fi
1348}

Legend:
Removed from v.1.88  
changed lines
  Added in v.1.97

  ViewVC Help
Powered by ViewVC 1.1.20