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

Diff of /eclass/eutils.eclass

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

Revision 1.266 Revision 1.279
1# Copyright 1999-2006 Gentoo Foundation 1# Copyright 1999-2006 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.266 2007/01/04 22:14:34 flameeyes Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.279 2007/04/25 09:14:35 carlo Exp $
4# 4#
5# This eclass is for general purpose functions that most ebuilds 5# This eclass is for general purpose functions that most ebuilds
6# have to implement themselves. 6# have to implement themselves.
7# 7#
8# NB: If you add anything, please comment it! 8# NB: If you add anything, please comment it!
253 einfo "${EPATCH_SINGLE_MSG}" 253 einfo "${EPATCH_SINGLE_MSG}"
254 else 254 else
255 einfo "Applying ${patchname} ..." 255 einfo "Applying ${patchname} ..."
256 fi 256 fi
257 else 257 else
258 einfo " ${patchname} ..." 258 einfo " ${patchname} ..."
259 fi 259 fi
260 260
261 echo "***** ${patchname} *****" > ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/} 261 echo "***** ${patchname} *****" > ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
262 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/} 262 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
263 263
892 if [ "${SLOT}" == "0" ] ; then 892 if [ "${SLOT}" == "0" ] ; then
893 local desktop_name="${PN}" 893 local desktop_name="${PN}"
894 else 894 else
895 local desktop_name="${PN}-${SLOT}" 895 local desktop_name="${PN}-${SLOT}"
896 fi 896 fi
897 local desktop=${T}/${exec%% *}-${desktop_name}.desktop 897 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop"
898# local desktop=${T}/${exec%% *:-${desktop_name}}.desktop 898 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop
899 899
900 cat <<-EOF > "${desktop}"
900echo "[Desktop Entry] 901 [Desktop Entry]
901Encoding=UTF-8 902 Encoding=UTF-8
902Version=0.9.2 903 Version=0.9.2
903Name=${name} 904 Name=${name}
904Type=Application 905 Type=Application
905Comment=${DESCRIPTION} 906 Comment=${DESCRIPTION}
906Exec=${exec} 907 Exec=${exec}
907TryExec=${exec%% *} 908 TryExec=${exec%% *}
908Path=${path} 909 Path=${path}
909Icon=${icon} 910 Icon=${icon}
910Categories=Application;${type};" > "${desktop}" 911 Categories=Application;${type};
912 EOF
911 913
912 ( 914 (
913 # wrap the env here so that the 'insinto' call 915 # wrap the env here so that the 'insinto' call
914 # doesn't corrupt the env of the caller 916 # doesn't corrupt the env of the caller
915 insinto /usr/share/applications 917 insinto /usr/share/applications
916 doins "${desktop}" 918 doins "${desktop}"
917 ) 919 )
918} 920}
919 921
922
923# Validate desktop entries using desktop-file-utils
924# Carsten Lohrke <carlo@gentoo.org>
925#
926# Usage: validate_desktop_entries [directory ...]
927
928validate_desktop_entries() {
929 if [[ -x /usr/bin/desktop-file-validate ]] ; then
930 einfo "Checking desktop entry validity"
931 local directories=""
932 for d in /usr/share/applications $@ ; do
933 [[ -d ${D}${d} ]] && directories="${directories} ${D}${d}"
934 done
935 if [[ -n ${directories} ]] ; then
936 for FILE in $(find ${directories} -name "*\.desktop" \
937 -not -path '*.hidden*' | sort -u 2>/dev/null)
938 do
939 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | \
940 sed -e "s|error: ||" -e "s|${FILE}:|--|g" )
941 [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:}
942 done
943 fi
944 echo ""
945 else
946 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo."
947 fi
948}
949
950
920# Make a GDM/KDM Session file 951# Make a GDM/KDM Session file
921# 952#
922# make_session_desktop(<title>, <command>) 953# make_session_desktop(<title>, <command>)
923# title: File to execute to start the Window Manager 954# title: File to execute to start the Window Manager
924# command: Name of the Window Manager 955# command: Name of the Window Manager
929 960
930 local title=$1 961 local title=$1
931 local command=$2 962 local command=$2
932 local desktop=${T}/${wm}.desktop 963 local desktop=${T}/${wm}.desktop
933 964
965 cat <<-EOF > "${desktop}"
934echo "[Desktop Entry] 966 [Desktop Entry]
935Encoding=UTF-8 967 Encoding=UTF-8
936Name=${title} 968 Name=${title}
937Comment=This session logs you into ${title} 969 Comment=This session logs you into ${title}
938Exec=${command} 970 Exec=${command}
939TryExec=${command} 971 TryExec=${command}
940Type=Application" > "${desktop}" 972 Type=Application
973 EOF
941 974
975 (
976 # wrap the env here so that the 'insinto' call
977 # doesn't corrupt the env of the caller
942 insinto /usr/share/xsessions 978 insinto /usr/share/xsessions
943 doins "${desktop}" 979 doins "${desktop}"
980 )
944} 981}
945 982
946domenu() { 983domenu() {
984 (
985 # wrap the env here so that the 'insinto' call
986 # doesn't corrupt the env of the caller
947 local i j 987 local i j ret=0
948 insinto /usr/share/applications 988 insinto /usr/share/applications
949 for i in "$@" ; do 989 for i in "$@" ; do
950 if [[ -f ${i} ]] ; then 990 if [[ -f ${i} ]] ; then
951 doins "${i}" 991 doins "${i}"
992 ((ret+=$?))
952 elif [[ -d ${i} ]] ; then 993 elif [[ -d ${i} ]] ; then
953 for j in "${i}"/*.desktop ; do 994 for j in "${i}"/*.desktop ; do
954 doins "${j}" 995 doins "${j}"
996 ((ret+=$?))
955 done 997 done
956 fi 998 fi
957 done 999 done
1000 exit ${ret}
1001 )
958} 1002}
959newmenu() { 1003newmenu() {
1004 (
1005 # wrap the env here so that the 'insinto' call
1006 # doesn't corrupt the env of the caller
960 insinto /usr/share/applications 1007 insinto /usr/share/applications
961 newins "$1" "$2" 1008 newins "$@"
1009 )
962} 1010}
963 1011
964doicon() { 1012doicon() {
1013 (
1014 # wrap the env here so that the 'insinto' call
1015 # doesn't corrupt the env of the caller
965 local i j 1016 local i j ret
966 insinto /usr/share/pixmaps 1017 insinto /usr/share/pixmaps
967 for i in "$@" ; do 1018 for i in "$@" ; do
968 if [[ -f ${i} ]] ; then 1019 if [[ -f ${i} ]] ; then
969 doins "${i}" 1020 doins "${i}"
1021 ((ret+=$?))
970 elif [[ -d ${i} ]] ; then 1022 elif [[ -d ${i} ]] ; then
971 for j in "${i}"/*.png ; do 1023 for j in "${i}"/*.png ; do
972 doins "${j}" 1024 doins "${j}"
1025 ((ret+=$?))
973 done 1026 done
974 fi 1027 fi
975 done 1028 done
1029 exit ${ret}
1030 )
976} 1031}
977newicon() { 1032newicon() {
1033 (
1034 # wrap the env here so that the 'insinto' call
1035 # doesn't corrupt the env of the caller
978 insinto /usr/share/pixmaps 1036 insinto /usr/share/pixmaps
979 newins "$1" "$2" 1037 newins "$@"
1038 )
980} 1039}
981 1040
982############################################################## 1041##############################################################
983# END: Handle .desktop files and menu entries # 1042# END: Handle .desktop files and menu entries #
984############################################################## 1043##############################################################
1021# lseek 1080# lseek
1022# root@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin 1081# root@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin
1023# lseek(3, -4, SEEK_END) = 2981250 1082# lseek(3, -4, SEEK_END) = 2981250
1024# thus we would pass in the value of '4' as the second parameter. 1083# thus we would pass in the value of '4' as the second parameter.
1025unpack_pdv() { 1084unpack_pdv() {
1026 local src=$(find_unpackable_file $1) 1085 local src=$(find_unpackable_file "$1")
1027 local sizeoff_t=$2 1086 local sizeoff_t=$2
1028 1087
1029 [[ -z ${src} ]] && die "Could not locate source for '$1'" 1088 [[ -z ${src} ]] && die "Could not locate source for '$1'"
1030 [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :(" 1089 [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :("
1031 1090
1032 local shrtsrc=$(basename "${src}") 1091 local shrtsrc=$(basename "${src}")
1033 echo ">>> Unpacking ${shrtsrc} to ${PWD}" 1092 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1034 local metaskip=`tail -c ${sizeoff_t} ${src} | hexdump -e \"%i\"` 1093 local metaskip=$(tail -c ${sizeoff_t} "${src}" | hexdump -e \"%i\")
1035 local tailskip=`tail -c $((${sizeoff_t}*2)) ${src} | head -c ${sizeoff_t} | hexdump -e \"%i\"` 1094 local tailskip=$(tail -c $((${sizeoff_t}*2)) "${src}" | head -c ${sizeoff_t} | hexdump -e \"%i\")
1036 1095
1037 # grab metadata for debug reasons 1096 # grab metadata for debug reasons
1038 local metafile="$(emktemp)" 1097 local metafile=$(emktemp)
1039 tail -c +$((${metaskip}+1)) ${src} > ${metafile} 1098 tail -c +$((${metaskip}+1)) "${src}" > "${metafile}"
1040 1099
1041 # rip out the final file name from the metadata 1100 # rip out the final file name from the metadata
1042 local datafile="`tail -c +$((${metaskip}+1)) ${src} | strings | head -n 1`" 1101 local datafile=$(tail -c +$((${metaskip}+1)) "${src}" | strings | head -n 1)
1043 datafile="`basename ${datafile}`" 1102 datafile=$(basename "${datafile}")
1044 1103
1045 # now lets uncompress/untar the file if need be 1104 # now lets uncompress/untar the file if need be
1046 local tmpfile="$(emktemp)" 1105 local tmpfile=$(emktemp)
1047 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile} 1106 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile}
1048 1107
1049 local iscompressed="`file -b ${tmpfile}`" 1108 local iscompressed=$(file -b "${tmpfile}")
1050 if [ "${iscompressed:0:8}" == "compress" ] ; then 1109 if [[ ${iscompressed:0:8} == "compress" ]] ; then
1051 iscompressed=1 1110 iscompressed=1
1052 mv ${tmpfile}{,.Z} 1111 mv ${tmpfile}{,.Z}
1053 gunzip ${tmpfile} 1112 gunzip ${tmpfile}
1054 else 1113 else
1055 iscompressed=0 1114 iscompressed=0
1056 fi 1115 fi
1057 local istar="`file -b ${tmpfile}`" 1116 local istar=$(file -b "${tmpfile}")
1058 if [ "${istar:0:9}" == "POSIX tar" ] ; then 1117 if [[ ${istar:0:9} == "POSIX tar" ]] ; then
1059 istar=1 1118 istar=1
1060 else 1119 else
1061 istar=0 1120 istar=0
1062 fi 1121 fi
1063 1122
1155 dd) exe="dd ibs=${skip} skip=1 obs=1024 conv=sync if='${src}'";; 1214 dd) exe="dd ibs=${skip} skip=1 obs=1024 conv=sync if='${src}'";;
1156 *) die "makeself cant handle exe '${exe}'" 1215 *) die "makeself cant handle exe '${exe}'"
1157 esac 1216 esac
1158 1217
1159 # lets grab the first few bytes of the file to figure out what kind of archive it is 1218 # lets grab the first few bytes of the file to figure out what kind of archive it is
1160 local tmpfile="$(emktemp)" 1219 local tmpfile=$(emktemp)
1161 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}" 1220 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}"
1162 local filetype="$(file -b "${tmpfile}")" 1221 local filetype=$(file -b "${tmpfile}")
1163 case ${filetype} in 1222 case ${filetype} in
1164 *tar\ archive*) 1223 *tar\ archive*)
1165 eval ${exe} | tar --no-same-owner -xf - 1224 eval ${exe} | tar --no-same-owner -xf -
1166 ;; 1225 ;;
1167 bzip2*) 1226 bzip2*)
1212 return 0 1271 return 0
1213 fi 1272 fi
1214 done 1273 done
1215 set +o noglob; set -$shopts #reset old shell opts 1274 set +o noglob; set -$shopts #reset old shell opts
1216 1275
1217 local licmsg="$(emktemp)" 1276 local licmsg=$(emktemp)
1218 cat << EOF > ${licmsg} 1277 cat <<-EOF > ${licmsg}
1219********************************************************** 1278 **********************************************************
1220The following license outlines the terms of use of this 1279 The following license outlines the terms of use of this
1221package. You MUST accept this license for installation to 1280 package. You MUST accept this license for installation to
1222continue. When you are done viewing, hit 'q'. If you 1281 continue. When you are done viewing, hit 'q'. If you
1223CTRL+C out of this, the install will not run! 1282 CTRL+C out of this, the install will not run!
1224********************************************************** 1283 **********************************************************
1225 1284
1226EOF 1285 EOF
1227 cat ${lic} >> ${licmsg} 1286 cat ${lic} >> ${licmsg}
1228 ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}" 1287 ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}"
1229 einfon "Do you accept the terms of this license (${l})? [yes/no] " 1288 einfon "Do you accept the terms of this license (${l})? [yes/no] "
1230 read alic 1289 read alic
1231 case ${alic} in 1290 case ${alic} in
1536# an example might be from libogg.so.0 to libogg.so.1. Removing libogg.so.0 1595# an example might be from libogg.so.0 to libogg.so.1. Removing libogg.so.0
1537# would break packages that link against it. Most people get around this 1596# would break packages that link against it. Most people get around this
1538# by using the portage SLOT mechanism, but that is not always a relevant 1597# by using the portage SLOT mechanism, but that is not always a relevant
1539# solution, so instead you can add the following to your ebuilds: 1598# solution, so instead you can add the following to your ebuilds:
1540# 1599#
1541# src_install() { 1600# pkg_preinst() {
1542# ... 1601# ...
1543# preserve_old_lib /usr/$(get_libdir)/libogg.so.0 1602# preserve_old_lib /usr/$(get_libdir)/libogg.so.0
1544# ... 1603# ...
1545# } 1604# }
1546# 1605#
1549# preserve_old_lib_notify /usr/$(get_libdir)/libogg.so.0 1608# preserve_old_lib_notify /usr/$(get_libdir)/libogg.so.0
1550# ... 1609# ...
1551# } 1610# }
1552 1611
1553preserve_old_lib() { 1612preserve_old_lib() {
1554 LIB=$1 1613 if [[ ${EBUILD_PHASE} != "preinst" ]] ; then
1614 eerror "preserve_old_lib() must be called from pkg_preinst() only"
1615 die "Invalid preserve_old_lib() usage"
1616 fi
1617 [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]"
1555 1618
1556 if [ -n "${LIB}" -a -f "${ROOT}${LIB}" ]; then 1619 local lib dir
1557 SONAME=`basename ${LIB}` 1620 for lib in "$@" ; do
1558 DIRNAME=`dirname ${LIB}` 1621 [[ -e ${ROOT}/${lib} ]] || continue
1559 1622 dir=${lib%/*}
1560 dodir ${DIRNAME} 1623 dodir ${dir} || die "dodir ${dir} failed"
1561 cp ${ROOT}${LIB} ${D}${DIRNAME} 1624 cp "${ROOT}"/${lib} "${D}"/${lib} || die "cp ${lib} failed"
1562 touch ${D}${LIB} 1625 touch "${D}"/${lib}
1563 fi 1626 done
1564} 1627}
1565 1628
1566preserve_old_lib_notify() { 1629preserve_old_lib_notify() {
1567 LIB=$1 1630 if [[ ${EBUILD_PHASE} != "postinst" ]] ; then
1631 eerror "preserve_old_lib_notify() must be called from pkg_postinst() only"
1632 die "Invalid preserve_old_lib_notify() usage"
1633 fi
1568 1634
1569 if [ -n "${LIB}" -a -f "${ROOT}${LIB}" ]; then 1635 local lib notice=0
1570 SONAME=`basename ${LIB}` 1636 for lib in "$@" ; do
1571 1637 [[ -e ${ROOT}/${lib} ]] || continue
1638 if [[ ${notice} -eq 0 ]] ; then
1639 notice=1
1572 ewarn "An old version of an installed library was detected on your system." 1640 ewarn "Old versions of installed libraries were detected on your system."
1573 ewarn "In order to avoid breaking packages that link against it, this older version" 1641 ewarn "In order to avoid breaking packages that depend on these old libs,"
1574 ewarn "is not being removed. In order to make full use of this newer version," 1642 ewarn "the libraries are not being removed. You need to run revdep-rebuild"
1575 ewarn "you will need to execute the following command:" 1643 ewarn "in order to remove these old dependencies. If you do not have this"
1576 ewarn " revdep-rebuild --library ${SONAME}" 1644 ewarn "helper program, simply emerge the 'gentoolkit' package."
1577 ewarn 1645 ewarn
1578 ewarn "After doing that, you can safely remove ${LIB}"
1579 ewarn "Note: 'emerge gentoolkit' to get revdep-rebuild"
1580 fi 1646 fi
1647 ewarn " # revdep-rebuild --library ${lib##*/}"
1648 done
1581} 1649}
1582 1650
1583# Hack for people to figure out if a package was built with 1651# Hack for people to figure out if a package was built with
1584# certain USE flags 1652# certain USE flags
1585# 1653#
1586# Usage: built_with_use [-a|-o] <DEPEND ATOM> <List of USE flags> 1654# Usage: built_with_use [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1587# ex: built_with_use xchat gtk2 1655# ex: built_with_use xchat gtk2
1588# 1656#
1589# Flags: -a all USE flags should be utilized 1657# Flags: -a all USE flags should be utilized
1590# -o at least one USE flag should be utilized 1658# -o at least one USE flag should be utilized
1659# --missing peform the specified action if the flag is not in IUSE (true/false/die)
1660# --hidden USE flag we're checking is hidden expanded so it isnt in IUSE
1591# Note: the default flag is '-a' 1661# Note: the default flag is '-a'
1592built_with_use() { 1662built_with_use() {
1663 local hidden="no"
1664 if [[ $1 == "--hidden" ]] ; then
1665 hidden="yes"
1666 shift
1667 fi
1668
1669 local missing_action="die"
1670 if [[ $1 == "--missing" ]] ; then
1671 missing_action=$2
1672 shift ; shift
1673 case ${missing_action} in
1674 true|false|die) ;;
1675 *) die "unknown action '${missing_action}'";;
1676 esac
1677 fi
1678
1593 local opt=$1 1679 local opt=$1
1594 [[ ${opt:0:1} = "-" ]] && shift || opt="-a" 1680 [[ ${opt:0:1} = "-" ]] && shift || opt="-a"
1595 1681
1596 local PKG=$(best_version $1) 1682 local PKG=$(best_version $1)
1597 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package" 1683 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package"
1598 shift 1684 shift
1599 1685
1600 local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE 1686 local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE
1601 local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE 1687 local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE
1602 1688
1603 # if the USE file doesnt exist, assume the $PKG is either 1689 # if the IUSE file doesn't exist, the read will error out, we need to handle
1604 # injected or package.provided 1690 # this gracefully
1691 if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]] ; then
1692 case ${missing_action} in
1693 true) return 0;;
1694 false) return 1;;
1605 [[ ! -e ${USEFILE} ]] && die "Unable to determine what USE flags $PKG was built with" 1695 die) die "Unable to determine what USE flags $PKG was built with";;
1696 esac
1697 fi
1606 1698
1699 if [[ ${hidden} == "no" ]] ; then
1607 local IUSE_BUILT=$(<${IUSEFILE}) 1700 local IUSE_BUILT=$(<${IUSEFILE})
1608 # Don't check USE_EXPAND #147237 1701 # Don't check USE_EXPAND #147237
1609 local expand 1702 local expand
1610 for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]') ; do 1703 for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]') ; do
1611 if [[ $1 == ${expand}_* ]] ; then 1704 if [[ $1 == ${expand}_* ]] ; then
1612 expand="" 1705 expand=""
1613 break 1706 break
1614 fi 1707 fi
1615 done 1708 done
1616 if [[ -n ${expand} ]] ; then 1709 if [[ -n ${expand} ]] ; then
1710 if ! has $1 ${IUSE_BUILT} ; then
1711 case ${missing_action} in
1712 true) return 0;;
1713 false) return 1;;
1617 has $1 ${IUSE_BUILT} || die "$PKG does not actually support the $1 USE flag!" 1714 die) die "$PKG does not actually support the $1 USE flag!";;
1715 esac
1716 fi
1717 fi
1618 fi 1718 fi
1619 1719
1620 local USE_BUILT=$(<${USEFILE}) 1720 local USE_BUILT=$(<${USEFILE})
1621 while [[ $# -gt 0 ]] ; do 1721 while [[ $# -gt 0 ]] ; do
1622 if [[ ${opt} = "-o" ]] ; then 1722 if [[ ${opt} = "-o" ]] ; then

Legend:
Removed from v.1.266  
changed lines
  Added in v.1.279

  ViewVC Help
Powered by ViewVC 1.1.20