1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: bitcoincore.eclass
6 # Luke Dashjr <luke_gentoo_bitcoin@dashjr.org>
7 # @BLURB: common code for Bitcoin Core ebuilds
9 # This eclass is used in Bitcoin Core ebuilds (bitcoin-qt, bitcoind,
10 # libbitcoinconsensus) to provide a single common place for the common ebuild
13 # The eclass provides all common dependencies as well as common use flags.
15 has "${EAPI:-0}" 5 || die "EAPI=${EAPI} not supported"
17 if [[ ! ${_BITCOINCORE_ECLASS} ]]; then
20 local liuse=( ${BITCOINCORE_IUSE} )
21 has "${1}" "${liuse[@]#[+-]}"
25 local liuse=( ${BITCOINCORE_POLICY_PATCHES} )
26 has "${1}" "${liuse[@]#[+-]}"
30 inherit autotools db-use eutils
32 if [ -z "$BITCOINCORE_COMMITHASH" ]; then
38 EXPORT_FUNCTIONS src_prepare src_test src_install
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
44 if [[ ! ${_BITCOINCORE_ECLASS} ]]; then
46 # @ECLASS-VARIABLE: BITCOINCORE_COMMITHASH
48 # Set this variable before the inherit line, to the upstream commit hash.
50 # @ECLASS-VARIABLE: BITCOINCORE_IUSE
52 # Set this variable before the inherit line, to the USE flags supported.
54 # @ECLASS-VARIABLE: BITCOINCORE_LJR_DATE
56 # Set this variable before the inherit line, to the datestamp of the Knots
59 # @ECLASS-VARIABLE: BITCOINCORE_POLICY_PATCHES
61 # Set this variable before the inherit line, to a space-delimited list of
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]"
74 BITCOINCORE_LJR_NAME=ljr
75 BITCOINCORE_KNOTS_USE=knots
76 [ -n "${BITCOINCORE_LJR_PV}" ] || BITCOINCORE_LJR_PV="${PV}"
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 )"
86 LIBEVENT_DEPEND="dev-libs/libevent"
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
94 if in_bcc_policy spamfilter; then
95 REQUIRED_USE="${REQUIRED_USE} bitcoin_policy_spamfilter? ( ${BITCOINCORE_KNOTS_USE} )"
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"
106 die "Unrecognised version"
110 [ -n "${BITCOINCORE_SERIES}" ] || BITCOINCORE_SERIES="0.${BITCOINCORE_MINOR}.x"
114 if [ -n "${BITCOINCORE_LJR_PREV}" ]; then
115 if [ "$1" = "dir" ]; then
116 testsfx="/test/${BITCOINCORE_LJR_PREV}"
118 testsfx=".${BITCOINCORE_LJR_PREV}"
121 echo "${BITCOINCORE_LJR_PV}.${BITCOINCORE_LJR_NAME}${BITCOINCORE_LJR_DATE}${testsfx}"
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"
130 HOMEPAGE="http://bitcoincore.org/"
132 if [ -z "$BITCOINCORE_COMMITHASH" ]; then
133 EGIT_PROJECT='bitcoin'
134 EGIT_REPO_URI="https://github.com/bitcoin/bitcoin.git"
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"
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} )"
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} )"
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} )"
150 S="${WORKDIR}/${MyPN}-${BITCOINCORE_COMMITHASH}"
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}"
162 new_BITCOINCORE_IUSE="$new_BITCOINCORE_IUSE ${iuse_def}bitcoin_policy_${mypolicy}"
164 echo $new_BITCOINCORE_IUSE
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 )"
171 BITCOINCORE_COMMON_DEPEND="
174 if ! has libevent ${BITCOINCORE_NO_DEPEND}; then
175 BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND} ${LIBEVENT_DEPEND}"
177 if [ "${BITCOINCORE_NEED_LIBSECP256K1}" = "1" ]; then
178 BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND} $LIBSECP256K1_DEPEND"
180 if [ "${PN}" = "libbitcoinconsensus" ]; then
181 DEPEND="$DEPEND ${BITCOINCORE_COMMON_DEPEND}
184 >=dev-libs/boost-1.52.0[threads(+)]
188 BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND}
190 >=dev-libs/boost-1.52.0[threads(+)]
193 bitcoincore_common_depend_use() {
194 in_bcc_iuse "$1" || return
195 BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND} $1? ( $2 )"
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
205 if [ "${BITCOINCORE_NEED_LEVELDB}" = "1" ]; then
206 RDEPEND="${RDEPEND} virtual/bitcoin-leveldb"
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 )"
214 bitcoincore_policymsg() {
215 local USEFlag="bitcoin_policy_$1"
216 in_iuse "${USEFlag}" || return
217 if use "${USEFlag}"; then
218 [ -n "$2" ] && einfo "$2"
220 [ -n "$3" ] && einfo "$3"
222 bitcoincore_policymsg_flag=true
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."
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}"
252 bitcoincore_predelete_patch() {
254 mkdir -p "${WORKDIR}/pdp"
255 local tmpfile="${WORKDIR}/pdp/${patchfile##*/}"
258 if (m[(^diff .* b/(.*)$)]) {
262 if (m[^deleted file]) {
273 ' <"${patchfile}" >"${tmpfile}" || die
277 bitcoincore_prepare() {
279 if [ -n "${BITCOINCORE_NO_SYSLIBS}" ]; then
281 elif [ "${PV}" = "9999" ]; then
282 epatch "${FILESDIR}/${PV}-syslibs.patch"
284 epatch "$(LJR_PATCH syslibs)"
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)"
292 epatch "$(LJR_PATCH ljrF)"
295 if use_if_iuse 1stclassmsg; then
296 epatch "$(LJR_PATCH 1stclassmsg)"
298 if use_if_iuse addrindex; then
299 epatch "${DISTDIR}/${BITCOINCORE_ADDRINDEX_PATCHFILE}"
301 if use_if_iuse xt; then
302 epatch "${DISTDIR}/${BITCOINXT_PATCHFILE}"
304 { use_if_iuse zeromq && [ "${BITCOINCORE_MINOR}" -lt 12 ]; } && epatch "$(LJR_PATCH zeromq)"
305 for mypolicy in ${BITCOINCORE_POLICY_PATCHES}; do
306 mypolicy="${mypolicy#[-+]}"
308 if [ "${BITCOINCORE_MINOR}" -ge 12 ]; then
309 case "${mypolicy}" in
311 use bitcoin_policy_rbf || sed -i 's/\(DEFAULT_ENABLE_REPLACEMENT = \)true/\1false/' src/main.h
314 use bitcoin_policy_spamfilter || sed -i 's/\(DEFAULT_SPAMFILTER = \)true/\1false/' src/main.h
317 die "Unknown policy ${mypolicy}"
322 use bitcoin_policy_${mypolicy} || continue
323 case "${mypolicy}" in
325 if [ -n "${BITCOINCORE_RBF_PATCHFILE}" ]; then
326 epatch "${DISTDIR}/${BITCOINCORE_RBF_PATCHFILE}"
328 epatch "$(LJR_PATCH ${mypolicy})"
332 epatch "$(LJR_PATCH ${mypolicy})"
337 echo '#!/bin/true' >share/genbuild.sh
339 echo "#define BUILD_SUFFIX gentoo${PVR#${PV}}" >src/obj/build.h
342 bitcoincore_autoreconf() {
344 rm -r src/leveldb || die
345 rm -r src/secp256k1 || die
348 bitcoincore_src_prepare() {
350 bitcoincore_autoreconf
355 if use_if_iuse upnp; then
356 my_econf="${my_econf} --with-miniupnpc --enable-upnp-default"
358 my_econf="${my_econf} --without-miniupnpc --disable-upnp-default"
360 if use_if_iuse test; then
361 my_econf="${my_econf} --enable-tests"
363 my_econf="${my_econf} --disable-tests"
365 if use_if_iuse wallet; then
366 my_econf="${my_econf} --enable-wallet"
368 my_econf="${my_econf} --disable-wallet"
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"
374 if [ -z "${BITCOINCORE_NO_SYSLIBS}" ]; then
375 my_econf="${my_econf} --disable-util-cli --disable-util-tx"
377 my_econf="${my_econf} --without-utils"
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"
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"
391 --with-system-libsecp256k1 \
392 --with-system-univalue \
400 bitcoincore_src_test() {
404 bitcoincore_src_install() {
406 [ "${PN}" = "libbitcoinconsensus" ] || rm "${D}/usr/bin/test_bitcoin"
409 _BITCOINCORE_ECLASS=1