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