updated patch

This commit is contained in:
Chris Kleeschulte 2015-06-08 19:55:25 -04:00
parent 0bd637232b
commit 9d74bf8787
1 changed files with 74 additions and 83 deletions

View File

@ -1,3 +1,28 @@
From 0444112b743602ae2182832603fb9ac603907c9a Mon Sep 17 00:00:00 2001
From: Chris Kleeschulte <chrisk@bitpay.com>
Date: Mon, 1 Jun 2015 13:41:12 -0400
Subject: [PATCH] Applied JJ's patch to v0.10.2
---
Makefile.am | 5 +++++
configure.ac | 31 +++++++++++++++++++++++++--
src/Makefile.am | 19 +++++++++++++++--
src/Makefile.daemon.include | 52 +++++++++++++++++++++++++++++++++++++++++++++
src/bitcoin-main.cpp | 15 +++++++++++++
src/bitcoind.cpp | 22 +------------------
src/bitcoind.h | 25 ++++++++++++++++++++++
src/init.h | 8 +++++++
src/leveldbwrapper.h | 6 ++----
src/rpcdump.cpp | 7 +++---
src/rpcwallet.cpp | 1 +
src/rpcwallet.h | 17 +++++++++++++++
src/wallet.h | 3 +--
13 files changed, 176 insertions(+), 35 deletions(-)
create mode 100644 src/Makefile.daemon.include
create mode 100644 src/bitcoin-main.cpp
create mode 100644 src/bitcoind.h
create mode 100644 src/rpcwallet.h
diff --git a/Makefile.am b/Makefile.am
index b51f477..58241df 100644
--- a/Makefile.am
@ -15,7 +40,7 @@ index b51f477..58241df 100644
-$(MAKE) -C $(top_distdir)/src/leveldb clean
-$(MAKE) -C $(top_distdir)/src/secp256k1 distclean
diff --git a/configure.ac b/configure.ac
index 9814197..3f25415 100644
index 579035f..cd20489 100644
--- a/configure.ac
+++ b/configure.ac
@@ -126,6 +126,12 @@ AC_ARG_ENABLE([reduce-exports],
@ -31,7 +56,7 @@ index 9814197..3f25415 100644
AC_ARG_ENABLE([ccache],
[AS_HELP_STRING([--enable-ccache],
[use ccache for building (default is yes if ccache is found)])],
@@ -387,6 +393,9 @@ fi
@@ -409,6 +415,9 @@ fi
if test x$use_hardening != xno; then
AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
@ -41,7 +66,7 @@ index 9814197..3f25415 100644
AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[
AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[
@@ -400,7 +409,7 @@ if test x$use_hardening != xno; then
@@ -422,7 +431,7 @@ if test x$use_hardening != xno; then
AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"])
AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"])
@ -50,7 +75,7 @@ index 9814197..3f25415 100644
# All windows code is PIC, forcing it on just adds useless compile warnings
AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"])
AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"])
@@ -418,6 +427,17 @@ if test x$use_hardening != xno; then
@@ -440,6 +449,17 @@ if test x$use_hardening != xno; then
OBJCXXFLAGS="$CXXFLAGS"
fi
@ -68,7 +93,7 @@ index 9814197..3f25415 100644
dnl this flag screws up non-darwin gcc even when the check fails. special-case it.
if test x$TARGET_OS = xdarwin; then
AX_CHECK_LINK_FLAG([[-Wl,-dead_strip]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip"])
@@ -463,7 +483,7 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([
@@ -485,7 +505,7 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([
]
)
@ -77,8 +102,8 @@ index 9814197..3f25415 100644
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[RE_CXXFLAGS="-fvisibility=hidden"],
[
if test x$use_reduce_exports = xyes; then
@@ -811,6 +831,13 @@ if test x$build_bitcoin_utils$build_bitcoin_libs$build_bitcoind$bitcoin_enable_q
AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-libs --with-daemon --with-gui or --enable-tests])
@@ -496,6 +516,13 @@ if test x$use_reduce_exports != xno; then
])
fi
+AC_MSG_CHECKING([whether to compile as daemonlib])
@ -88,61 +113,14 @@ index 9814197..3f25415 100644
+ AC_MSG_RESULT([no])
+fi
+
AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
diff --git a/doc/build-unix.md b/doc/build-unix.md
index 8ddee3b..c4274a3 100644
--- a/doc/build-unix.md
+++ b/doc/build-unix.md
@@ -239,3 +239,42 @@ In this case there is no dependency on Berkeley DB 4.8.
Mining is also possible in disable-wallet mode, but only using the `getblocktemplate` RPC
call not `getwork`.
+Compiling bitcoind as a shared object (`libbitcoind.so`)
+--------------------------------------------------------
+
+### Compiling as a library
+
+``` bash
+# ensure clean up
+$ make clean
+
+# create configure file
+$ ./autogen.sh
+
+# configure as a library with -fPIC on all object files
+# use --with-incompatible-bdb if necessary
+# use --prefix=/usr if necessary
+$ ./configure --enable-daemonlib
+
+# build libbitcoind.so
+$ time make
+...
+real 31m33.128s
+user 16m23.930s
+sys 2m52.310s
+```
+
+`--enable-daemonlib` will compile all object files with `-fPIC` (Position
+Independent Code - needed to create a shared object).
+
+`make` will then compile `./src/libbitcoind.so` (with `-shared -fPIC`), linking
+to all the freshly compiled PIC object files. This will completely ignore
+compiling tests and the QT object files.
+
+Without `--enable-daemonlib`, the Makefile with compile bitcoind with -fPIE
+(Position Independent for Executable), this allows compiling of bitcoind.
+
+#### Todo
+
+- Find a way to compile bitcoind and libbitcoind.so at the same time without
+ recompiling object files each time? Possibly use libtool's .lo/.la.
LEVELDB_CPPFLAGS=
LIBLEVELDB=
LIBMEMENV=
diff --git a/src/Makefile.am b/src/Makefile.am
index d6ac6e1..4ac63a2 100644
index 81b16d1..cc926e1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,12 +31,15 @@ LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a
@@ -31,12 +31,14 @@ LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a
LIBBITCOIN_UNIVALUE=univalue/libbitcoin_univalue.a
LIBBITCOINQT=qt/libbitcoinqt.a
LIBSECP256K1=secp256k1/libsecp256k1.la
@ -153,12 +131,11 @@ index d6ac6e1..4ac63a2 100644
# Make is not made aware of per-object dependencies to avoid limiting building parallelization
# But to build the less dependent modules first, we manually select their order here:
+
+if !ENABLE_DAEMONLIB
noinst_LIBRARIES = \
EXTRA_LIBRARIES = \
crypto/libbitcoin_crypto.a \
libbitcoin_util.a \
@@ -76,6 +79,7 @@ BITCOIN_CORE_H = \
@@ -76,6 +78,7 @@ BITCOIN_CORE_H = \
amount.h \
base58.h \
bloom.h \
@ -166,7 +143,7 @@ index d6ac6e1..4ac63a2 100644
chain.h \
chainparams.h \
chainparamsbase.h \
@@ -152,10 +156,17 @@ JSON_H = \
@@ -152,10 +155,17 @@ JSON_H = \
json/json_spirit_writer.h \
json/json_spirit_writer_template.h
@ -184,7 +161,7 @@ index d6ac6e1..4ac63a2 100644
libbitcoin_util_a-clientversion.$(OBJEXT): obj/build.h
# server: shared between bitcoind and bitcoin-qt
@@ -165,6 +176,7 @@ libbitcoin_server_a_SOURCES = \
@@ -165,6 +175,7 @@ libbitcoin_server_a_SOURCES = \
alert.cpp \
bloom.cpp \
chain.cpp \
@ -192,16 +169,17 @@ index d6ac6e1..4ac63a2 100644
checkpoints.cpp \
init.cpp \
leveldbwrapper.cpp \
@@ -304,7 +316,7 @@ bitcoind_LDADD = \
@@ -304,8 +315,7 @@ bitcoind_LDADD = \
if ENABLE_WALLET
bitcoind_LDADD += libbitcoin_wallet.a
endif
-bitcoind_SOURCES = bitcoind.cpp
-#
+bitcoind_SOURCES = bitcoin-main.cpp
#
if TARGET_WINDOWS
@@ -380,6 +392,7 @@ if USE_LIBSECP256K1
bitcoind_SOURCES += bitcoind-res.rc
@@ -380,6 +390,7 @@ if USE_LIBSECP256K1
libbitcoinconsensus_la_LIBADD += secp256k1/libsecp256k1.la
endif
endif
@ -209,7 +187,7 @@ index d6ac6e1..4ac63a2 100644
CLEANFILES = leveldb/libleveldb.a leveldb/libmemenv.a *.gcda *.gcno
@@ -405,6 +418,9 @@ clean-local:
@@ -405,6 +416,9 @@ clean-local:
@test -f $(PROTOC)
$(AM_V_GEN) $(PROTOC) --cpp_out=$(@D) --proto_path=$(abspath $(<D) $<)
@ -219,17 +197,17 @@ index d6ac6e1..4ac63a2 100644
if ENABLE_TESTS
include Makefile.test.include
endif
@@ -416,3 +432,4 @@ endif
@@ -416,3 +430,4 @@ endif
if ENABLE_QT_TESTS
include Makefile.qttest.include
endif
+endif
diff --git a/src/Makefile.daemon.include b/src/Makefile.daemon.include
new file mode 100644
index 0000000..f411ea8
index 0000000..b4934ba
--- /dev/null
+++ b/src/Makefile.daemon.include
@@ -0,0 +1,43 @@
@@ -0,0 +1,52 @@
+all: $(LIBBITCOIND)
+
+leveldb_obj = \
@ -263,16 +241,25 @@ index 0000000..f411ea8
+libbitcoind_obj += compat/glibcxx_compat.o
+endif
+
+CXXFLAGS += -I./leveldb/helpers/memenv
+COMMAND = $(CC) -dynamiclib \
+ -lc++ -lcrypto -L/usr/lib -lminiupnpc \
+ $(CXXFLAGS) $(CPPFLAGS) $(DEFS) $(LEVELDB_CPPFLAGS) \
+ $(BITCOIN_INCLUDES) $(BITCOIN_CONFIG_INCLUDES) $(BOOST_LIBS) \
+ $(BDB_LIBS) $(PROTOBUF_LIBS) $(SSL_LIBS) $(LIBS) \
+ $(leveldb_obj) $(libbitcoind_obj) \
+ ./secp256k1/libsecp256k1_la-secp256k1.o \
+ -o libbitcoind.dylib
+
+clientversion.o: clientversion.cpp obj/build.h
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(BITCOIN_INCLUDES) $(BITCOIN_CONFIG_INCLUDES) \
+ $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
+do:
+ @echo "$(COMMAND)"
+
+$(LIBBITCOIND): $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1) $(libbitcoind_obj)
+ $(CC) -shared $(CXXFLAGS) $(CPPFLAGS) $(DEFS) $(LEVELDB_CPPFLAGS) \
+ $(BITCOIN_INCLUDES) $(BITCOIN_CONFIG_INCLUDES) -o $@ $(BOOST_LIBS) \
+ $(BDB_LIBS) $(PROTOBUF_LIBS) $(SSL_LIBS) $(LIBS) \
+ $(leveldb_obj) $(libbitcoind_obj)
+ $(COMMAND)
diff --git a/src/bitcoin-main.cpp b/src/bitcoin-main.cpp
new file mode 100644
index 0000000..b37f9cf
@ -416,13 +403,14 @@ index 4247920..08c8164 100644
~CLevelDBWrapper();
diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp
index 8b95373..53f9a5a 100644
index 8b95373..cd18b91 100644
--- a/src/rpcdump.cpp
+++ b/src/rpcdump.cpp
@@ -26,11 +26,11 @@ using namespace std;
@@ -25,12 +25,11 @@ using namespace json_spirit;
using namespace std;
void EnsureWalletIsUnlocked();
-
-std::string static EncodeDumpTime(int64_t nTime) {
+std::string EncodeDumpTime(int64_t nTime) {
return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime);
@ -433,7 +421,7 @@ index 8b95373..53f9a5a 100644
static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
static const std::locale loc(std::locale::classic(),
new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ"));
@@ -43,7 +43,7 @@ int64_t static DecodeDumpTime(const std::string &str) {
@@ -43,7 +42,7 @@ int64_t static DecodeDumpTime(const std::string &str) {
return (ptime - epoch).total_seconds();
}
@ -443,7 +431,7 @@ index 8b95373..53f9a5a 100644
BOOST_FOREACH(unsigned char c, str) {
if (c <= 32 || c >= 128 || c == '%') {
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index d2d14ad..e8abb3d 100644
index e43eee1..8862738 100644
--- a/src/rpcwallet.cpp
+++ b/src/rpcwallet.cpp
@@ -4,6 +4,7 @@
@ -478,10 +466,10 @@ index 0000000..2b53241
+
+#endif
diff --git a/src/wallet.h b/src/wallet.h
index 70d274c..604e9e7 100644
index 058107e..3dfc8c4 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -105,8 +105,6 @@ public:
@@ -110,8 +110,6 @@ public:
class CWallet : public CCryptoKeyStore, public CValidationInterface
{
private:
@ -490,7 +478,7 @@ index 70d274c..604e9e7 100644
CWalletDB *pwalletdbEncryption;
//! the current wallet version: clients below this version are not able to load the wallet
@@ -201,6 +199,7 @@ public:
@@ -206,6 +204,7 @@ public:
bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL) const;
@ -498,3 +486,6 @@ index 70d274c..604e9e7 100644
bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet) const;
bool IsSpent(const uint256& hash, unsigned int n) const;
--
2.3.2 (Apple Git-55)