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-07-28 12:37:10 -07:00
h_and_a_dir=$($root_dir/platform/os.sh h_and_a_dir)
2015-07-28 07:51:39 -07:00
depends_dir=$($root_dir/platform/os.sh depends_dir)
2015-07-28 12:37:10 -07:00
os_dir=$(${root_dir}/platform/os.sh osdir)
host=$(${root_dir}/platform/os.sh host)
btc_dir="${root_dir}/libbitcoind"
2015-07-28 15:13:14 -07:00
ext=$($root_dir/platform/os.sh ext)
2015-07-31 12:53:04 -07:00
export CPPFLAGS="-I${h_and_a_dir}/include/boost -I${h_and_a_dir}/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include -L${h_and_a_dir}/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-07-28 12:37:10 -07:00
boost_files_count=`find "${h_and_a_dir}"/lib -iname "libboost_*-mt.a" | wc -l | xargs`
db_files_count=`find "${h_and_a_dir}"/lib -iname "libdb*.a" | wc -l | xargs`
should_rebuild=false
if [[ "${boost_files_count}" -lt 5 || ( "${db_files_count}" -lt 1 && "${test}" = true ) ]]; then
should_rebuild=true
fi
if [ "${should_rebuild}" = true ]; then
if [ "${test}" = true ]; then
2015-07-31 12:53:04 -07:00
make HOST=${host} NO_QT=1 NO_UPNP=1
2015-07-28 12:37:10 -07:00
else
2015-07-31 12:53:04 -07:00
make HOST=${host} NO_QT=1 NO_WALLET=1 NO_UPNP=1
2015-07-28 12:37:10 -07:00
fi
2015-07-27 14:39:20 -07:00
else
2015-07-28 12:37:10 -07:00
echo "Looks like libs are already built, so we won't rebuild them. Incidentally, we found: ${boost_files_count} boost libraries and: ${db_files_count} Berkeley DB libraries and you have test mode set to: ${test}"
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-08-04 11:18:45 -07:00
patch_sha="${root_dir}"/etc/patch_sha.txt
2015-07-31 12:53:04 -07:00
last_patch_file_sha=
if [ -e "${patch_sha}" ]; then
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-07-28 15:13:14 -07:00
shared_file_built=true
fi
if [ "${shared_file_built}" = false ]; then
2015-07-31 12:53:04 -07:00
mac_response=$($root_dir/platform/os.sh mac_dependencies)
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
rm -f "${os_dir}/libbitcoind.*"
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-07-28 15:13:14 -07:00
boost_libdir="--with-boost-libdir=${h_and_a_dir}/lib"
2015-07-28 07:51:39 -07:00
2015-07-28 15:13:14 -07:00
full_options="${options} ${boost_libdir} --prefix=${os_dir}"
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..."
echo -n `shasum -a 256 "${root_dir}"/etc/bitcoin.patch | awk '{print $1}'` > "${root_dir}"/etc/patch_sha.txt
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
2014-12-06 17:18:12 -08:00