Skip to content

Commit 4122112

Browse files
committed
Merge #11702: [build] Add a script for installing db4
6e4cdd6 [docs] Add reference to install_db4.sh in OS X build instructions (James O'Beirne) af9103e [build] Add a script for installing db4 (James O'Beirne) Pull request description: Instead of maintaining rote instructions for building BerkeleyDB in `doc/build-{unix,openbsd}.md`, reference a script that does the same thing and can be called from unanticipated contexts, e.g. Docker builds. The script was written with portability in mind, though I haven't tested it on openbsd. I wasn't sure if we wanted to create a separate directory for this sort of thing (e.g. `contrib/install`) so I just stuck it in `contrib/`; happy to move it around if anyone has another preference. Tree-SHA512: d2fc83c065d083458c448e6041e5e9ef67f8165974925560a83881d22d1e9448ea3dd4f7a38196800a8cd6dcf206208a2d6d12417bfe094902d4754e4ca67f18
2 parents 99bc0b4 + 6e4cdd6 commit 4122112

File tree

5 files changed

+117
-43
lines changed

5 files changed

+117
-43
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ DIST_CONTRIB = $(top_srcdir)/contrib/bitcoin-cli.bash-completion \
4242
$(top_srcdir)/contrib/bitcoin-tx.bash-completion \
4343
$(top_srcdir)/contrib/bitcoind.bash-completion \
4444
$(top_srcdir)/contrib/init \
45+
$(top_srcdir)/contrib/install_db4.sh \
4546
$(top_srcdir)/contrib/rpm
4647
DIST_SHARE = \
4748
$(top_srcdir)/share/genbuild.sh \

contrib/install_db4.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/sh
2+
3+
# Install libdb4.8 (Berkeley DB).
4+
5+
set -e
6+
7+
if [ -z "${1}" ]; then
8+
echo "Usage: ./install_db4.sh <base-dir> [<extra-bdb-configure-flag> ...]"
9+
echo
10+
echo "Must specify a single argument: the directory in which db5 will be built."
11+
echo "This is probably \`pwd\` if you're at the root of the bitcoin repository."
12+
exit 1
13+
fi
14+
15+
expand_path() {
16+
echo "$(cd "${1}" && pwd -P)"
17+
}
18+
19+
BDB_PREFIX="$(expand_path ${1})/db4"; shift;
20+
BDB_EXTRA_CONFIGURE_FLAGS="${@}"
21+
BDB_VERSION='db-4.8.30.NC'
22+
BDB_HASH='12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef'
23+
BDB_URL="https://download.oracle.com/berkeley-db/${BDB_VERSION}.tar.gz"
24+
25+
check_exists() {
26+
which "$1" >/dev/null 2>&1
27+
}
28+
29+
sha256_check() {
30+
# Args: <sha256_hash> <filename>
31+
#
32+
if check_exists sha256sum; then
33+
echo "${1} ${2}" | sha256sum -c
34+
elif check_exists sha256; then
35+
echo "${1} ${2}" | sha256 -c
36+
else
37+
echo "${1} ${2}" | shasum -a 256 -c
38+
fi
39+
}
40+
41+
http_get() {
42+
# Args: <url> <filename> <sha256_hash>
43+
#
44+
# It's acceptable that we don't require SSL here because we manually verify
45+
# content hashes below.
46+
#
47+
if [ -f "${2}" ]; then
48+
echo "File ${2} already exists; not downloading again"
49+
elif check_exists curl; then
50+
curl --insecure "${1}" -o "${2}"
51+
else
52+
wget --no-check-certificate "${1}" -O "${2}"
53+
fi
54+
55+
sha256_check "${3}" "${2}"
56+
}
57+
58+
mkdir -p "${BDB_PREFIX}"
59+
http_get "${BDB_URL}" "${BDB_VERSION}.tar.gz" "${BDB_HASH}"
60+
tar -xzvf ${BDB_VERSION}.tar.gz -C "$BDB_PREFIX"
61+
cd "${BDB_PREFIX}/${BDB_VERSION}/"
62+
63+
# Apply a patch when building on OS X to make the build work with Xcode.
64+
#
65+
if [ "$(uname)" = "Darwin" ]; then
66+
BDB_OSX_ATOMIC_PATCH_URL='https://raw.githubusercontent.com/narkoleptik/os-x-berkeleydb-patch/0007e2846ae3fc9757849f5277018f4179ad17ef/atomic.patch'
67+
BDB_OSX_ATOMIC_PATCH_HASH='ba0e2b4f53e9cb0ec58f60a979b53b8567b4565f0384886196f1fc1ef111d151'
68+
69+
http_get "${BDB_OSX_ATOMIC_PATCH_URL}" atomic.patch "${BDB_OSX_ATOMIC_PATCH_HASH}"
70+
patch -p1 < atomic.patch
71+
fi
72+
73+
cd build_unix/
74+
75+
"${BDB_PREFIX}/${BDB_VERSION}/dist/configure" \
76+
--enable-cxx --disable-shared --with-pic --prefix="${BDB_PREFIX}" \
77+
"${BDB_EXTRA_CONFIGURE_FLAGS}"
78+
79+
make install
80+
81+
echo
82+
echo "db4 build complete."
83+
echo
84+
echo 'When compiling bitcoind, run `./configure` in the following way:'
85+
echo
86+
echo " export BDB_PREFIX='${BDB_PREFIX}'"
87+
echo ' ./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" ...'

doc/build-openbsd.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,17 @@ The default C++ compiler that comes with OpenBSD 6.2 is g++ 4.2.1. This version
3838

3939
BerkeleyDB is only necessary for the wallet functionality. To skip this, pass `--disable-wallet` to `./configure`.
4040

41-
See "Berkeley DB" in [build-unix.md](build-unix.md#berkeley-db) for instructions on how to build BerkeleyDB 4.8.
42-
You cannot use the BerkeleyDB library from ports, for the same reason as boost above (g++/libstd++ incompatibility).
41+
It is recommended to use Berkeley DB 4.8. You cannot use the BerkeleyDB library
42+
from ports, for the same reason as boost above (g++/libstd++ incompatibility).
43+
If you have to build it yourself, you can use [the installation script included
44+
in contrib/](contrib/install_db4.sh) like so
4345

44-
```bash
45-
# Pick some path to install BDB to, here we create a directory within the bitcoin directory
46-
BITCOIN_ROOT=$(pwd)
47-
BDB_PREFIX="${BITCOIN_ROOT}/db4"
48-
mkdir -p $BDB_PREFIX
49-
50-
# Fetch the source and verify that it is not tampered with
51-
curl -o db-4.8.30.NC.tar.gz 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
52-
echo '12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef db-4.8.30.NC.tar.gz' | sha256 -c
53-
# MUST output: (SHA256) db-4.8.30.NC.tar.gz: OK
54-
tar -xzf db-4.8.30.NC.tar.gz
55-
56-
# Build the library and install to specified prefix
57-
cd db-4.8.30.NC/build_unix/
58-
# Note: Do a static build so that it can be embedded into the executable, instead of having to find a .so at runtime
59-
../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX CC=egcc CXX=eg++ CPP=ecpp
60-
make install # do NOT use -jX, this is broken
46+
```shell
47+
./contrib/install_db4.sh `pwd` CC=egcc CXX=eg++ CPP=ecpp
6148
```
6249

50+
from the root of the repository.
51+
6352
### Resource limits
6453

6554
The standard ulimit restrictions in OpenBSD are very strict:

doc/build-osx.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ If you want to build the disk image with `make deploy` (.dmg / optional), you ne
2626

2727
NOTE: Building with Qt4 is still supported, however, could result in a broken UI. Building with Qt5 is recommended.
2828

29+
Berkeley DB
30+
-----------
31+
It is recommended to use Berkeley DB 4.8. If you have to build it yourself,
32+
you can use [the installation script included in contrib/](contrib/install_db4.sh)
33+
like so
34+
35+
```shell
36+
./contrib/install_db4.sh .
37+
```
38+
39+
from the root of the repository.
40+
41+
**Note**: You only need Berkeley DB if the wallet is enabled (see the section *Disable-Wallet mode* below).
42+
2943
Build Bitcoin Core
3044
------------------------
3145

doc/build-unix.md

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -165,33 +165,16 @@ turned off by default. See the configure options for upnp behavior desired:
165165

166166
Berkeley DB
167167
-----------
168-
It is recommended to use Berkeley DB 4.8. If you have to build it yourself:
168+
It is recommended to use Berkeley DB 4.8. If you have to build it yourself,
169+
you can use [the installation script included in contrib/](contrib/install_db4.sh)
170+
like so
169171

170-
```bash
171-
BITCOIN_ROOT=$(pwd)
172-
173-
# Pick some path to install BDB to, here we create a directory within the bitcoin directory
174-
BDB_PREFIX="${BITCOIN_ROOT}/db4"
175-
mkdir -p $BDB_PREFIX
176-
177-
# Fetch the source and verify that it is not tampered with
178-
wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
179-
echo '12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef db-4.8.30.NC.tar.gz' | sha256sum -c
180-
# -> db-4.8.30.NC.tar.gz: OK
181-
tar -xzvf db-4.8.30.NC.tar.gz
182-
183-
# Build the library and install to our prefix
184-
cd db-4.8.30.NC/build_unix/
185-
# Note: Do a static build so that it can be embedded into the executable, instead of having to find a .so at runtime
186-
../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX
187-
make install
188-
189-
# Configure Bitcoin Core to use our own-built instance of BDB
190-
cd $BITCOIN_ROOT
191-
./autogen.sh
192-
./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" # (other args...)
172+
```shell
173+
./contrib/install_db4.sh `pwd`
193174
```
194175

176+
from the root of the repository.
177+
195178
**Note**: You only need Berkeley DB if the wallet is enabled (see the section *Disable-Wallet mode* below).
196179

197180
Boost

0 commit comments

Comments
 (0)