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

Diff of /eclass/eutils.eclass

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

Revision 1.268 Revision 1.278
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.268 2007/01/13 19:36:14 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.278 2007/04/22 15:55:07 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 $@ ; do
933 directories="${directories} ${D}${d}"
934 done
935 for FILE in $(find ${D}/usr/share/applications ${directories} -name "*\.desktop" \
936 -not -path '*.hidden*' | sort -u 2>/dev/null)
937 do
938 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | \
939 sed -e "s|error: ||" -e "s|${FILE}:|--|g" )
940 [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:}
941 done
942 echo ""
943 else
944 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo."
945 fi
946}
947
948
920# Make a GDM/KDM Session file 949# Make a GDM/KDM Session file
921# 950#
922# make_session_desktop(<title>, <command>) 951# make_session_desktop(<title>, <command>)
923# title: File to execute to start the Window Manager 952# title: File to execute to start the Window Manager
924# command: Name of the Window Manager 953# command: Name of the Window Manager
929 958
930 local title=$1 959 local title=$1
931 local command=$2 960 local command=$2
932 local desktop=${T}/${wm}.desktop 961 local desktop=${T}/${wm}.desktop
933 962
963 cat <<-EOF > "${desktop}"
934echo "[Desktop Entry] 964 [Desktop Entry]
935Encoding=UTF-8 965 Encoding=UTF-8
936Name=${title} 966 Name=${title}
937Comment=This session logs you into ${title} 967 Comment=This session logs you into ${title}
938Exec=${command} 968 Exec=${command}
939TryExec=${command} 969 TryExec=${command}
940Type=Application" > "${desktop}" 970 Type=Application
971 EOF
941 972
973 (
974 # wrap the env here so that the 'insinto' call
975 # doesn't corrupt the env of the caller
942 insinto /usr/share/xsessions 976 insinto /usr/share/xsessions
943 doins "${desktop}" 977 doins "${desktop}"
978 )
944} 979}
945 980
946domenu() { 981domenu() {
982 (
983 # wrap the env here so that the 'insinto' call
984 # doesn't corrupt the env of the caller
947 local i j 985 local i j ret=0
948 insinto /usr/share/applications 986 insinto /usr/share/applications
949 for i in "$@" ; do 987 for i in "$@" ; do
950 if [[ -f ${i} ]] ; then 988 if [[ -f ${i} ]] ; then
951 doins "${i}" 989 doins "${i}"
990 ((ret+=$?))
952 elif [[ -d ${i} ]] ; then 991 elif [[ -d ${i} ]] ; then
953 for j in "${i}"/*.desktop ; do 992 for j in "${i}"/*.desktop ; do
954 doins "${j}" 993 doins "${j}"
994 ((ret+=$?))
955 done 995 done
956 fi 996 fi
957 done 997 done
998 exit ${ret}
999 )
958} 1000}
959newmenu() { 1001newmenu() {
1002 (
1003 # wrap the env here so that the 'insinto' call
1004 # doesn't corrupt the env of the caller
960 insinto /usr/share/applications 1005 insinto /usr/share/applications
961 newins "$1" "$2" 1006 newins "$@"
1007 )
962} 1008}
963 1009
964doicon() { 1010doicon() {
1011 (
1012 # wrap the env here so that the 'insinto' call
1013 # doesn't corrupt the env of the caller
965 local i j 1014 local i j ret
966 insinto /usr/share/pixmaps 1015 insinto /usr/share/pixmaps
967 for i in "$@" ; do 1016 for i in "$@" ; do
968 if [[ -f ${i} ]] ; then 1017 if [[ -f ${i} ]] ; then
969 doins "${i}" 1018 doins "${i}"
1019 ((ret+=$?))
970 elif [[ -d ${i} ]] ; then 1020 elif [[ -d ${i} ]] ; then
971 for j in "${i}"/*.png ; do 1021 for j in "${i}"/*.png ; do
972 doins "${j}" 1022 doins "${j}"
1023 ((ret+=$?))
973 done 1024 done
974 fi 1025 fi
975 done 1026 done
1027 exit ${ret}
1028 )
976} 1029}
977newicon() { 1030newicon() {
1031 (
1032 # wrap the env here so that the 'insinto' call
1033 # doesn't corrupt the env of the caller
978 insinto /usr/share/pixmaps 1034 insinto /usr/share/pixmaps
979 newins "$1" "$2" 1035 newins "$@"
1036 )
980} 1037}
981 1038
982############################################################## 1039##############################################################
983# END: Handle .desktop files and menu entries # 1040# END: Handle .desktop files and menu entries #
984############################################################## 1041##############################################################
1021# lseek 1078# lseek
1022# root@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin 1079# root@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin
1023# lseek(3, -4, SEEK_END) = 2981250 1080# lseek(3, -4, SEEK_END) = 2981250
1024# thus we would pass in the value of '4' as the second parameter. 1081# thus we would pass in the value of '4' as the second parameter.
1025unpack_pdv() { 1082unpack_pdv() {
1026 local src=$(find_unpackable_file $1) 1083 local src=$(find_unpackable_file "$1")
1027 local sizeoff_t=$2 1084 local sizeoff_t=$2
1028 1085
1029 [[ -z ${src} ]] && die "Could not locate source for '$1'" 1086 [[ -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 :(" 1087 [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :("
1031 1088
1032 local shrtsrc=$(basename "${src}") 1089 local shrtsrc=$(basename "${src}")
1033 echo ">>> Unpacking ${shrtsrc} to ${PWD}" 1090 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1034 local metaskip=`tail -c ${sizeoff_t} ${src} | hexdump -e \"%i\"` 1091 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\"` 1092 local tailskip=$(tail -c $((${sizeoff_t}*2)) "${src}" | head -c ${sizeoff_t} | hexdump -e \"%i\")
1036 1093
1037 # grab metadata for debug reasons 1094 # grab metadata for debug reasons
1038 local metafile="$(emktemp)" 1095 local metafile=$(emktemp)
1039 tail -c +$((${metaskip}+1)) ${src} > ${metafile} 1096 tail -c +$((${metaskip}+1)) "${src}" > "${metafile}"
1040 1097
1041 # rip out the final file name from the metadata 1098 # rip out the final file name from the metadata
1042 local datafile="`tail -c +$((${metaskip}+1)) ${src} | strings | head -n 1`" 1099 local datafile=$(tail -c +$((${metaskip}+1)) "${src}" | strings | head -n 1)
1043 datafile="`basename ${datafile}`" 1100 datafile=$(basename "${datafile}")
1044 1101
1045 # now lets uncompress/untar the file if need be 1102 # now lets uncompress/untar the file if need be
1046 local tmpfile="$(emktemp)" 1103 local tmpfile=$(emktemp)
1047 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile} 1104 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile}
1048 1105
1049 local iscompressed="`file -b ${tmpfile}`" 1106 local iscompressed=$(file -b "${tmpfile}")
1050 if [ "${iscompressed:0:8}" == "compress" ] ; then 1107 if [[ ${iscompressed:0:8} == "compress" ]] ; then
1051 iscompressed=1 1108 iscompressed=1
1052 mv ${tmpfile}{,.Z} 1109 mv ${tmpfile}{,.Z}
1053 gunzip ${tmpfile} 1110 gunzip ${tmpfile}
1054 else 1111 else
1055 iscompressed=0 1112 iscompressed=0
1056 fi 1113 fi
1057 local istar="`file -b ${tmpfile}`" 1114 local istar=$(file -b "${tmpfile}")
1058 if [ "${istar:0:9}" == "POSIX tar" ] ; then 1115 if [[ ${istar:0:9} == "POSIX tar" ]] ; then
1059 istar=1 1116 istar=1
1060 else 1117 else
1061 istar=0 1118 istar=0
1062 fi 1119 fi
1063 1120
1155 dd) exe="dd ibs=${skip} skip=1 obs=1024 conv=sync if='${src}'";; 1212 dd) exe="dd ibs=${skip} skip=1 obs=1024 conv=sync if='${src}'";;
1156 *) die "makeself cant handle exe '${exe}'" 1213 *) die "makeself cant handle exe '${exe}'"
1157 esac 1214 esac
1158 1215
1159 # lets grab the first few bytes of the file to figure out what kind of archive it is 1216 # lets grab the first few bytes of the file to figure out what kind of archive it is
1160 local tmpfile="$(emktemp)" 1217 local tmpfile=$(emktemp)
1161 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}" 1218 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}"
1162 local filetype="$(file -b "${tmpfile}")" 1219 local filetype=$(file -b "${tmpfile}")
1163 case ${filetype} in 1220 case ${filetype} in
1164 *tar\ archive*) 1221 *tar\ archive*)
1165 eval ${exe} | tar --no-same-owner -xf - 1222 eval ${exe} | tar --no-same-owner -xf -
1166 ;; 1223 ;;
1167 bzip2*) 1224 bzip2*)
1212 return 0 1269 return 0
1213 fi 1270 fi
1214 done 1271 done
1215 set +o noglob; set -$shopts #reset old shell opts 1272 set +o noglob; set -$shopts #reset old shell opts
1216 1273
1217 local licmsg="$(emktemp)" 1274 local licmsg=$(emktemp)
1218 cat << EOF > ${licmsg} 1275 cat <<-EOF > ${licmsg}
1219********************************************************** 1276 **********************************************************
1220The following license outlines the terms of use of this 1277 The following license outlines the terms of use of this
1221package. You MUST accept this license for installation to 1278 package. You MUST accept this license for installation to
1222continue. When you are done viewing, hit 'q'. If you 1279 continue. When you are done viewing, hit 'q'. If you
1223CTRL+C out of this, the install will not run! 1280 CTRL+C out of this, the install will not run!
1224********************************************************** 1281 **********************************************************
1225 1282
1226EOF 1283 EOF
1227 cat ${lic} >> ${licmsg} 1284 cat ${lic} >> ${licmsg}
1228 ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}" 1285 ${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] " 1286 einfon "Do you accept the terms of this license (${l})? [yes/no] "
1230 read alic 1287 read alic
1231 case ${alic} in 1288 case ${alic} in
1551# } 1608# }
1552 1609
1553preserve_old_lib() { 1610preserve_old_lib() {
1554 if [[ ${EBUILD_PHASE} != "preinst" ]] ; then 1611 if [[ ${EBUILD_PHASE} != "preinst" ]] ; then
1555 eerror "preserve_old_lib() must be called from pkg_preinst() only" 1612 eerror "preserve_old_lib() must be called from pkg_preinst() only"
1556# die "Invalid preserve_old_lib() usage" 1613 die "Invalid preserve_old_lib() usage"
1557 fi 1614 fi
1558 [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]" 1615 [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]"
1559 1616
1560 local lib dir 1617 local lib dir
1561 for lib in "$@" ; do 1618 for lib in "$@" ; do
1568} 1625}
1569 1626
1570preserve_old_lib_notify() { 1627preserve_old_lib_notify() {
1571 if [[ ${EBUILD_PHASE} != "postinst" ]] ; then 1628 if [[ ${EBUILD_PHASE} != "postinst" ]] ; then
1572 eerror "preserve_old_lib_notify() must be called from pkg_postinst() only" 1629 eerror "preserve_old_lib_notify() must be called from pkg_postinst() only"
1573# die "Invalid preserve_old_lib_notify() usage" 1630 die "Invalid preserve_old_lib_notify() usage"
1574 fi 1631 fi
1575 1632
1576 local lib notice=0 1633 local lib notice=0
1577 for lib in "$@" ; do 1634 for lib in "$@" ; do
1578 [[ -e ${ROOT}/${lib} ]] || continue 1635 [[ -e ${ROOT}/${lib} ]] || continue
1590} 1647}
1591 1648
1592# Hack for people to figure out if a package was built with 1649# Hack for people to figure out if a package was built with
1593# certain USE flags 1650# certain USE flags
1594# 1651#
1595# Usage: built_with_use [-a|-o] <DEPEND ATOM> <List of USE flags> 1652# Usage: built_with_use [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1596# ex: built_with_use xchat gtk2 1653# ex: built_with_use xchat gtk2
1597# 1654#
1598# Flags: -a all USE flags should be utilized 1655# Flags: -a all USE flags should be utilized
1599# -o at least one USE flag should be utilized 1656# -o at least one USE flag should be utilized
1657# --missing peform the specified action if the flag is not in IUSE (true/false/die)
1658# --hidden USE flag we're checking is hidden expanded so it isnt in IUSE
1600# Note: the default flag is '-a' 1659# Note: the default flag is '-a'
1601built_with_use() { 1660built_with_use() {
1661 local hidden="no"
1662 if [[ $1 == "--hidden" ]] ; then
1663 hidden="yes"
1664 shift
1665 fi
1666
1667 local missing_action="die"
1668 if [[ $1 == "--missing" ]] ; then
1669 missing_action=$2
1670 shift ; shift
1671 case ${missing_action} in
1672 true|false|die) ;;
1673 *) die "unknown action '${missing_action}'";;
1674 esac
1675 fi
1676
1602 local opt=$1 1677 local opt=$1
1603 [[ ${opt:0:1} = "-" ]] && shift || opt="-a" 1678 [[ ${opt:0:1} = "-" ]] && shift || opt="-a"
1604 1679
1605 local PKG=$(best_version $1) 1680 local PKG=$(best_version $1)
1606 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package" 1681 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package"
1607 shift 1682 shift
1608 1683
1609 local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE 1684 local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE
1610 local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE 1685 local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE
1611 1686
1612 # if the USE file doesnt exist, assume the $PKG is either 1687 # if the IUSE file doesn't exist, the read will error out, we need to handle
1613 # injected or package.provided 1688 # this gracefully
1689 if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]] ; then
1690 case ${missing_action} in
1691 true) return 0;;
1692 false) return 1;;
1614 [[ ! -e ${USEFILE} ]] && die "Unable to determine what USE flags $PKG was built with" 1693 die) die "Unable to determine what USE flags $PKG was built with";;
1694 esac
1695 fi
1615 1696
1697 if [[ ${hidden} == "no" ]] ; then
1616 local IUSE_BUILT=$(<${IUSEFILE}) 1698 local IUSE_BUILT=$(<${IUSEFILE})
1617 # Don't check USE_EXPAND #147237 1699 # Don't check USE_EXPAND #147237
1618 local expand 1700 local expand
1619 for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]') ; do 1701 for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]') ; do
1620 if [[ $1 == ${expand}_* ]] ; then 1702 if [[ $1 == ${expand}_* ]] ; then
1621 expand="" 1703 expand=""
1622 break 1704 break
1623 fi 1705 fi
1624 done 1706 done
1625 if [[ -n ${expand} ]] ; then 1707 if [[ -n ${expand} ]] ; then
1708 if ! has $1 ${IUSE_BUILT} ; then
1709 case ${missing_action} in
1710 true) return 0;;
1711 false) return 1;;
1626 has $1 ${IUSE_BUILT} || die "$PKG does not actually support the $1 USE flag!" 1712 die) die "$PKG does not actually support the $1 USE flag!";;
1713 esac
1714 fi
1715 fi
1627 fi 1716 fi
1628 1717
1629 local USE_BUILT=$(<${USEFILE}) 1718 local USE_BUILT=$(<${USEFILE})
1630 while [[ $# -gt 0 ]] ; do 1719 while [[ $# -gt 0 ]] ; do
1631 if [[ ${opt} = "-o" ]] ; then 1720 if [[ ${opt} = "-o" ]] ; then

Legend:
Removed from v.1.268  
changed lines
  Added in v.1.278

  ViewVC Help
Powered by ViewVC 1.1.20