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

Diff of /eclass/eutils.eclass

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

Revision 1.85 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.85 2004/02/29 22:34:41 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"
258 else 298 else
259 PATCH_TARGET="${x}" 299 PATCH_TARGET="${x}"
260 fi 300 fi
261 301
262 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 302 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
263 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 303 echo "patch -p${count} ${popts} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
264 304
265 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 305 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
266 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 306 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
267 307
268 if [ "${PATCH_SUFFIX}" != "patch" ] 308 if [ "${PATCH_SUFFIX}" != "patch" ]
275 count=5 315 count=5
276 break 316 break
277 fi 317 fi
278 fi 318 fi
279 319
280 if (cat ${PATCH_TARGET} | patch ${popts} --dry-run -f -p${count}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1 320 if (cat ${PATCH_TARGET} | patch -p${count} ${popts} --dry-run -f) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
281 then 321 then
282 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 322 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
283 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 323 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
284 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 324 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
285 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 325 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
286 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 326 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
287 327
288 cat ${PATCH_TARGET} | patch ${popts} -p${count} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1 328 cat ${PATCH_TARGET} | patch -p${count} ${popts} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1
289 329
290 if [ "$?" -ne 0 ] 330 if [ "$?" -ne 0 ]
291 then 331 then
292 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 332 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
293 echo 333 echo
431 then 471 then
432 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))" 472 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
433 else 473 else
434 jobs=2 474 jobs=2
435 fi 475 fi
476 elif [ "${ARCH}" = "s390" ]
477 then
478 # s390 has "# processors : "
479 jobs="$((`grep "^\# processors" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
436 else 480 else
437 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))" 481 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
438 die "Unknown ARCH -- ${ARCH}!" 482 die "Unknown ARCH -- ${ARCH}!"
439 fi 483 fi
440 484
471 mktemp -p ${topdir} 515 mktemp -p ${topdir}
472 else 516 else
473 local tmp="${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}" 517 local tmp="${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}"
474 touch ${tmp} 518 touch ${tmp}
475 echo ${tmp} 519 echo ${tmp}
520 fi
521}
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
476 fi 540 fi
477} 541}
478 542
479# Simplify/standardize adding users to the system 543# Simplify/standardize adding users to the system
480# vapier@gentoo.org 544# vapier@gentoo.org
497 eerror "No username specified !" 561 eerror "No username specified !"
498 die "Cannot call enewuser without a username" 562 die "Cannot call enewuser without a username"
499 fi 563 fi
500 564
501 # lets see if the username already exists 565 # lets see if the username already exists
502 if [ "${euser}" == "`getent passwd \"${euser}\" | cut -d: -f1`" ] 566 if [ "${euser}" == "`egetent passwd \"${euser}\" | cut -d: -f1`" ]
503 then 567 then
504 return 0 568 return 0
505 fi 569 fi
506 einfo "Adding user '${euser}' to your system ..." 570 einfo "Adding user '${euser}' to your system ..."
507 571
512 local euid="$1"; shift 576 local euid="$1"; shift
513 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] 577 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ]
514 then 578 then
515 if [ "${euid}" -gt 0 ] 579 if [ "${euid}" -gt 0 ]
516 then 580 then
517 if [ ! -z "`getent passwd ${euid}`" ] 581 if [ ! -z "`egetent passwd ${euid}`" ]
518 then 582 then
519 euid="next" 583 euid="next"
520 fi 584 fi
521 else 585 else
522 eerror "Userid given but is not greater than 0 !" 586 eerror "Userid given but is not greater than 0 !"
525 else 589 else
526 euid="next" 590 euid="next"
527 fi 591 fi
528 if [ "${euid}" == "next" ] 592 if [ "${euid}" == "next" ]
529 then 593 then
530 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
531 [ -z "`getent passwd ${euid}`" ] && break 601 [ -z "`egetent passwd ${euid}`" ] && break
532 done 602 done
533 fi 603 fi
534 opts="${opts} -u ${euid}" 604 opts="${opts} -u ${euid}"
535 einfo " - Userid: ${euid}" 605 einfo " - Userid: ${euid}"
536 606
564 then 634 then
565 local oldifs="${IFS}" 635 local oldifs="${IFS}"
566 export IFS="," 636 export IFS=","
567 for g in ${egroups} 637 for g in ${egroups}
568 do 638 do
569 if [ -z "`getent group \"${g}\"`" ] 639 if [ -z "`egetent group \"${g}\"`" ]
570 then 640 then
571 eerror "You must add group ${g} to the system first" 641 eerror "You must add group ${g} to the system first"
572 die "${g} is not a valid GID" 642 die "${g} is not a valid GID"
573 fi 643 fi
574 done 644 done
581 651
582 # handle extra and add the user 652 # handle extra and add the user
583 local eextra="$@" 653 local eextra="$@"
584 local oldsandbox="${SANDBOX_ON}" 654 local oldsandbox="${SANDBOX_ON}"
585 export SANDBOX_ON="0" 655 export SANDBOX_ON="0"
656 if [ "${ARCH}" == "macos" ];
657 then
658 ### Make the user
586 if [ -z "${eextra}" ] 659 if [ -z "${eextra}" ]
587 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
588 useradd ${opts} ${euser} \ 679 useradd ${opts} ${euser} \
589 -c "added by portage for ${PN}" \ 680 -c "added by portage for ${PN}" \
590 || die "enewuser failed" 681 || die "enewuser failed"
591 else 682 else
592 einfo " - Extra: ${eextra}" 683 einfo " - Extra: ${eextra}"
593 useradd ${opts} ${euser} ${eextra} \ 684 useradd ${opts} ${euser} ${eextra} \
594 || die "enewuser failed" 685 || die "enewuser failed"
686 fi
595 fi 687 fi
596 export SANDBOX_ON="${oldsandbox}" 688 export SANDBOX_ON="${oldsandbox}"
597 689
598 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ] 690 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ]
599 then 691 then
621 eerror "No group specified !" 713 eerror "No group specified !"
622 die "Cannot call enewgroup without a group" 714 die "Cannot call enewgroup without a group"
623 fi 715 fi
624 716
625 # see if group already exists 717 # see if group already exists
626 if [ "${egroup}" == "`getent group \"${egroup}\" | cut -d: -f1`" ] 718 if [ "${egroup}" == "`egetent group \"${egroup}\" | cut -d: -f1`" ]
627 then 719 then
628 return 0 720 return 0
629 fi 721 fi
630 einfo "Adding group '${egroup}' to your system ..." 722 einfo "Adding group '${egroup}' to your system ..."
631 723
636 local egid="$1"; shift 728 local egid="$1"; shift
637 if [ ! -z "${egid}" ] 729 if [ ! -z "${egid}" ]
638 then 730 then
639 if [ "${egid}" -gt 0 ] 731 if [ "${egid}" -gt 0 ]
640 then 732 then
641 if [ -z "`getent group ${egid}`" ] 733 if [ -z "`egetent group ${egid}`" ]
642 then 734 then
735 if [ "${ARCH}" == "macos" ] ; then
736 opts="${opts} ${egid}"
737 else
643 opts="${opts} -g ${egid}" 738 opts="${opts} -g ${egid}"
739 fi
644 else 740 else
645 egid="next available; requested gid taken" 741 egid="next available; requested gid taken"
646 fi 742 fi
647 else 743 else
648 eerror "Groupid given but is not greater than 0 !" 744 eerror "Groupid given but is not greater than 0 !"
658 opts="${opts} ${eextra}" 754 opts="${opts} ${eextra}"
659 755
660 # add the group 756 # add the group
661 local oldsandbox="${SANDBOX_ON}" 757 local oldsandbox="${SANDBOX_ON}"
662 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
663 groupadd ${opts} ${egroup} || die "enewgroup failed" 779 groupadd ${opts} ${egroup} || die "enewgroup failed"
780 fi
664 export SANDBOX_ON="${oldsandbox}" 781 export SANDBOX_ON="${oldsandbox}"
665} 782}
666 783
667# Simple script to replace 'dos2unix' binaries 784# Simple script to replace 'dos2unix' binaries
668# vapier@gentoo.org 785# vapier@gentoo.org
689# name: the name that will show up in the menu 806# name: the name that will show up in the menu
690# icon: give your little like a pretty little icon ... 807# icon: give your little like a pretty little icon ...
691# this can be relative (to /usr/share/pixmaps) or 808# this can be relative (to /usr/share/pixmaps) or
692# a full path to an icon 809# a full path to an icon
693# type: what kind of application is this ? for categories: 810# type: what kind of application is this ? for categories:
694# http://www.freedesktop.org/standards/menu/draft/menu-spec/menu-spec.html 811# http://www.freedesktop.org/standards/menu-spec/
695# path: if your app needs to startup in a specific dir 812# path: if your app needs to startup in a specific dir
696make_desktop_entry() { 813make_desktop_entry() {
697 [ -z "$1" ] && eerror "You must specify the executable" && return 1 814 [ -z "$1" ] && eerror "You must specify the executable" && return 1
698 815
699 local exec="${1}" 816 local exec="${1}"
705 if [ -z "${type}" ] 822 if [ -z "${type}" ]
706 then 823 then
707 case ${CATEGORY} in 824 case ${CATEGORY} in
708 "app-emulation") 825 "app-emulation")
709 type=Emulator 826 type=Emulator
710 subdir="Games" 827 subdir="Emulation"
711 ;; 828 ;;
712 "games-"*) 829 "games-"*)
713 type=Game 830 type=Game
714 subdir="Games" 831 subdir="Games"
715 ;; 832 ;;
939 tail -n +${skip} ${src} | bzip2 -dc | tar --no-same-owner -xf - 1056 tail -n +${skip} ${src} | bzip2 -dc | tar --no-same-owner -xf -
940 ;; 1057 ;;
941 gzip*) 1058 gzip*)
942 tail -n +${skip} ${src} | tar --no-same-owner -xzf - 1059 tail -n +${skip} ${src} | tar --no-same-owner -xzf -
943 ;; 1060 ;;
1061 compress*)
1062 tail -n +${skip} ${src} | gunzip | tar --no-same-owner -xf -
1063 ;;
944 *) 1064 *)
1065 eerror "Unknown filetype \"${filetype}\" ?"
945 false 1066 false
946 ;; 1067 ;;
947 esac 1068 esac
948 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})" 1069 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
949} 1070}
1169 einfo "or hit CTRL+C to abort the emerge." 1290 einfo "or hit CTRL+C to abort the emerge."
1170 read 1291 read
1171 fi 1292 fi
1172 done 1293 done
1173} 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.85  
changed lines
  Added in v.1.97

  ViewVC Help
Powered by ViewVC 1.1.20