net-fs/openafs-kernel: remove vulnerable versions
[gentoo.git] / eclass / bitcoincore.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4 #
5 # @ECLASS: bitcoincore.eclass
6 # @MAINTAINER:
7 # Luke Dashjr <luke_gentoo_bitcoin@dashjr.org>
8 # @BLURB: common code for Bitcoin Core ebuilds
9 # @DESCRIPTION:
10 # This eclass is used in Bitcoin Core ebuilds (bitcoin-qt, bitcoind,
11 # libbitcoinconsensus) to provide a single common place for the common ebuild
12 # stuff.
13 #
14 # The eclass provides all common dependencies as well as common use flags.
15
16 has "${EAPI:-0}" 5 || die "EAPI=${EAPI} not supported"
17
18 if [[ ! ${_BITCOINCORE_ECLASS} ]]; then
19
20 in_bcc_iuse() {
21         local liuse=( ${BITCOINCORE_IUSE} )
22         has "${1}" "${liuse[@]#[+-]}"
23 }
24
25 in_bcc_policy() {
26         local liuse=( ${BITCOINCORE_POLICY_PATCHES} )
27         has "${1}" "${liuse[@]#[+-]}"
28 }
29
30 DB_VER="4.8"
31 inherit autotools db-use eutils
32
33 if [ -z "$BITCOINCORE_COMMITHASH" ]; then
34         inherit git-2
35 fi
36
37 fi
38
39 EXPORT_FUNCTIONS src_prepare src_test src_install
40
41 if in_bcc_iuse ljr || in_bcc_iuse 1stclassmsg || in_bcc_iuse zeromq || [ -n "$BITCOINCORE_POLICY_PATCHES" ]; then
42         EXPORT_FUNCTIONS pkg_pretend
43 fi
44
45 if [[ ! ${_BITCOINCORE_ECLASS} ]]; then
46
47 # @ECLASS-VARIABLE: BITCOINCORE_COMMITHASH
48 # @DESCRIPTION:
49 # Set this variable before the inherit line, to the upstream commit hash.
50
51 # @ECLASS-VARIABLE: BITCOINCORE_IUSE
52 # @DESCRIPTION:
53 # Set this variable before the inherit line, to the USE flags supported.
54
55 # @ECLASS-VARIABLE: BITCOINCORE_LJR_DATE
56 # @DESCRIPTION:
57 # Set this variable before the inherit line, to the datestamp of the ljr
58 # patchset.
59
60 # @ECLASS-VARIABLE: BITCOINCORE_POLICY_PATCHES
61 # @DESCRIPTION:
62 # Set this variable before the inherit line, to a space-delimited list of
63 # supported policies.
64
65 MyPV="${PV/_/}"
66 MyPN="bitcoin"
67 MyP="${MyPN}-${MyPV}"
68
69 # These are expected to change in future versions
70 DOCS="${DOCS} doc/README.md doc/release-notes.md"
71 OPENSSL_DEPEND="dev-libs/openssl:0[-bindist]"
72 WALLET_DEPEND="sys-libs/db:$(db_ver_to_slot "${DB_VER}")[cxx]"
73 [ -n "${BITCOINCORE_LJR_PV}" ] || BITCOINCORE_LJR_PV="${PV}"
74
75 case "${PV}" in
76 0.10*)
77         BITCOINCORE_SERIES="0.10.x"
78         LIBSECP256K1_DEPEND="=dev-libs/libsecp256k1-0.0.0_pre20141212"
79         case "${PVR}" in
80         0.10.2)
81                 BITCOINCORE_RBF_DIFF="16f45600c8c372a738ffef544292864256382601...a23678edc70204599299459a206709a00e039db7"
82                 BITCOINCORE_RBF_PATCHFILE="${MyPN}-rbf-v0.10.2.patch"
83                 ;;
84         *)
85                 BITCOINCORE_RBF_DIFF="16f45600c8c372a738ffef544292864256382601...4890416cde655559eba09d3fd6f79db7d0d6314a"
86                 BITCOINCORE_RBF_PATCHFILE="${MyPN}-rbf-v0.10.2-r1.patch"
87                 ;;
88         esac
89         BITCOINCORE_XT_DIFF="047a89831760ff124740fe9f58411d57ee087078...d4084b62c42c38bfe302d712b98909ab26ecce2f"
90         ;;
91 0.11*)
92         BITCOINCORE_SERIES="0.11.x"
93         LIBSECP256K1_DEPEND="=dev-libs/libsecp256k1-0.0.0_pre20150423"
94         # RBF is bundled with ljr patchset since 0.11.1
95         if [ "${PVR}" = "0.11.0" ]; then
96                 BITCOINCORE_RBF_DIFF="5f032c75eefb0fe8ff79ed9595da1112c05f5c4a...660b96d24916b8ef4e0677e5d6162e24e2db447e"
97                 BITCOINCORE_RBF_PATCHFILE="${MyPN}-rbf-v0.11.0rc3.patch"
98         fi
99         ;;
100 9999*)
101         BITCOINCORE_SERIES="9999"
102         LIBSECP256K1_DEPEND=">dev-libs/libsecp256k1-0.0.0_pre20150422"
103         ;;
104 *)
105         die "Unrecognised version"
106         ;;
107 esac
108
109 LJR_PV() { echo "${BITCOINCORE_LJR_PV}.${1}${BITCOINCORE_LJR_DATE}"; }
110 LJR_PATCHDIR="${MyPN}-$(LJR_PV ljr).patches"
111 LJR_PATCH() { echo "${WORKDIR}/${LJR_PATCHDIR}/${MyPN}-$(LJR_PV ljr).$@.patch"; }
112 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"
113
114 HOMEPAGE="https://github.com/bitcoin/bitcoin"
115
116 if [ -z "$BITCOINCORE_COMMITHASH" ]; then
117         EGIT_PROJECT='bitcoin'
118         EGIT_REPO_URI="git://github.com/bitcoin/bitcoin.git https://github.com/bitcoin/bitcoin.git"
119 else
120         SRC_URI="https://github.com/${MyPN}/${MyPN}/archive/${BITCOINCORE_COMMITHASH}.tar.gz -> ${MyPN}-v${PV}${BITCOINCORE_SRC_SUFFIX}.tgz"
121         if [ -z "${BITCOINCORE_NO_SYSLIBS}" ]; then
122                 SRC_URI="${SRC_URI} http://luke.dashjr.org/programs/${MyPN}/files/${MyPN}d/luke-jr/${BITCOINCORE_SERIES}/$(LJR_PV ljr)/${LJR_PATCHDIR}.txz -> ${LJR_PATCHDIR}.tar.xz"
123         fi
124         if in_bcc_iuse xt; then
125                 BITCOINXT_PATCHFILE="${MyPN}xt-v${PV}.patch"
126                 SRC_URI="${SRC_URI} xt? ( https://github.com/bitcoinxt/bitcoinxt/compare/${BITCOINCORE_XT_DIFF}.diff -> ${BITCOINXT_PATCHFILE} )"
127         fi
128         if in_bcc_policy rbf && [ -n "${BITCOINCORE_RBF_DIFF}" ]; then
129                 SRC_URI="${SRC_URI} bitcoin_policy_rbf? ( https://github.com/petertodd/bitcoin/compare/${BITCOINCORE_RBF_DIFF}.diff -> ${BITCOINCORE_RBF_PATCHFILE} )"
130         fi
131         S="${WORKDIR}/${MyPN}-${BITCOINCORE_COMMITHASH}"
132 fi
133
134 bitcoincore_policy_iuse() {
135         local mypolicy iuse_def new_BITCOINCORE_IUSE=
136         for mypolicy in ${BITCOINCORE_POLICY_PATCHES}; do
137                 if [[ "${mypolicy:0:1}" =~ ^[+-] ]]; then
138                         iuse_def=${mypolicy:0:1}
139                         mypolicy="${mypolicy:1}"
140                 else
141                         iuse_def=
142                 fi
143                 new_BITCOINCORE_IUSE="$new_BITCOINCORE_IUSE ${iuse_def}bitcoin_policy_${mypolicy}"
144         done
145         echo $new_BITCOINCORE_IUSE
146 }
147 IUSE="$IUSE $BITCOINCORE_IUSE $(bitcoincore_policy_iuse)"
148 if in_bcc_policy rbf && in_bcc_iuse xt; then
149         REQUIRED_USE="${REQUIRED_USE} bitcoin_policy_rbf? ( !xt )"
150 fi
151
152 BITCOINCORE_COMMON_DEPEND="
153         ${OPENSSL_DEPEND}
154 "
155 if [ "${BITCOINCORE_NEED_LIBSECP256K1}" = "1" ]; then
156         BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND} $LIBSECP256K1_DEPEND"
157 fi
158 if [ "${PN}" != "libbitcoinconsensus" ]; then
159         BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND} >=dev-libs/boost-1.52.0[threads(+)]"
160 fi
161 bitcoincore_common_depend_use() {
162         in_bcc_iuse "$1" || return
163         BITCOINCORE_COMMON_DEPEND="${BITCOINCORE_COMMON_DEPEND} $1? ( $2 )"
164 }
165 bitcoincore_common_depend_use upnp net-libs/miniupnpc
166 bitcoincore_common_depend_use wallet "${WALLET_DEPEND}"
167 bitcoincore_common_depend_use zeromq net-libs/zeromq
168 RDEPEND="${RDEPEND} ${BITCOINCORE_COMMON_DEPEND}"
169 DEPEND="${DEPEND} ${BITCOINCORE_COMMON_DEPEND}
170         >=app-shells/bash-4.1
171         sys-apps/sed
172 "
173 if [ "${BITCOINCORE_NEED_LEVELDB}" = "1" ]; then
174         RDEPEND="${RDEPEND} virtual/bitcoin-leveldb"
175 fi
176 if in_bcc_iuse ljr && [ "$BITCOINCORE_SERIES" = "0.10.x" ]; then
177         DEPEND="${DEPEND} ljr? ( dev-vcs/git )"
178 fi
179
180 bitcoincore_policymsg() {
181         local USEFlag="bitcoin_policy_$1"
182         in_iuse "${USEFlag}" || return
183         if use "${USEFlag}"; then
184                 [ -n "$2" ] && einfo "$2"
185         else
186                 [ -n "$3" ] && einfo "$3"
187         fi
188         bitcoincore_policymsg_flag=true
189 }
190
191 bitcoincore_pkg_pretend() {
192         bitcoincore_policymsg_flag=false
193         if use_if_iuse ljr || use_if_iuse 1stclassmsg || use_if_iuse xt || use_if_iuse zeromq; then
194                 einfo "Extra functionality improvements to Bitcoin Core are enabled."
195                 bitcoincore_policymsg_flag=true
196         fi
197         bitcoincore_policymsg cltv \
198                 "CLTV policy is enabled: Your node will recognise and assist OP_CHECKLOCKTIMEVERIFY (BIP65) transactions." \
199                 "CLTV policy is disabled: Your node will not recognise OP_CHECKLOCKTIMEVERIFY (BIP65) transactions."
200         bitcoincore_policymsg cpfp \
201                 "CPFP policy is enabled: If you mine, you will give consideration to child transaction fees to pay for their parents." \
202                 "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."
203         bitcoincore_policymsg dcmp \
204                 "Data Carrier Multi-Push policy is enabled: Your node will assist transactions with at most a single multiple-'push' data carrier output." \
205                 "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'."
206         bitcoincore_policymsg rbf \
207                 "Replace By Fee policy is enabled: Your node will preferentially mine and relay transactions paying the highest fee, regardless of receive order." \
208                 "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."
209         bitcoincore_policymsg spamfilter \
210                 "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)." \
211                 "Enhanced spam filter policy is disabled: Your node will not be checking for notorious spam scripts, and may assist them."
212         $bitcoincore_policymsg_flag && einfo "For more information on any of the above, see ${LJR_PATCH_DESC}"
213 }
214
215 bitcoincore_prepare() {
216         local mypolicy
217         if [ -n "${BITCOINCORE_NO_SYSLIBS}" ]; then
218                 true
219         elif [ "${PV}" = "9999" ]; then
220                 epatch "${FILESDIR}/${PV}-syslibs.patch"
221         else
222                 epatch "$(LJR_PATCH syslibs)"
223         fi
224         if use_if_iuse ljr; then
225                 if [ "${BITCOINCORE_SERIES}" = "0.10.x" ]; then
226                         # Regular epatch won't work with binary files
227                         local patchfile="$(LJR_PATCH ljrF)"
228                         einfo "Applying ${patchfile##*/} ..."
229                         git apply --whitespace=nowarn "${patchfile}" || die
230                 else
231                         epatch "$(LJR_PATCH ljrF)"
232                 fi
233         fi
234         if use_if_iuse 1stclassmsg; then
235                 epatch "$(LJR_PATCH 1stclassmsg)"
236         fi
237         if use_if_iuse xt; then
238                 epatch "${DISTDIR}/${BITCOINXT_PATCHFILE}"
239         fi
240         use_if_iuse zeromq && epatch "$(LJR_PATCH zeromq)"
241         for mypolicy in ${BITCOINCORE_POLICY_PATCHES}; do
242                 mypolicy="${mypolicy#[-+]}"
243                 use bitcoin_policy_${mypolicy} || continue
244                 case "${mypolicy}" in
245                 rbf)
246                         if [ -n "${BITCOINCORE_RBF_PATCHFILE}" ]; then
247                                 epatch "${DISTDIR}/${BITCOINCORE_RBF_PATCHFILE}"
248                         else
249                                 epatch "$(LJR_PATCH ${mypolicy})"
250                         fi
251                         ;;
252                 *)
253                         epatch "$(LJR_PATCH ${mypolicy})"
254                         ;;
255                 esac
256         done
257 }
258
259 bitcoincore_autoreconf() {
260         eautoreconf
261         rm -r src/leveldb || die
262         rm -r src/secp256k1 || die
263 }
264
265 bitcoincore_src_prepare() {
266          bitcoincore_prepare
267          bitcoincore_autoreconf
268 }
269
270 bitcoincore_conf() {
271         local my_econf=
272         if use_if_iuse upnp; then
273                 my_econf="${my_econf} --with-miniupnpc --enable-upnp-default"
274         else
275                 my_econf="${my_econf} --without-miniupnpc --disable-upnp-default"
276         fi
277         if use_if_iuse test; then
278                 my_econf="${my_econf} --enable-tests"
279         else
280                 my_econf="${my_econf} --disable-tests"
281         fi
282         if use_if_iuse wallet; then
283                 my_econf="${my_econf} --enable-wallet"
284         else
285                 my_econf="${my_econf} --disable-wallet"
286         fi
287         if [ -z "${BITCOINCORE_NO_SYSLIBS}" ]; then
288                 my_econf="${my_econf} --disable-util-cli --disable-util-tx"
289         else
290                 my_econf="${my_econf} --without-utils"
291         fi
292         if [ "${BITCOINCORE_NEED_LEVELDB}" = "1" ]; then
293                 # Passing --with-system-leveldb fails if leveldb is not installed, so only use it for targets that use LevelDB
294                 my_econf="${my_econf} --with-system-leveldb"
295         fi
296         econf \
297                 --disable-ccache \
298                 --disable-static \
299                 --with-system-libsecp256k1  \
300                 --without-libs    \
301                 --without-daemon  \
302                 --without-gui     \
303                 ${my_econf}  \
304                 "$@"
305 }
306
307 bitcoincore_src_test() {
308         emake check
309 }
310
311 bitcoincore_src_install() {
312         default
313         [ "${PN}" = "libbitcoinconsensus" ] || rm "${D}/usr/bin/test_bitcoin"
314 }
315
316 _BITCOINCORE_ECLASS=1
317 fi