dev-libs/libusb: stable 1.0.21 for sparc, bug #630342
[gentoo.git] / eclass / bitcoincore.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4 # @ECLASS: bitcoincore.eclass
5 # @MAINTAINER:
6 # Luke Dashjr <luke_gentoo_bitcoin@dashjr.org>
7 # @BLURB: common code for Bitcoin Core ebuilds
8 # @DESCRIPTION:
9 # This eclass is used in Bitcoin Core ebuilds (bitcoin-qt, bitcoind,
10 # libbitcoinconsensus) to provide a single common place for the common ebuild
11 # stuff.
12 #
13 # The eclass provides all common dependencies as well as common use flags.
14
15 has "${EAPI:-0}" 5 || die "EAPI=${EAPI} not supported"
16
17 if [[ ! ${_BITCOINCORE_ECLASS} ]]; then
18
19 in_bcc_iuse() {
20         local liuse=( ${BITCOINCORE_IUSE} )
21         has "${1}" "${liuse[@]#[+-]}"
22 }
23
24 in_bcc_policy() {
25         local liuse=( ${BITCOINCORE_POLICY_PATCHES} )
26         has "${1}" "${liuse[@]#[+-]}"
27 }
28
29 DB_VER="4.8"
30 inherit autotools db-use eutils
31
32 if [ -z "$BITCOINCORE_COMMITHASH" ]; then
33         inherit git-2
34 fi
35
36 fi
37
38 EXPORT_FUNCTIONS src_prepare src_test src_install
39
40 if in_bcc_iuse ljr || in_bcc_iuse knots || in_bcc_iuse 1stclassmsg || in_bcc_iuse zeromq || [ -n "$BITCOINCORE_POLICY_PATCHES" ]; then
41         EXPORT_FUNCTIONS pkg_pretend
42 fi
43
44 if [[ ! ${_BITCOINCORE_ECLASS} ]]; then
45
46 # @ECLASS-VARIABLE: BITCOINCORE_COMMITHASH
47 # @DESCRIPTION:
48 # Set this variable before the inherit line, to the upstream commit hash.
49
50 # @ECLASS-VARIABLE: BITCOINCORE_IUSE
51 # @DESCRIPTION:
52 # Set this variable before the inherit line, to the USE flags supported.
53
54 # @ECLASS-VARIABLE: BITCOINCORE_LJR_DATE
55 # @DESCRIPTION:
56 # Set this variable before the inherit line, to the datestamp of the Knots
57 # patchset.
58
59 # @ECLASS-VARIABLE: BITCOINCORE_POLICY_PATCHES
60 # @DESCRIPTION:
61 # Set this variable before the inherit line, to a space-delimited list of
62 # supported policies.
63
64 MyPV="${PV/_/}"
65 MyPN="bitcoin"
66 MyP="${MyPN}-${MyPV}"
67
68 # These are expected to change in future versions
69 DOCS="${DOCS} doc/README.md doc/release-notes.md"
70 OPENSSL_DEPEND="dev-libs/openssl:0[-bindist]"
71 WALLET_DEPEND="sys-libs/db:$(db_ver_to_slot "${DB_VER}")[cxx]"
72 LIBEVENT_DEPEND=""
73 UNIVALUE_DEPEND=""
74 BITCOINCORE_LJR_NAME=ljr
75 BITCOINCORE_KNOTS_USE=knots
76 [ -n "${BITCOINCORE_LJR_PV}" ] || BITCOINCORE_LJR_PV="${PV}"
77
78 case "${PV}" in
79 0.13*)
80         BITCOINCORE_MINOR=$(get_version_component_range 2)
81         IUSE="${IUSE} libressl"
82         OPENSSL_DEPEND="!libressl? ( dev-libs/openssl:0[-bindist] ) libressl? ( dev-libs/libressl )"
83         if in_bcc_iuse libevent; then
84                 LIBEVENT_DEPEND="libevent? ( dev-libs/libevent )"
85         else
86                 LIBEVENT_DEPEND="dev-libs/libevent"
87         fi
88         LIBSECP256K1_DEPEND="=dev-libs/libsecp256k1-0.0.0_pre20151118[recovery]"
89         UNIVALUE_DEPEND="dev-libs/univalue"
90         BITCOINCORE_LJR_NAME=knots
91         if in_bcc_iuse ljr; then
92                 BITCOINCORE_KNOTS_USE=ljr
93         fi
94         if in_bcc_policy spamfilter; then
95                 REQUIRED_USE="${REQUIRED_USE} bitcoin_policy_spamfilter? ( ${BITCOINCORE_KNOTS_USE} )"
96         fi
97         ;;
98 9999*)
99         BITCOINCORE_MINOR=9999
100         BITCOINCORE_SERIES="9999"
101         LIBEVENT_DEPEND="dev-libs/libevent"
102         LIBSECP256K1_DEPEND=">dev-libs/libsecp256k1-0.0.0_pre20150422"
103         UNIVALUE_DEPEND="dev-libs/univalue"
104         ;;
105 *)
106         die "Unrecognised version"
107         ;;
108 esac
109
110 [ -n "${BITCOINCORE_SERIES}" ] || BITCOINCORE_SERIES="0.${BITCOINCORE_MINOR}.x"
111
112 LJR_PV() {
113         local testsfx=
114         if [ -n "${BITCOINCORE_LJR_PREV}" ]; then
115                 if [ "$1" = "dir" ]; then
116                         testsfx="/test/${BITCOINCORE_LJR_PREV}"
117                 else
118                         testsfx=".${BITCOINCORE_LJR_PREV}"
119                 fi
120         fi
121         echo "${BITCOINCORE_LJR_PV}.${BITCOINCORE_LJR_NAME}${BITCOINCORE_LJR_DATE}${testsfx}"
122 }
123 LJR_PATCHDIR="${MyPN}-$(LJR_PV ljr).patches"
124 LJR_PATCH() { echo "${WORKDIR}/${LJR_PATCHDIR}/${MyPN}-$(LJR_PV ljr).$@.patch"; }
125 LJR_PATCH_DESC="http://luke.dashjr.org/programs/${MyPN}/files/${MyPN}d/luke-jr/${BITCOINCORE_SERIES}/$(LJR_PV ljr)/${MyPN}-$(LJR_PV ljr).desc.txt"
126 if [ "$BITCOINCORE_MINOR" -ge 12 ]; then
127         LJR_PATCH_DESC="http://bitcoinknots.org/files/${BITCOINCORE_SERIES}/$(LJR_PV dir)/${MyPN}-$(LJR_PV).desc.html"
128 fi
129
130 HOMEPAGE="http://bitcoincore.org/"
131
132 if [ -z "$BITCOINCORE_COMMITHASH" ]; then
133         EGIT_PROJECT='bitcoin'
134         EGIT_REPO_URI="https://github.com/bitcoin/bitcoin.git"
135 else
136         SRC_URI="https://github.com/${MyPN}/${MyPN}/archive/${BITCOINCORE_COMMITHASH}.tar.gz -> ${MyPN}-v${PV}${BITCOINCORE_SRC_SUFFIX}.tgz"
137         if [ -z "${BITCOINCORE_NO_SYSLIBS}" ]; then
138                 SRC_URI="${SRC_URI} http://bitcoinknots.org/files/${BITCOINCORE_SERIES}/$(LJR_PV dir)/${LJR_PATCHDIR}.txz -> ${LJR_PATCHDIR}.tar.xz"
139         fi
140         if in_bcc_iuse addrindex; then
141                 SRC_URI="${SRC_URI} addrindex? ( https://github.com/btcdrak/bitcoin/compare/${BITCOINCORE_ADDRINDEX_DIFF}.diff -> ${BITCOINCORE_ADDRINDEX_PATCHFILE} )"
142         fi
143         if in_bcc_iuse xt; then
144                 BITCOINXT_PATCHFILE="${MyPN}xt-v${PV}.patch"
145                 SRC_URI="${SRC_URI} xt? ( https://github.com/bitcoinxt/bitcoinxt/compare/${BITCOINCORE_XT_DIFF}.diff -> ${BITCOINXT_PATCHFILE} )"
146         fi
147         if in_bcc_policy rbf && [ -n "${BITCOINCORE_RBF_DIFF}" ]; then
148                 SRC_URI="${SRC_URI} bitcoin_policy_rbf? ( https://github.com/petertodd/bitcoin/compare/${BITCOINCORE_RBF_DIFF}.diff -> ${BITCOINCORE_RBF_PATCHFILE} )"
149         fi
150         S="${WORKDIR}/${MyPN}-${BITCOINCORE_COMMITHASH}"
151 fi
152
153 bitcoincore_policy_iuse() {
154         local mypolicy iuse_def new_BITCOINCORE_IUSE=
155         for mypolicy in ${BITCOINCORE_POLICY_PATCHES}; do
156                 if [[ "${mypolicy:0:1}" =~ ^[+-] ]]; then
157                         iuse_def=${mypolicy:0:1}
158                         mypolicy="${mypolicy:1}"
159                 else
160                         iuse_def=
161                 fi
162                 new_BITCOINCORE_IUSE="$new_BITCOINCORE_IUSE ${iuse_def}bitcoin_policy_${mypolicy}"
163         done
164         echo $new_BITCOINCORE_IUSE
165 }
166 IUSE="$IUSE $BITCOINCORE_IUSE $(bitcoincore_policy_iuse)"
167 if in_bcc_policy rbf && in_bcc_iuse xt; then
168         REQUIRED_USE="${REQUIRED_USE} bitcoin_policy_rbf? ( !xt )"
169 fi
170
171 BITCOINCORE_COMMON_DEPEND="
172         ${OPENSSL_DEPEND}
173 "
174 if ! has libevent ${BITCOINCORE_NO_DEPEND}; then
175         BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND} ${LIBEVENT_DEPEND}"
176 fi
177 if [ "${BITCOINCORE_NEED_LIBSECP256K1}" = "1" ]; then
178         BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND} $LIBSECP256K1_DEPEND"
179 fi
180 if [ "${PN}" = "libbitcoinconsensus" ]; then
181         DEPEND="$DEPEND ${BITCOINCORE_COMMON_DEPEND}
182                 test? (
183                         ${UNIVALUE_DEPEND}
184                         >=dev-libs/boost-1.52.0[threads(+)]
185                 )
186         "
187 else
188         BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND}
189                 ${UNIVALUE_DEPEND}
190                 >=dev-libs/boost-1.52.0[threads(+)]
191         "
192 fi
193 bitcoincore_common_depend_use() {
194         in_bcc_iuse "$1" || return
195         BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND} $1? ( $2 )"
196 }
197 bitcoincore_common_depend_use upnp net-libs/miniupnpc
198 bitcoincore_common_depend_use wallet "${WALLET_DEPEND}"
199 bitcoincore_common_depend_use zeromq net-libs/zeromq
200 RDEPEND="${RDEPEND} ${BITCOINCORE_COMMON_DEPEND}"
201 DEPEND="${DEPEND} ${BITCOINCORE_COMMON_DEPEND}
202         >=app-shells/bash-4.1
203         sys-apps/sed
204 "
205 if [ "${BITCOINCORE_NEED_LEVELDB}" = "1" ]; then
206         RDEPEND="${RDEPEND} virtual/bitcoin-leveldb"
207 fi
208 if in_bcc_iuse ${BITCOINCORE_KNOTS_USE}; then
209         if [ "${BITCOINCORE_LJR_NAME}" = "knots" ]; then
210                 DEPEND="${DEPEND} ${BITCOINCORE_KNOTS_USE}? ( dev-lang/perl )"
211         fi
212 fi
213
214 bitcoincore_policymsg() {
215         local USEFlag="bitcoin_policy_$1"
216         in_iuse "${USEFlag}" || return
217         if use "${USEFlag}"; then
218                 [ -n "$2" ] && einfo "$2"
219         else
220                 [ -n "$3" ] && einfo "$3"
221         fi
222         bitcoincore_policymsg_flag=true
223 }
224
225 bitcoincore_pkg_pretend() {
226         bitcoincore_policymsg_flag=false
227         if use_if_iuse ${BITCOINCORE_KNOTS_USE} || use_if_iuse 1stclassmsg || use_if_iuse addrindex || use_if_iuse xt || { use_if_iuse zeromq && [ "${BITCOINCORE_MINOR}" -lt 12 ]; }; then
228                 einfo "Extra functionality improvements to Bitcoin Core are enabled."
229                 bitcoincore_policymsg_flag=true
230                 if use_if_iuse addrindex addrindex; then
231                         einfo "Please be aware that the addrindex functionality is known to be unreliable."
232                 fi
233         fi
234         bitcoincore_policymsg cltv \
235                 "CLTV policy is enabled: Your node will recognise and assist OP_CHECKLOCKTIMEVERIFY (BIP65) transactions." \
236                 "CLTV policy is disabled: Your node will not recognise OP_CHECKLOCKTIMEVERIFY (BIP65) transactions."
237         bitcoincore_policymsg cpfp \
238                 "CPFP policy is enabled: If you mine, you will give consideration to child transaction fees to pay for their parents." \
239                 "CPFP policy is disabled: If you mine, you will ignore transactions unless they have sufficient fee themselves, even if child transactions offer a fee to cover their cost."
240         bitcoincore_policymsg dcmp \
241                 "Data Carrier Multi-Push policy is enabled: Your node will assist transactions with at most a single multiple-'push' data carrier output." \
242                 "Data Carrier Multi-Push policy is disabled: Your node will assist transactions with at most a single data carrier output with only a single 'push'."
243         bitcoincore_policymsg rbf \
244                 "Replace By Fee policy is enabled: Your node will preferentially mine and relay transactions paying the highest fee, regardless of receive order." \
245                 "Replace By Fee policy is disabled: Your node will only accept the first transaction seen consuming a conflicting input, regardless of fee offered by later ones."
246         bitcoincore_policymsg spamfilter \
247                 "Enhanced spam filter policy is enabled: Your node will identify notorious spam scripts and avoid assisting them. This may impact your ability to use some services (see link for a list)." \
248                 "Enhanced spam filter policy is disabled: Your node will not be checking for notorious spam scripts, and may assist them."
249         $bitcoincore_policymsg_flag && einfo "For more information on any of the above, see ${LJR_PATCH_DESC}"
250 }
251
252 bitcoincore_predelete_patch() {
253         local patchfile="$1"
254         mkdir -p "${WORKDIR}/pdp"
255         local tmpfile="${WORKDIR}/pdp/${patchfile##*/}"
256         perl -ne '
257                 newline:
258                 if (m[(^diff .* b/(.*)$)]) {
259                         $a = "$1\n";
260                         $f = $2;
261                         $_ = <>;
262                         if (m[^deleted file]) {
263                                 unlink($f) || die;
264                                 while (!m[^diff ]) {
265                                         $_ = <>
266                                 }
267                                 goto newline
268                         } else {
269                                 print($a)
270                         }
271                 }
272                 print
273         ' <"${patchfile}" >"${tmpfile}" || die
274         epatch "${tmpfile}"
275 }
276
277 bitcoincore_prepare() {
278         local mypolicy
279         if [ -n "${BITCOINCORE_NO_SYSLIBS}" ]; then
280                 true
281         elif [ "${PV}" = "9999" ]; then
282                 epatch "${FILESDIR}/${PV}-syslibs.patch"
283         else
284                 epatch "$(LJR_PATCH syslibs)"
285         fi
286         if use_if_iuse ${BITCOINCORE_KNOTS_USE}; then
287                 if [ "${BITCOINCORE_LJR_NAME}" = "knots" ]; then
288                         bitcoincore_predelete_patch "$(LJR_PATCH f)"
289                         bitcoincore_predelete_patch "$(LJR_PATCH branding)"
290                         epatch "$(LJR_PATCH ts)"
291                 else
292                         epatch "$(LJR_PATCH ljrF)"
293                 fi
294         fi
295         if use_if_iuse 1stclassmsg; then
296                 epatch "$(LJR_PATCH 1stclassmsg)"
297         fi
298         if use_if_iuse addrindex; then
299                 epatch "${DISTDIR}/${BITCOINCORE_ADDRINDEX_PATCHFILE}"
300         fi
301         if use_if_iuse xt; then
302                 epatch "${DISTDIR}/${BITCOINXT_PATCHFILE}"
303         fi
304         { use_if_iuse zeromq && [ "${BITCOINCORE_MINOR}" -lt 12 ]; } && epatch "$(LJR_PATCH zeromq)"
305         for mypolicy in ${BITCOINCORE_POLICY_PATCHES}; do
306                 mypolicy="${mypolicy#[-+]}"
307
308                 if [ "${BITCOINCORE_MINOR}" -ge 12 ]; then
309                         case "${mypolicy}" in
310                         rbf)
311                                 use bitcoin_policy_rbf || sed -i 's/\(DEFAULT_ENABLE_REPLACEMENT = \)true/\1false/' src/main.h
312                                 ;;
313                         spamfilter)
314                                 use bitcoin_policy_spamfilter || sed -i 's/\(DEFAULT_SPAMFILTER = \)true/\1false/' src/main.h
315                                 ;;
316                         *)
317                                 die "Unknown policy ${mypolicy}"
318                         esac
319                         continue
320                 fi
321
322                 use bitcoin_policy_${mypolicy} || continue
323                 case "${mypolicy}" in
324                 rbf)
325                         if [ -n "${BITCOINCORE_RBF_PATCHFILE}" ]; then
326                                 epatch "${DISTDIR}/${BITCOINCORE_RBF_PATCHFILE}"
327                         else
328                                 epatch "$(LJR_PATCH ${mypolicy})"
329                         fi
330                         ;;
331                 *)
332                         epatch "$(LJR_PATCH ${mypolicy})"
333                         ;;
334                 esac
335         done
336
337         echo '#!/bin/true' >share/genbuild.sh
338         mkdir -p src/obj
339         echo "#define BUILD_SUFFIX gentoo${PVR#${PV}}" >src/obj/build.h
340 }
341
342 bitcoincore_autoreconf() {
343         eautoreconf
344         rm -r src/leveldb || die
345         rm -r src/secp256k1 || die
346 }
347
348 bitcoincore_src_prepare() {
349          bitcoincore_prepare
350          bitcoincore_autoreconf
351 }
352
353 bitcoincore_conf() {
354         local my_econf=
355         if use_if_iuse upnp; then
356                 my_econf="${my_econf} --with-miniupnpc --enable-upnp-default"
357         else
358                 my_econf="${my_econf} --without-miniupnpc --disable-upnp-default"
359         fi
360         if use_if_iuse test; then
361                 my_econf="${my_econf} --enable-tests"
362         else
363                 my_econf="${my_econf} --disable-tests"
364         fi
365         if use_if_iuse wallet; then
366                 my_econf="${my_econf} --enable-wallet"
367         else
368                 my_econf="${my_econf} --disable-wallet"
369         fi
370         if ! use_if_iuse zeromq; then
371                 # NOTE: Older (pre-0.12) patches would disable ZMQ if --enable-zmq was passed
372                 my_econf="${my_econf} --disable-zmq"
373         fi
374         if [ -z "${BITCOINCORE_NO_SYSLIBS}" ]; then
375                 my_econf="${my_econf} --disable-util-cli --disable-util-tx"
376         else
377                 my_econf="${my_econf} --without-utils"
378         fi
379         # Knots 0.12.0 errors if --with-libevent used for bitcoin{d,-cli}, so only disable it when not wanted
380         if has libevent ${BITCOINCORE_NO_DEPEND} || { in_bcc_iuse libevent && ! use libevent; }; then
381                 my_econf="${my_econf} --without-libevent"
382         fi
383         if [ "${BITCOINCORE_NEED_LEVELDB}" = "1" ]; then
384                 # Passing --with-system-leveldb fails if leveldb is not installed, so only use it for targets that use LevelDB
385                 my_econf="${my_econf} --with-system-leveldb"
386         fi
387         econf \
388                 --disable-bench  \
389                 --disable-ccache \
390                 --disable-static \
391                 --with-system-libsecp256k1  \
392                 --with-system-univalue  \
393                 --without-libs    \
394                 --without-daemon  \
395                 --without-gui     \
396                 ${my_econf}  \
397                 "$@"
398 }
399
400 bitcoincore_src_test() {
401         emake check
402 }
403
404 bitcoincore_src_install() {
405         default
406         [ "${PN}" = "libbitcoinconsensus" ] || rm "${D}/usr/bin/test_bitcoin"
407 }
408
409 _BITCOINCORE_ECLASS=1
410 fi