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

Diff of /eclass/eutils.eclass

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

Revision 1.310 Revision 1.324
1# Copyright 1999-2007 Gentoo Foundation 1# Copyright 1999-2009 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.310 2009/02/15 20:09:09 grobian Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.324 2010/01/03 19:57:10 zmedico Exp $
4 4
5# @ECLASS: eutils.eclass 5# @ECLASS: eutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# base-system@gentoo.org 7# base-system@gentoo.org
8# @BLURB: many extra (but common) functions that are used in ebuilds 8# @BLURB: many extra (but common) functions that are used in ebuilds
66# Remove .svn directories recursiveley. Useful when a source tarball contains 66# Remove .svn directories recursiveley. Useful when a source tarball contains
67# internal Subversion directories. Defaults to $PWD. 67# internal Subversion directories. Defaults to $PWD.
68esvn_clean() { 68esvn_clean() {
69 [[ -z $* ]] && set -- . 69 [[ -z $* ]] && set -- .
70 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf 70 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
71}
72
73# @FUNCTION: eshopts_push
74# @USAGE: [options to `set`]
75# @DESCRIPTION:
76# Often times code will want to enable a shell option to change code behavior.
77# Since changing shell options can easily break other pieces of code (which
78# assume the default state), eshopts_push is used to (1) push the current shell
79# options onto a stack and (2) pass the specified arguments to set.
80#
81# A common example is to disable shell globbing so that special meaning/care
82# may be used with variables/arguments to custom functions. That would be:
83# @CODE
84# eshopts_push -o noglob
85# for x in ${foo} ; do
86# if ...some check... ; then
87# eshopts_pop
88# return 0
89# fi
90# done
91# eshopts_pop
92# @CODE
93eshopts_push() {
94 # have to assume __ESHOPTS_SAVE__ isn't screwed with
95 # as a `declare -a` here will reset its value
96 local i=${#__ESHOPTS_SAVE__[@]}
97 __ESHOPTS_SAVE__[$i]=$-
98 [[ $# -eq 0 ]] && return 0
99 set "$@" || die "eshopts_push: bad options to set: $*"
100}
101
102# @FUNCTION: eshopts_pop
103# @USAGE:
104# @DESCRIPTION:
105# Restore the shell options to the state saved with the corresponding
106# eshopts_push call. See that function for more details.
107eshopts_pop() {
108 [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments"
109 local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 ))
110 [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair"
111 local s=${__ESHOPTS_SAVE__[$i]}
112 unset __ESHOPTS_SAVE__[$i]
113 set +$- || die "eshopts_pop: sanity: invalid shell settings: $-"
114 set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}"
71} 115}
72 116
73# Default directory where patches are located 117# Default directory where patches are located
74EPATCH_SOURCE="${WORKDIR}/patch" 118EPATCH_SOURCE="${WORKDIR}/patch"
75# Default extension for patches 119# Default extension for patches
183 227
184 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" 228 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
185 fi 229 fi
186 230
187 case ${EPATCH_SUFFIX##*\.} in 231 case ${EPATCH_SUFFIX##*\.} in
232 xz)
233 PIPE_CMD="xz -dc"
234 PATCH_SUFFIX="xz"
235 ;;
188 lzma) 236 lzma)
189 PIPE_CMD="lzma -dc" 237 PIPE_CMD="lzma -dc"
190 PATCH_SUFFIX="lzma" 238 PATCH_SUFFIX="lzma"
191 ;; 239 ;;
192 bz2) 240 bz2)
343 if [ "${SINGLE_PATCH}" = "no" ] 391 if [ "${SINGLE_PATCH}" = "no" ]
344 then 392 then
345 einfo "Done with patching" 393 einfo "Done with patching"
346 fi 394 fi
347} 395}
396epatch_user() {
397 [[ $# -ne 0 ]] && die "epatch_user takes no options"
398
399 # don't clobber any EPATCH vars that the parent might want
400 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
401 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
402 EPATCH_SOURCE=${base}/${CTARGET}/${check}
403 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
404 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
405 if [[ -d ${EPATCH_SOURCE} ]] ; then
406 EPATCH_SOURCE=${EPATCH_SOURCE} \
407 EPATCH_SUFFIX="patch" \
408 EPATCH_FORCE="yes" \
409 EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \
410 epatch
411 break
412 fi
413 done
414}
348 415
349# @FUNCTION: emktemp 416# @FUNCTION: emktemp
350# @USAGE: [temp dir] 417# @USAGE: [temp dir]
351# @DESCRIPTION: 418# @DESCRIPTION:
352# Cheap replacement for when debianutils (and thus mktemp) 419# Cheap replacement for when debianutils (and thus mktemp)
392# Small wrapper for getent (Linux), 459# Small wrapper for getent (Linux),
393# nidump (< Mac OS X 10.5), dscl (Mac OS X 10.5), 460# nidump (< Mac OS X 10.5), dscl (Mac OS X 10.5),
394# and pw (FreeBSD) used in enewuser()/enewgroup() 461# and pw (FreeBSD) used in enewuser()/enewgroup()
395egetent() { 462egetent() {
396 case ${CHOST} in 463 case ${CHOST} in
464 *-darwin[678])
465 case "$2" in
466 *[!0-9]*) # Non numeric
467 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
468 ;;
469 *) # Numeric
470 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
471 ;;
472 esac
473 ;;
397 *-darwin9) 474 *-darwin*)
398 local mytype=$1 475 local mytype=$1
399 [[ "passwd" == $mytype ]] && mytype="Users" 476 [[ "passwd" == $mytype ]] && mytype="Users"
400 [[ "group" == $mytype ]] && mytype="Groups" 477 [[ "group" == $mytype ]] && mytype="Groups"
401 case "$2" in 478 case "$2" in
402 *[!0-9]*) # Non numeric 479 *[!0-9]*) # Non numeric
404 ;; 481 ;;
405 *) # Numeric 482 *) # Numeric
406 local mykey="UniqueID" 483 local mykey="UniqueID"
407 [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID" 484 [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID"
408 dscl . -search /$mytype $mykey $2 2>/dev/null 485 dscl . -search /$mytype $mykey $2 2>/dev/null
409 ;;
410 esac
411 ;;
412 *-darwin*)
413 case "$2" in
414 *[!0-9]*) # Non numeric
415 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
416 ;;
417 *) # Numeric
418 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
419 ;; 486 ;;
420 esac 487 esac
421 ;; 488 ;;
422 *-freebsd*|*-dragonfly*) 489 *-freebsd*|*-dragonfly*)
423 local opts action="user" 490 local opts action="user"
623 fi 690 fi
624 ;; 691 ;;
625 692
626 *) 693 *)
627 if [[ -z $@ ]] ; then 694 if [[ -z $@ ]] ; then
628 useradd ${opts} ${euser} \ 695 useradd ${opts} \
629 -c "added by portage for ${PN}" \ 696 -c "added by portage for ${PN}" \
697 ${euser} \
630 || die "enewuser failed" 698 || die "enewuser failed"
631 else 699 else
632 einfo " - Extra: $@" 700 einfo " - Extra: $@"
633 useradd ${opts} ${euser} "$@" \ 701 useradd ${opts} "$@" \
702 ${euser} \
634 || die "enewuser failed" 703 || die "enewuser failed"
635 fi 704 fi
636 ;; 705 ;;
637 esac 706 esac
638 707
920 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop" 989 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop"
921 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop 990 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop
922 991
923 cat <<-EOF > "${desktop}" 992 cat <<-EOF > "${desktop}"
924 [Desktop Entry] 993 [Desktop Entry]
925 Version=1.0
926 Name=${name} 994 Name=${name}
927 Type=Application 995 Type=Application
928 Comment=${DESCRIPTION} 996 Comment=${DESCRIPTION}
929 Exec=${exec} 997 Exec=${exec}
930 TryExec=${exec%% *} 998 TryExec=${exec%% *}
969 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo." 1037 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo."
970 fi 1038 fi
971} 1039}
972 1040
973# @FUNCTION: make_session_desktop 1041# @FUNCTION: make_session_desktop
974# @USAGE: <title> <command> 1042# @USAGE: <title> <command> [command args...]
975# @DESCRIPTION: 1043# @DESCRIPTION:
976# Make a GDM/KDM Session file. The title is the file to execute to start the 1044# Make a GDM/KDM Session file. The title is the file to execute to start the
977# Window Manager. The command is the name of the Window Manager. 1045# Window Manager. The command is the name of the Window Manager.
1046#
1047# You can set the name of the file via the ${wm} variable.
978make_session_desktop() { 1048make_session_desktop() {
979 [[ -z $1 ]] && eerror "make_session_desktop: You must specify the title" && return 1 1049 [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1
980 [[ -z $2 ]] && eerror "make_session_desktop: You must specify the command" && return 1 1050 [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1
981 1051
982 local title=$1 1052 local title=$1
983 local command=$2 1053 local command=$2
984 local desktop=${T}/${wm}.desktop 1054 local desktop=${T}/${wm:-${PN}}.desktop
1055 shift 2
985 1056
986 cat <<-EOF > "${desktop}" 1057 cat <<-EOF > "${desktop}"
987 [Desktop Entry] 1058 [Desktop Entry]
988 Name=${title} 1059 Name=${title}
989 Comment=This session logs you into ${title} 1060 Comment=This session logs you into ${title}
990 Exec=${command} 1061 Exec=${command} $*
991 TryExec=${command} 1062 TryExec=${command}
992 Type=Application 1063 Type=XSession
993 EOF 1064 EOF
994 1065
995 ( 1066 (
996 # wrap the env here so that the 'insinto' call 1067 # wrap the env here so that the 'insinto' call
997 # doesn't corrupt the env of the caller 1068 # doesn't corrupt the env of the caller
1309 lic="${PWD}/${lic}" 1380 lic="${PWD}/${lic}"
1310 elif [ -e "${lic}" ] ; then 1381 elif [ -e "${lic}" ] ; then
1311 lic="${lic}" 1382 lic="${lic}"
1312 fi 1383 fi
1313 fi 1384 fi
1314 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1315 local l="`basename ${lic}`" 1385 local l="`basename ${lic}`"
1316 1386
1317 # here is where we check for the licenses the user already 1387 # here is where we check for the licenses the user already
1318 # accepted ... if we don't find a match, we make the user accept 1388 # accepted ... if we don't find a match, we make the user accept
1319 local shopts=$-
1320 local alic 1389 local alic
1321 set -o noglob #so that bash doesn't expand "*" 1390 eshopts_push -o noglob # so that bash doesn't expand "*"
1322 for alic in ${ACCEPT_LICENSE} ; do 1391 for alic in ${ACCEPT_LICENSE} ; do
1323 if [[ ${alic} == ${l} ]]; then 1392 if [[ ${alic} == ${l} ]]; then
1324 set +o noglob; set -${shopts} #reset old shell opts 1393 eshopts_pop
1325 return 0 1394 return 0
1326 fi 1395 fi
1327 done 1396 done
1328 set +o noglob; set -$shopts #reset old shell opts 1397 eshopts_pop
1398 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1329 1399
1330 local licmsg=$(emktemp) 1400 local licmsg=$(emktemp)
1331 cat <<-EOF > ${licmsg} 1401 cat <<-EOF > ${licmsg}
1332 ********************************************************** 1402 **********************************************************
1333 The following license outlines the terms of use of this 1403 The following license outlines the terms of use of this
1580# of the lists. 1650# of the lists.
1581strip-linguas() { 1651strip-linguas() {
1582 local ls newls nols 1652 local ls newls nols
1583 if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then 1653 if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then
1584 local op=$1; shift 1654 local op=$1; shift
1585 ls=$(find "$1" -name '*.po' -exec basename {} .po \;); shift 1655 ls=$(find "$1" -name '*.po' -exec basename {} .po ';'); shift
1586 local d f 1656 local d f
1587 for d in "$@" ; do 1657 for d in "$@" ; do
1588 if [[ ${op} == "-u" ]] ; then 1658 if [[ ${op} == "-u" ]] ; then
1589 newls=${ls} 1659 newls=${ls}
1590 else 1660 else
1591 newls="" 1661 newls=""
1592 fi 1662 fi
1593 for f in $(find "$d" -name '*.po' -exec basename {} .po \;) ; do 1663 for f in $(find "$d" -name '*.po' -exec basename {} .po ';') ; do
1594 if [[ ${op} == "-i" ]] ; then 1664 if [[ ${op} == "-i" ]] ; then
1595 hasq ${f} ${ls} && newls="${newls} ${f}" 1665 hasq ${f} ${ls} && newls="${newls} ${f}"
1596 else 1666 else
1597 hasq ${f} ${ls} || newls="${newls} ${f}" 1667 hasq ${f} ${ls} || newls="${newls} ${f}"
1598 fi 1668 fi
1611 else 1681 else
1612 nols="${nols} ${f}" 1682 nols="${nols} ${f}"
1613 fi 1683 fi
1614 done 1684 done
1615 [[ -n ${nols} ]] \ 1685 [[ -n ${nols} ]] \
1616 && ewarn "Sorry, but ${PN} does not support the LINGUAs:" ${nols} 1686 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1617 export LINGUAS=${newls:1} 1687 export LINGUAS=${newls:1}
1618} 1688}
1619 1689
1620# @FUNCTION: preserve_old_lib 1690# @FUNCTION: preserve_old_lib
1621# @USAGE: <libs to preserve> [more libs] 1691# @USAGE: <libs to preserve> [more libs]
1821 ) || die 1891 ) || die
1822 else 1892 else
1823 newbin "${tmpwrapper}" "${wrapper}" || die 1893 newbin "${tmpwrapper}" "${wrapper}" || die
1824 fi 1894 fi
1825} 1895}
1896
1897# @FUNCTION: prepalldocs
1898# @USAGE:
1899# @DESCRIPTION:
1900# Compress files in /usr/share/doc which are not already
1901# compressed, excluding /usr/share/doc/${PF}/html.
1902# Uses the ecompressdir to do the compression.
1903# 2009-02-18 by betelgeuse:
1904# Commented because ecompressdir is even more internal to
1905# Portage than prepalldocs (it's not even mentioned in man 5
1906# ebuild). Please submit a better version for review to gentoo-dev
1907# if you want prepalldocs here.
1908#prepalldocs() {
1909# if [[ -n $1 ]] ; then
1910# ewarn "prepalldocs: invalid usage; takes no arguments"
1911# fi
1912
1913# cd "${D}"
1914# [[ -d usr/share/doc ]] || return 0
1915
1916# find usr/share/doc -exec gzip {} +
1917# ecompressdir --ignore /usr/share/doc/${PF}/html
1918# ecompressdir --queue /usr/share/doc
1919#}

Legend:
Removed from v.1.310  
changed lines
  Added in v.1.324

  ViewVC Help
Powered by ViewVC 1.1.20