| 1 | # Copyright 1999-2008 Gentoo Foundation |
1 | # Copyright 1999-2008 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/base.eclass,v 1.35 2008/11/09 15:47:47 loki_val Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/base.eclass,v 1.53 2010/05/27 08:09:33 scarabeus Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: base.eclass |
5 | # @ECLASS: base.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Peter Alfredsen <loki_val@gentoo.org> |
7 | # QA Team <qa@gentoo.org> |
| 8 | # |
8 | # |
| 9 | # Original author Dan Armak <danarmak@gentoo.org> |
9 | # Original author Dan Armak <danarmak@gentoo.org> |
| 10 | # @BLURB: The base eclass defines some default functions and variables. |
10 | # @BLURB: The base eclass defines some default functions and variables. |
| 11 | # @DESCRIPTION: |
11 | # @DESCRIPTION: |
| 12 | # The base eclass defines some default functions and variables. Nearly |
12 | # The base eclass defines some default functions and variables. Nearly |
| 13 | # everything else inherits from here. |
13 | # everything else inherits from here. |
| 14 | # |
|
|
| 15 | # NOTE: You must define EAPI before inheriting from base, or the wrong functions |
|
|
| 16 | # may be exported. |
|
|
| 17 | |
|
|
| 18 | |
14 | |
| 19 | inherit eutils |
15 | inherit eutils |
| 20 | |
16 | |
|
|
17 | BASE_EXPF="src_unpack src_compile src_install" |
| 21 | case "${EAPI:-0}" in |
18 | case "${EAPI:-0}" in |
| 22 | 2) |
19 | 2|3|4) BASE_EXPF+=" src_prepare src_configure" ;; |
| 23 | EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install |
20 | *) ;; |
| 24 | ;; |
|
|
| 25 | *) |
|
|
| 26 | EXPORT_FUNCTIONS src_unpack src_compile src_install |
|
|
| 27 | ;; |
|
|
| 28 | esac |
21 | esac |
| 29 | |
22 | |
| 30 | DESCRIPTION="Based on the $ECLASS eclass" |
23 | EXPORT_FUNCTIONS ${BASE_EXPF} |
|
|
24 | |
|
|
25 | # @ECLASS-VARIABLE: DOCS |
|
|
26 | # @DESCRIPTION: |
|
|
27 | # Array containing documents passed to dodoc command. |
|
|
28 | # |
|
|
29 | # DOCS=( "${S}/doc/document.txt" "${S}/doc/doc_folder/" ) |
|
|
30 | |
|
|
31 | # @ECLASS-VARIABLE: HTML_DOCS |
|
|
32 | # @DESCRIPTION: |
|
|
33 | # Array containing documents passed to dohtml command. |
|
|
34 | # |
|
|
35 | # HTML_DOCS=( "${S}/doc/document.html" "${S}/doc/html_folder/" ) |
|
|
36 | |
|
|
37 | # @ECLASS-VARIABLE: PATCHES |
|
|
38 | # @DESCRIPTION: |
|
|
39 | # PATCHES array variable containing all various patches to be applied. |
|
|
40 | # This variable is expected to be defined in global scope of ebuild. |
|
|
41 | # Make sure to specify the full path. This variable is utilised in |
|
|
42 | # src_unpack/src_prepare phase based on EAPI. |
|
|
43 | # |
|
|
44 | # NOTE: if using patches folders with special file suffixes you have to |
|
|
45 | # define one additional variable EPATCH_SUFFIX="something" |
|
|
46 | # |
|
|
47 | # PATCHES=( "${FILESDIR}/mypatch.patch" "${FILESDIR}/patches_folder/" ) |
|
|
48 | |
| 31 | |
49 | |
| 32 | # @FUNCTION: base_src_unpack |
50 | # @FUNCTION: base_src_unpack |
| 33 | # @USAGE: [ unpack ] [ patch ] [ autopatch ] [ all ] |
|
|
| 34 | # @DESCRIPTION: |
51 | # @DESCRIPTION: |
| 35 | # The base src_unpack function, which is exported. If no argument is given, |
52 | # The base src_unpack function, which is exported. |
| 36 | # "all" is assumed if EAPI!=2, "unpack" if EAPI=2. |
53 | # Calls also src_prepare with eapi older than 2. |
| 37 | base_src_unpack() { |
54 | base_src_unpack() { |
| 38 | |
|
|
| 39 | debug-print-function $FUNCNAME "$@" |
55 | debug-print-function $FUNCNAME "$@" |
| 40 | |
56 | |
| 41 | if [ -z "$1" ] |
57 | pushd "${WORKDIR}" > /dev/null |
| 42 | then |
58 | |
| 43 | case "${EAPI:-0}" in |
59 | [[ -n "${A}" ]] && unpack ${A} |
| 44 | 2) |
60 | has src_prepare ${BASE_EXPF} || base_src_prepare |
| 45 | base_src_util unpack |
61 | |
| 46 | ;; |
62 | popd > /dev/null |
| 47 | *) |
|
|
| 48 | base_src_util all |
|
|
| 49 | ;; |
|
|
| 50 | esac |
|
|
| 51 | else |
|
|
| 52 | base_src_util $@ |
|
|
| 53 | fi |
|
|
| 54 | } |
63 | } |
| 55 | |
64 | |
| 56 | # @FUNCTION: base_src_prepare |
65 | # @FUNCTION: base_src_prepare |
| 57 | # @DESCRIPTION: |
66 | # @DESCRIPTION: |
| 58 | # The base src_prepare function, which is exported when EAPI=2. Performs |
67 | # The base src_prepare function, which is exported |
| 59 | # "base_src_util autopatch". |
68 | # EAPI is greater or equal to 2. Here the PATCHES array is evaluated. |
| 60 | base_src_prepare() { |
69 | base_src_prepare() { |
|
|
70 | debug-print-function $FUNCNAME "$@" |
|
|
71 | debug-print "$FUNCNAME: PATCHES=$PATCHES" |
| 61 | |
72 | |
| 62 | debug-print-function $FUNCNAME "$@" |
73 | local patches_failed=0 |
| 63 | |
74 | |
| 64 | base_src_util autopatch |
75 | pushd "${S}" > /dev/null |
| 65 | } |
76 | if [[ "$(declare -p PATCHES 2>/dev/null 2>&1)" == "declare -a"* ]]; then |
|
|
77 | for x in "${PATCHES[@]}"; do |
|
|
78 | debug-print "$FUNCNAME: applying patch from ${x}" |
|
|
79 | if [[ -d "${x}" ]]; then |
|
|
80 | # Use standardized names and locations with bulk patching |
|
|
81 | # Patch directory is ${WORKDIR}/patch |
|
|
82 | # See epatch() in eutils.eclass for more documentation |
|
|
83 | EPATCH_SUFFIX=${EPATCH_SUFFIX:=patch} |
| 66 | |
84 | |
| 67 | # @FUNCTION: base_src_util |
85 | # in order to preserve normal EPATCH_SOURCE value that can |
| 68 | # @USAGE: [ unpack ] [ patch ] [ autopatch ] [ all ] |
86 | # be used other way than with base eclass store in local |
| 69 | # @DESCRIPTION: |
87 | # variable and restore later |
| 70 | # The base_src_util function is the grunt function for base src_unpack |
88 | oldval=${EPATCH_SOURCE} |
| 71 | # and base src_prepare. |
89 | EPATCH_SOURCE=${x} |
| 72 | base_src_util() { |
90 | EPATCH_FORCE=yes |
|
|
91 | epatch |
|
|
92 | EPATCH_SOURCE=${oldval} |
|
|
93 | elif [[ -f "${x}" ]]; then |
|
|
94 | epatch "${x}" |
|
|
95 | else |
|
|
96 | ewarn "QA: File or directory \"${x}\" does not exist." |
|
|
97 | ewarn "QA: Check your PATCHES array or add missing file/directory." |
|
|
98 | patches_failed=1 |
|
|
99 | fi |
|
|
100 | done |
|
|
101 | [[ ${patches_failed} -eq 1 ]] && die "Some patches failed. See above messages." |
|
|
102 | else |
|
|
103 | for x in ${PATCHES}; do |
|
|
104 | debug-print "$FUNCNAME: patching from ${x}" |
|
|
105 | epatch "${x}" |
|
|
106 | done |
|
|
107 | fi |
| 73 | |
108 | |
| 74 | debug-print-function $FUNCNAME "$@" |
109 | # Apply user patches |
|
|
110 | debug-print "$FUNCNAME: applying user patches" |
|
|
111 | epatch_user |
| 75 | |
112 | |
| 76 | cd "${WORKDIR}" |
113 | popd > /dev/null |
| 77 | |
|
|
| 78 | while [ "$1" ]; do |
|
|
| 79 | |
|
|
| 80 | case $1 in |
|
|
| 81 | unpack) |
|
|
| 82 | debug-print-section unpack |
|
|
| 83 | unpack ${A} |
|
|
| 84 | ;; |
|
|
| 85 | patch) |
|
|
| 86 | debug-print-section patch |
|
|
| 87 | cd "${S}" |
|
|
| 88 | epatch "${FILESDIR}/${P}-gentoo.diff" |
|
|
| 89 | ;; |
|
|
| 90 | autopatch) |
|
|
| 91 | debug-print-section autopatch |
|
|
| 92 | debug-print "$FUNCNAME: autopatch: PATCHES=$PATCHES, PATCHES1=$PATCHES1" |
|
|
| 93 | cd "${S}" |
|
|
| 94 | if [[ ${#PATCHES[@]} -gt 1 ]]; then |
|
|
| 95 | for x in "${PATCHES[@]}"; do |
|
|
| 96 | debug-print "$FUNCNAME: autopatch: patching from ${x}" |
|
|
| 97 | epatch "${x}" |
|
|
| 98 | done |
|
|
| 99 | else |
|
|
| 100 | for x in ${PATCHES} ${PATCHES1}; do |
|
|
| 101 | debug-print "$FUNCNAME: autopatch: patching from ${x}" |
|
|
| 102 | epatch "${x}" |
|
|
| 103 | done |
|
|
| 104 | fi |
|
|
| 105 | ;; |
|
|
| 106 | all) |
|
|
| 107 | debug-print-section all |
|
|
| 108 | base_src_util unpack autopatch |
|
|
| 109 | ;; |
|
|
| 110 | esac |
|
|
| 111 | |
|
|
| 112 | shift |
|
|
| 113 | done |
|
|
| 114 | |
|
|
| 115 | } |
114 | } |
| 116 | |
115 | |
| 117 | # @FUNCTION: base_src_configure |
116 | # @FUNCTION: base_src_configure |
| 118 | # @DESCRIPTION: |
117 | # @DESCRIPTION: |
| 119 | # The base src_prepare function, which is exported when EAPI=2. Performs |
118 | # The base src_configure function, which is exported when |
| 120 | # "base_src_work configure". |
119 | # EAPI is greater or equal to 2. Runs basic econf. |
| 121 | base_src_configure() { |
120 | base_src_configure() { |
| 122 | |
|
|
| 123 | debug-print-function $FUNCNAME "$@" |
121 | debug-print-function $FUNCNAME "$@" |
| 124 | |
122 | |
| 125 | base_src_work configure |
123 | # there is no pushd ${S} so we can override its place where to run |
|
|
124 | [[ -x ${ECONF_SOURCE:-.}/configure ]] && econf "$@" |
| 126 | } |
125 | } |
| 127 | |
126 | |
| 128 | # @FUNCTION: base_src_compile |
127 | # @FUNCTION: base_src_compile |
| 129 | # @USAGE: [ configure ] [ make ] [ all ] |
|
|
| 130 | # @DESCRIPTION: |
128 | # @DESCRIPTION: |
| 131 | # The base src_compile function, which is exported. If no argument is given, |
129 | # The base src_compile function, calls src_configure with |
| 132 | # "all" is assumed if EAPI!=2, "make" if EAPI=2. |
130 | # EAPI older than 2. |
| 133 | base_src_compile() { |
131 | base_src_compile() { |
| 134 | |
|
|
| 135 | debug-print-function $FUNCNAME "$@" |
132 | debug-print-function $FUNCNAME "$@" |
| 136 | |
133 | |
| 137 | if [ -z "$1" ] |
134 | has src_configure ${BASE_EXPF} || base_src_configure |
| 138 | then |
135 | base_src_make "$@" |
| 139 | case "${EAPI:-0}" in |
136 | } |
| 140 | 2) |
137 | |
| 141 | base_src_work make |
138 | # @FUNCTION: base_src_make |
| 142 | ;; |
139 | # @DESCRIPTION: |
| 143 | *) |
140 | # Actual function that runs emake command. |
| 144 | base_src_work all |
141 | base_src_make() { |
| 145 | ;; |
142 | debug-print-function $FUNCNAME "$@" |
| 146 | esac |
143 | |
| 147 | else |
144 | if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then |
| 148 | base_src_work $@ |
145 | emake "$@" || die "died running emake, $FUNCNAME" |
| 149 | fi |
146 | fi |
| 150 | } |
147 | } |
| 151 | |
148 | |
| 152 | # @FUNCTION: base_src_work |
149 | # @FUNCTION: base_src_install |
| 153 | # @USAGE: [ configure ] [ make ] [ all ] |
|
|
| 154 | # @DESCRIPTION: |
150 | # @DESCRIPTION: |
| 155 | # The base_src_work function is the grunt function for base src_configure |
151 | # The base src_install function. Runs make install and |
| 156 | # and base src_compile. |
152 | # installs documents and html documents from DOCS and HTML_DOCS |
| 157 | base_src_work() { |
153 | # arrays. |
| 158 | |
154 | base_src_install() { |
| 159 | debug-print-function $FUNCNAME "$@" |
155 | debug-print-function $FUNCNAME "$@" |
| 160 | |
156 | |
| 161 | cd "${S}" |
157 | emake DESTDIR="${D}" "$@" install || die "died running make install, $FUNCNAME" |
| 162 | |
158 | base_src_install_docs |
| 163 | while [ "$1" ]; do |
|
|
| 164 | |
|
|
| 165 | case $1 in |
|
|
| 166 | configure) |
|
|
| 167 | debug-print-section configure |
|
|
| 168 | econf || die "died running econf, $FUNCNAME:configure" |
|
|
| 169 | ;; |
|
|
| 170 | make) |
|
|
| 171 | debug-print-section make |
|
|
| 172 | emake || die "died running emake, $FUNCNAME:make" |
|
|
| 173 | ;; |
|
|
| 174 | all) |
|
|
| 175 | debug-print-section all |
|
|
| 176 | base_src_work configure make |
|
|
| 177 | ;; |
|
|
| 178 | esac |
|
|
| 179 | |
|
|
| 180 | shift |
|
|
| 181 | done |
|
|
| 182 | |
|
|
| 183 | } |
159 | } |
| 184 | |
160 | |
| 185 | # @FUNCTION: base_src_install |
161 | # @FUNCTION: base_src_install_docs |
| 186 | # @USAGE: [ make ] [ all ] |
|
|
| 187 | # @DESCRIPTION: |
162 | # @DESCRIPTION: |
| 188 | # The base src_install function, which is exported. If no argument is given, |
163 | # Actual function that install documentation from |
| 189 | # "all" is assumed. |
164 | # DOCS and HTML_DOCS arrays. |
| 190 | base_src_install() { |
165 | base_src_install_docs() { |
|
|
166 | debug-print-function $FUNCNAME "$@" |
| 191 | |
167 | |
| 192 | debug-print-function $FUNCNAME "$@" |
168 | local x |
| 193 | [ -z "$1" ] && base_src_install all |
|
|
| 194 | |
169 | |
| 195 | cd "${S}" |
170 | pushd "${S}" > /dev/null |
| 196 | |
171 | |
| 197 | while [ "$1" ]; do |
172 | if [[ "$(declare -p DOCS 2>/dev/null 2>&1)" == "declare -a"* ]]; then |
|
|
173 | for x in "${DOCS[@]}"; do |
|
|
174 | debug-print "$FUNCNAME: docs: creating document from ${x}" |
|
|
175 | dodoc "${x}" || die "dodoc failed" |
|
|
176 | done |
|
|
177 | fi |
|
|
178 | if [[ "$(declare -p HTML_DOCS 2>/dev/null 2>&1)" == "declare -a"* ]]; then |
|
|
179 | for x in "${HTML_DOCS[@]}"; do |
|
|
180 | debug-print "$FUNCNAME: docs: creating html document from ${x}" |
|
|
181 | dohtml -r "${x}" || die "dohtml failed" |
|
|
182 | done |
|
|
183 | fi |
| 198 | |
184 | |
| 199 | case $1 in |
185 | popd > /dev/null |
| 200 | make) |
|
|
| 201 | debug-print-section make |
|
|
| 202 | make DESTDIR="${D}" install || die "died running make install, $FUNCNAME:make" |
|
|
| 203 | ;; |
|
|
| 204 | all) |
|
|
| 205 | debug-print-section all |
|
|
| 206 | base_src_install make |
|
|
| 207 | ;; |
|
|
| 208 | esac |
|
|
| 209 | |
|
|
| 210 | shift |
|
|
| 211 | done |
|
|
| 212 | |
|
|
| 213 | } |
186 | } |