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