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