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