| 1 | # Copyright 1999-2009 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.327 2010/01/10 15:49:01 scarabeus Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.334 2010/02/26 03:15:26 abcd 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 |
| … | |
… | |
| 17 | |
17 | |
| 18 | inherit multilib portability |
18 | inherit multilib portability |
| 19 | |
19 | |
| 20 | DESCRIPTION="Based on the ${ECLASS} eclass" |
20 | DESCRIPTION="Based on the ${ECLASS} eclass" |
| 21 | |
21 | |
|
|
22 | if has "${EAPI:-0}" 0 1 2; then |
|
|
23 | |
| 22 | # @FUNCTION: epause |
24 | # @FUNCTION: epause |
| 23 | # @USAGE: [seconds] |
25 | # @USAGE: [seconds] |
| 24 | # @DESCRIPTION: |
26 | # @DESCRIPTION: |
| 25 | # Sleep for the specified number of seconds (default of 5 seconds). Useful when |
27 | # Sleep for the specified number of seconds (default of 5 seconds). Useful when |
| 26 | # printing a message the user should probably be reading and often used in |
28 | # printing a message the user should probably be reading and often used in |
| 27 | # conjunction with the ebeep function. If the EPAUSE_IGNORE env var is set, |
29 | # conjunction with the ebeep function. If the EPAUSE_IGNORE env var is set, |
| 28 | # don't wait at all. |
30 | # don't wait at all. Defined in EAPIs 0 1 and 2. |
| 29 | epause() { |
31 | epause() { |
| 30 | [[ -z ${EPAUSE_IGNORE} ]] && sleep ${1:-5} |
32 | [[ -z ${EPAUSE_IGNORE} ]] && sleep ${1:-5} |
| 31 | } |
33 | } |
| 32 | |
34 | |
| 33 | # @FUNCTION: ebeep |
35 | # @FUNCTION: ebeep |
| 34 | # @USAGE: [number of beeps] |
36 | # @USAGE: [number of beeps] |
| 35 | # @DESCRIPTION: |
37 | # @DESCRIPTION: |
| 36 | # Issue the specified number of beeps (default of 5 beeps). Useful when |
38 | # Issue the specified number of beeps (default of 5 beeps). Useful when |
| 37 | # printing a message the user should probably be reading and often used in |
39 | # printing a message the user should probably be reading and often used in |
| 38 | # conjunction with the epause function. If the EBEEP_IGNORE env var is set, |
40 | # conjunction with the epause function. If the EBEEP_IGNORE env var is set, |
| 39 | # don't beep at all. |
41 | # don't beep at all. Defined in EAPIs 0 1 and 2. |
| 40 | ebeep() { |
42 | ebeep() { |
| 41 | local n |
43 | local n |
| 42 | if [[ -z ${EBEEP_IGNORE} ]] ; then |
44 | if [[ -z ${EBEEP_IGNORE} ]] ; then |
| 43 | for ((n=1 ; n <= ${1:-5} ; n++)) ; do |
45 | for ((n=1 ; n <= ${1:-5} ; n++)) ; do |
| 44 | echo -ne "\a" |
46 | echo -ne "\a" |
| … | |
… | |
| 47 | sleep 1 |
49 | sleep 1 |
| 48 | done |
50 | done |
| 49 | fi |
51 | fi |
| 50 | } |
52 | } |
| 51 | |
53 | |
|
|
54 | else |
|
|
55 | |
|
|
56 | ebeep() { |
|
|
57 | [[ $(type -t eqawarn) == function ]] && \ |
|
|
58 | eqawarn "QA Notice: ebeep is not defined in EAPI=3, please file a bug at http://bugs.gentoo.org" |
|
|
59 | } |
|
|
60 | |
|
|
61 | epause() { |
|
|
62 | [[ $(type -t eqawarn) == function ]] && \ |
|
|
63 | eqawarn "QA Notice: epause is not defined in EAPI=3, please file a bug at http://bugs.gentoo.org" |
|
|
64 | } |
|
|
65 | |
|
|
66 | fi |
|
|
67 | |
| 52 | # @FUNCTION: ecvs_clean |
68 | # @FUNCTION: ecvs_clean |
| 53 | # @USAGE: [list of dirs] |
69 | # @USAGE: [list of dirs] |
| 54 | # @DESCRIPTION: |
70 | # @DESCRIPTION: |
| 55 | # Remove CVS directories recursiveley. Useful when a source tarball contains |
71 | # Remove CVS directories recursiveley. Useful when a source tarball contains |
| 56 | # internal CVS directories. Defaults to $PWD. |
72 | # internal CVS directories. Defaults to $PWD. |
| … | |
… | |
| 69 | [[ -z $* ]] && set -- . |
85 | [[ -z $* ]] && set -- . |
| 70 | find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf |
86 | find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf |
| 71 | } |
87 | } |
| 72 | |
88 | |
| 73 | # @FUNCTION: eshopts_push |
89 | # @FUNCTION: eshopts_push |
| 74 | # @USAGE: [options to `set`] |
90 | # @USAGE: [options to `set` or `shopt`] |
| 75 | # @DESCRIPTION: |
91 | # @DESCRIPTION: |
| 76 | # Often times code will want to enable a shell option to change code behavior. |
92 | # 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 |
93 | # 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 |
94 | # 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. |
95 | # options onto a stack and (2) pass the specified arguments to set. |
|
|
96 | # |
|
|
97 | # If the first argument is '-s' or '-u', we assume you want to call `shopt` |
|
|
98 | # rather than `set` as there are some options only available via that. |
| 80 | # |
99 | # |
| 81 | # A common example is to disable shell globbing so that special meaning/care |
100 | # 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: |
101 | # may be used with variables/arguments to custom functions. That would be: |
| 83 | # @CODE |
102 | # @CODE |
| 84 | # eshopts_push -o noglob |
103 | # eshopts_push -o noglob |
| … | |
… | |
| 92 | # @CODE |
111 | # @CODE |
| 93 | eshopts_push() { |
112 | eshopts_push() { |
| 94 | # have to assume __ESHOPTS_SAVE__ isn't screwed with |
113 | # have to assume __ESHOPTS_SAVE__ isn't screwed with |
| 95 | # as a `declare -a` here will reset its value |
114 | # as a `declare -a` here will reset its value |
| 96 | local i=${#__ESHOPTS_SAVE__[@]} |
115 | local i=${#__ESHOPTS_SAVE__[@]} |
|
|
116 | if [[ $1 == -[su] ]] ; then |
| 97 | __ESHOPTS_SAVE__[$i]=$- |
117 | __ESHOPTS_SAVE__[$i]=$(shopt -p) |
| 98 | [[ $# -eq 0 ]] && return 0 |
118 | [[ $# -eq 0 ]] && return 0 |
|
|
119 | shopt "$@" || die "eshopts_push: bad options to shopt: $*" |
|
|
120 | else |
|
|
121 | __ESHOPTS_SAVE__[$i]=$- |
|
|
122 | [[ $# -eq 0 ]] && return 0 |
| 99 | set "$@" || die "eshopts_push: bad options to set: $*" |
123 | set "$@" || die "eshopts_push: bad options to set: $*" |
|
|
124 | fi |
| 100 | } |
125 | } |
| 101 | |
126 | |
| 102 | # @FUNCTION: eshopts_pop |
127 | # @FUNCTION: eshopts_pop |
| 103 | # @USAGE: |
128 | # @USAGE: |
| 104 | # @DESCRIPTION: |
129 | # @DESCRIPTION: |
| … | |
… | |
| 108 | [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments" |
133 | [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments" |
| 109 | local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 )) |
134 | local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 )) |
| 110 | [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair" |
135 | [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair" |
| 111 | local s=${__ESHOPTS_SAVE__[$i]} |
136 | local s=${__ESHOPTS_SAVE__[$i]} |
| 112 | unset __ESHOPTS_SAVE__[$i] |
137 | unset __ESHOPTS_SAVE__[$i] |
|
|
138 | if [[ ${s} == "shopt -"* ]] ; then |
|
|
139 | eval "${s}" || die "eshopts_pop: sanity: invalid shopt options: ${s}" |
|
|
140 | else |
| 113 | set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" |
141 | set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" |
| 114 | set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" |
142 | set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" |
|
|
143 | fi |
| 115 | } |
144 | } |
| 116 | |
145 | |
| 117 | # @VARIABLE: EPATCH_SOURCE |
146 | # @VARIABLE: EPATCH_SOURCE |
| 118 | # @DESCRIPTION: |
147 | # @DESCRIPTION: |
| 119 | # Default directory to search for patches. |
148 | # Default directory to search for patches. |
| … | |
… | |
| 263 | # Let people filter things dynamically |
292 | # Let people filter things dynamically |
| 264 | if [[ -n ${EPATCH_EXCLUDE} ]] ; then |
293 | if [[ -n ${EPATCH_EXCLUDE} ]] ; then |
| 265 | # let people use globs in the exclude |
294 | # let people use globs in the exclude |
| 266 | eshopts_push -o noglob |
295 | eshopts_push -o noglob |
| 267 | |
296 | |
| 268 | local ex skip |
297 | local ex |
| 269 | for ex in ${EPATCH_EXCLUDE} ; do |
298 | for ex in ${EPATCH_EXCLUDE} ; do |
| 270 | [[ ${patchname} == ${ex} ]] && skip=1 |
299 | if [[ ${patchname} == ${ex} ]] ; then |
|
|
300 | eshopts_pop |
|
|
301 | continue 2 |
|
|
302 | fi |
| 271 | done |
303 | done |
| 272 | |
304 | |
| 273 | eshopts_pop |
305 | eshopts_pop |
| 274 | |
|
|
| 275 | [[ ${skip} = 1 ]] && continue |
|
|
| 276 | fi |
306 | fi |
| 277 | |
307 | |
| 278 | if [[ ${SINGLE_PATCH} == "yes" ]] ; then |
308 | if [[ ${SINGLE_PATCH} == "yes" ]] ; then |
| 279 | if [[ -n ${EPATCH_SINGLE_MSG} ]] ; then |
309 | if [[ -n ${EPATCH_SINGLE_MSG} ]] ; then |
| 280 | einfo "${EPATCH_SINGLE_MSG}" |
310 | einfo "${EPATCH_SINGLE_MSG}" |
| … | |
… | |
| 929 | irc) type=IRCClient;; |
959 | irc) type=IRCClient;; |
| 930 | mail) type=Email;; |
960 | mail) type=Email;; |
| 931 | news) type=News;; |
961 | news) type=News;; |
| 932 | nntp) type=News;; |
962 | nntp) type=News;; |
| 933 | p2p) type=FileTransfer;; |
963 | p2p) type=FileTransfer;; |
|
|
964 | voip) type=Telephony;; |
| 934 | *) type=;; |
965 | *) type=;; |
| 935 | esac |
966 | esac |
| 936 | type="Network;${type}" |
967 | type="Network;${type}" |
| 937 | ;; |
968 | ;; |
| 938 | |
969 | |
| … | |
… | |
| 947 | math*) type=Math;; |
978 | math*) type=Math;; |
| 948 | physics) type=Physics;; |
979 | physics) type=Physics;; |
| 949 | visual*) type=DataVisualization;; |
980 | visual*) type=DataVisualization;; |
| 950 | *) type=;; |
981 | *) type=;; |
| 951 | esac |
982 | esac |
| 952 | type="Science;${type}" |
983 | type="Education;Science;${type}" |
| 953 | ;; |
984 | ;; |
| 954 | |
985 | |
| 955 | sys) |
986 | sys) |
| 956 | type="System" |
987 | type="System" |
| 957 | ;; |
988 | ;; |
| … | |
… | |
| 959 | www) |
990 | www) |
| 960 | case ${catmin} in |
991 | case ${catmin} in |
| 961 | client) type=WebBrowser;; |
992 | client) type=WebBrowser;; |
| 962 | *) type=;; |
993 | *) type=;; |
| 963 | esac |
994 | esac |
| 964 | type="Network" |
995 | type="Network;${type}" |
| 965 | ;; |
996 | ;; |
| 966 | |
997 | |
| 967 | *) |
998 | *) |
| 968 | type= |
999 | type= |
| 969 | ;; |
1000 | ;; |
| … | |
… | |
| 974 | else |
1005 | else |
| 975 | local desktop_name="${PN}-${SLOT}" |
1006 | local desktop_name="${PN}-${SLOT}" |
| 976 | fi |
1007 | fi |
| 977 | local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop" |
1008 | local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop" |
| 978 | #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop |
1009 | #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop |
|
|
1010 | |
|
|
1011 | # Don't append another ";" when a valid category value is provided. |
|
|
1012 | type=${type%;}${type:+;} |
|
|
1013 | |
|
|
1014 | eshopts_push -s extglob |
|
|
1015 | if [[ -n ${icon} && ${icon} != /* && ${icon} == *.@(xpm|png|svg) ]]; then |
|
|
1016 | ewarn "As described in the Icon Theme Specification, icon file extensions are not" |
|
|
1017 | ewarn "allowed in .desktop files if the value is not an absolute path." |
|
|
1018 | icon=${icon%.@(xpm|png|svg)} |
|
|
1019 | fi |
|
|
1020 | eshopts_pop |
| 979 | |
1021 | |
| 980 | cat <<-EOF > "${desktop}" |
1022 | cat <<-EOF > "${desktop}" |
| 981 | [Desktop Entry] |
1023 | [Desktop Entry] |
| 982 | Name=${name} |
1024 | Name=${name} |
| 983 | Type=Application |
1025 | Type=Application |
| 984 | Comment=${DESCRIPTION} |
1026 | Comment=${DESCRIPTION} |
| 985 | Exec=${exec} |
1027 | Exec=${exec} |
| 986 | TryExec=${exec%% *} |
1028 | TryExec=${exec%% *} |
| 987 | Icon=${icon} |
1029 | Icon=${icon} |
| 988 | Categories=${type}; |
1030 | Categories=${type} |
| 989 | EOF |
1031 | EOF |
| 990 | |
1032 | |
| 991 | [[ ${path} ]] && echo "Path=${path}" >> "${desktop}" |
1033 | [[ ${path} ]] && echo "Path=${path}" >> "${desktop}" |
| 992 | |
1034 | |
| 993 | ( |
1035 | ( |
| … | |
… | |
| 1742 | } |
1784 | } |
| 1743 | |
1785 | |
| 1744 | # @FUNCTION: built_with_use |
1786 | # @FUNCTION: built_with_use |
| 1745 | # @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> |
1787 | # @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> |
| 1746 | # @DESCRIPTION: |
1788 | # @DESCRIPTION: |
|
|
1789 | # |
|
|
1790 | # Deprecated: Use EAPI 2 use deps in DEPEND|RDEPEND and with has_version calls. |
|
|
1791 | # |
| 1747 | # A temporary hack until portage properly supports DEPENDing on USE |
1792 | # A temporary hack until portage properly supports DEPENDing on USE |
| 1748 | # flags being enabled in packages. This will check to see if the specified |
1793 | # flags being enabled in packages. This will check to see if the specified |
| 1749 | # DEPEND atom was built with the specified list of USE flags. The |
1794 | # DEPEND atom was built with the specified list of USE flags. The |
| 1750 | # --missing option controls the behavior if called on a package that does |
1795 | # --missing option controls the behavior if called on a package that does |
| 1751 | # not actually support the defined USE flags (aka listed in IUSE). |
1796 | # not actually support the defined USE flags (aka listed in IUSE). |