2014-12-09 13:29:32 -08:00
|
|
|
#!/bin/bash
|
2014-12-09 13:24:24 -08:00
|
|
|
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."
|
2015-07-20 14:55:49 -07:00
|
|
|
options=`cat ${root_dir}/bin/config_options.sh`
|
2015-08-04 12:49:01 -07:00
|
|
|
depends_dir=$($root_dir/variables.sh depends_dir)
|
|
|
|
host=$(${root_dir}/variables.sh host)
|
2015-07-28 12:37:10 -07:00
|
|
|
btc_dir="${root_dir}/libbitcoind"
|
2015-08-04 12:49:01 -07:00
|
|
|
patch_sha=$($root_dir/variables.sh patch_sha)
|
|
|
|
export CPPFLAGS="-I${depends_dir}/${host}/include/boost -I${depends_dir}/${host}/include -L${depends_dir}/${host}/lib"
|
2015-07-28 12:37:10 -07:00
|
|
|
echo "Using BTC directory: ${btc_dir}"
|
2015-07-28 07:51:39 -07:00
|
|
|
|
|
|
|
cd "${root_dir}"
|
|
|
|
|
2015-07-27 06:54:39 -07:00
|
|
|
build_dependencies () {
|
|
|
|
if [ -d "${btc_dir}" ]; then
|
2015-07-28 12:37:10 -07:00
|
|
|
pushd "${depends_dir}"
|
2015-07-27 06:54:39 -07:00
|
|
|
echo "using host for dependencies: ${host}"
|
2015-08-04 12:49:01 -07:00
|
|
|
if [ "${test}" = true ]; then
|
|
|
|
make HOST=${host} NO_QT=1 NO_UPNP=1
|
2015-07-27 14:39:20 -07:00
|
|
|
else
|
2015-08-04 12:49:01 -07:00
|
|
|
make HOST=${host} NO_QT=1 NO_WALLET=1 NO_UPNP=1
|
2015-07-27 14:39:20 -07:00
|
|
|
fi
|
2015-07-27 06:54:39 -07:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-07-22 09:52:48 -07:00
|
|
|
get_patch_file () {
|
|
|
|
if test -e "${root_dir/PATCH_VERSION}"; then
|
|
|
|
tag=`cat "${root_dir}/PATCH_VERSION" | xargs`
|
|
|
|
else
|
|
|
|
echo "no tag file found, please create it in the root of the project as so: 'echo \"v0.10.2\" > PATCH_VERSION'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
compare_patch () {
|
2015-07-28 12:37:10 -07:00
|
|
|
cd "${btc_dir}"
|
2015-07-22 09:52:48 -07:00
|
|
|
get_patch_file
|
|
|
|
echo "running the diff command from HEAD to ${tag}"
|
2015-07-31 12:53:04 -07:00
|
|
|
git diff ${tag}..HEAD > /tmp/tmp.patch
|
2015-07-22 09:52:48 -07:00
|
|
|
matching_patch=`diff -w /tmp/tmp.patch "${root_dir}/etc/bitcoin.patch"`
|
|
|
|
}
|
2015-07-28 12:37:10 -07:00
|
|
|
|
2015-07-08 11:24:26 -07:00
|
|
|
debug=
|
2015-07-31 08:40:15 -07:00
|
|
|
if [ "${BITCORENODE_ENV}" == "debug" ]; then
|
2015-07-20 14:55:49 -07:00
|
|
|
options=`cat ${root_dir}/bin/config_options_debug.sh`
|
|
|
|
fi
|
|
|
|
|
2015-07-28 12:37:10 -07:00
|
|
|
test=false
|
2015-07-31 08:40:15 -07:00
|
|
|
if [ "${BITCORENODE_ENV}" == "test" ]; then
|
2015-07-27 14:39:20 -07:00
|
|
|
test=true
|
2015-07-20 14:55:49 -07:00
|
|
|
options=`cat ${root_dir}/bin/config_options_test.sh`
|
2014-12-07 00:02:31 -08:00
|
|
|
fi
|
|
|
|
|
2015-07-28 15:13:14 -07:00
|
|
|
patch_file_sha=$(shasum -a 256 "${root_dir}/etc/bitcoin.patch" | awk '{print $1}')
|
2015-07-31 12:53:04 -07:00
|
|
|
last_patch_file_sha=
|
|
|
|
if [ -e "${patch_sha}" ]; then
|
2015-08-04 12:49:01 -07:00
|
|
|
echo "Patch file sha exists, let's see if the patch has changed since last build..."
|
2015-08-04 11:18:45 -07:00
|
|
|
last_patch_file_sha=$(cat "${patch_sha}")
|
2015-07-28 15:13:14 -07:00
|
|
|
fi
|
|
|
|
shared_file_built=false
|
2015-08-04 11:18:45 -07:00
|
|
|
if [ "${last_patch_file_sha}" == "${patch_file_sha}" ]; then
|
2015-08-04 12:49:01 -07:00
|
|
|
echo "Patch file contents matches the sha from the patch file itself, so no reason to rebuild the bindings unless there are no prebuilt bindings."
|
2015-07-28 15:13:14 -07:00
|
|
|
shared_file_built=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${shared_file_built}" = false ]; then
|
2015-08-04 12:49:01 -07:00
|
|
|
echo "Looks like the patch to bitcoin changed since last build -or- this is the first build, so rebuilding libbitcoind itself..."
|
|
|
|
mac_response=$($root_dir/variables.sh mac_dependencies)
|
2015-07-31 12:53:04 -07:00
|
|
|
if [ "${mac_response}" != "" ]; then
|
|
|
|
echo "${mac_response}"
|
|
|
|
exit -1
|
|
|
|
fi
|
2015-07-28 15:13:14 -07:00
|
|
|
only_make=false
|
|
|
|
if [ -d "${btc_dir}" ]; then
|
|
|
|
echo "running compare patch..."
|
|
|
|
compare_patch
|
|
|
|
repatch=false
|
|
|
|
if [[ "${matching_patch}" =~ [^\s\\] ]]; then
|
|
|
|
echo "Warning! libbitcoind is not patched with:\
|
|
|
|
${root_dir}/etc/bitcoin.patch."
|
|
|
|
echo -n "Would you like to remove the current patch, checkout the tag: ${tag} and \
|
2015-07-22 09:52:48 -07:00
|
|
|
apply the current patch from "${root_dir}"/etc/bitcoin.patch? (y/N): "
|
2015-07-31 08:40:15 -07:00
|
|
|
if [ "${BITCORENODE_ASSUME_YES}" = true ]; then
|
2015-07-28 15:13:14 -07:00
|
|
|
input=y
|
|
|
|
echo ""
|
|
|
|
else
|
|
|
|
read input
|
|
|
|
fi
|
|
|
|
if [[ "${input}" =~ ^y|^Y ]]; then
|
|
|
|
repatch=true
|
|
|
|
echo "Removing directory: \"${btc_dir}\" and starting over!"
|
|
|
|
rm -fr "${btc_dir}"
|
|
|
|
fi
|
2015-07-22 09:52:48 -07:00
|
|
|
fi
|
2015-07-28 15:13:14 -07:00
|
|
|
if [ "${repatch}" = false ]; then
|
|
|
|
echo "Running make inside libbitcoind (assuming you've previously patched and configured libbitcoind)..."
|
|
|
|
cd "${btc_dir}"
|
|
|
|
only_make=true
|
2015-07-22 09:52:48 -07:00
|
|
|
fi
|
|
|
|
fi
|
2014-12-06 16:43:53 -08:00
|
|
|
|
2015-07-28 15:13:14 -07:00
|
|
|
if [ "${only_make}" = false ]; then
|
|
|
|
echo "Cloning, patching, and building libbitcoind..."
|
|
|
|
get_patch_file
|
|
|
|
echo "attempting to checkout tag: ${tag} of bitcoin from github..."
|
|
|
|
cd "${root_dir}"
|
|
|
|
git clone --depth 1 --branch "${tag}" https://github.com/bitcoin/bitcoin.git libbitcoind
|
2014-12-06 16:43:53 -08:00
|
|
|
|
2015-07-28 15:13:14 -07:00
|
|
|
cd "${btc_dir}"
|
2015-07-08 15:13:33 -07:00
|
|
|
|
2015-07-28 15:13:14 -07:00
|
|
|
echo '../patch-bitcoin.sh' "${btc_dir}"
|
|
|
|
../bin/patch-bitcoin "${btc_dir}"
|
2015-07-08 11:24:26 -07:00
|
|
|
|
2015-07-28 15:13:14 -07:00
|
|
|
if ! test -d .git; then
|
|
|
|
echo 'Please point this script to an upstream bitcoin git repo.'
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-12-06 16:43:53 -08:00
|
|
|
|
2015-07-28 15:13:14 -07:00
|
|
|
fi
|
|
|
|
build_dependencies
|
|
|
|
echo './autogen.sh'
|
|
|
|
./autogen.sh
|
2015-07-28 07:51:39 -07:00
|
|
|
|
2015-08-04 12:49:01 -07:00
|
|
|
boost_libdir="--with-boost-libdir=${depends_dir}/${host}/lib"
|
2015-07-28 07:51:39 -07:00
|
|
|
|
2015-08-04 12:49:01 -07:00
|
|
|
full_options="${options} ${boost_libdir}"
|
2015-07-28 15:13:14 -07:00
|
|
|
echo "running the configure script with the following options:\n :::[\"${full_options}\"]:::"
|
|
|
|
${full_options}
|
2015-07-28 07:51:39 -07:00
|
|
|
|
2015-07-28 15:13:14 -07:00
|
|
|
echo 'make V=1'
|
|
|
|
make V=1
|
2014-12-06 16:43:53 -08:00
|
|
|
|
2015-08-04 11:18:45 -07:00
|
|
|
echo "Creating the sha marker for the patching in libbitcoind..."
|
2015-08-04 12:49:01 -07:00
|
|
|
echo "Writing patch sha file to: \"${patch_sha}\""
|
|
|
|
echo -n `shasum -a 256 "${root_dir}"/etc/bitcoin.patch | awk '{print $1}'` > "${patch_sha}"
|
2015-07-28 15:13:14 -07:00
|
|
|
echo 'Build finished successfully.'
|
|
|
|
else
|
|
|
|
echo 'Using existing shared library.'
|
2015-07-02 14:13:03 -07:00
|
|
|
fi
|