diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index 1c6bc0a..db431de 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -2,7 +2,7 @@ TEMPLATE = app TARGET = bitcoin-qt VERSION = 0.8.0 INCLUDEPATH += src src/json src/qt -DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE +DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE LEVELDB_WITHOUT_MEMENV CONFIG += no_include_pwd CONFIG += thread @@ -96,24 +96,28 @@ contains(BITCOIN_NEED_QT_PLUGINS, 1) { QTPLUGIN += qcncodecs qjpcodecs qtwcodecs qkrcodecs qtaccessiblewidgets } +contains(USE_SYSTEM_LEVELDB, 1) { + LIBS += -lleveldb +} else { INCLUDEPATH += src/leveldb/include src/leveldb/helpers -LIBS += $$PWD/src/leveldb/libleveldb.a $$PWD/src/leveldb/libmemenv.a +LIBS += $$PWD/src/leveldb/libleveldb.a !win32 { - genleveldb.commands = cd $$PWD/src/leveldb && CC=$$QMAKE_CC CXX=$$QMAKE_CXX $(MAKE) OPT=\"$$QMAKE_CXXFLAGS\" libleveldb.a libmemenv.a + genleveldb.commands = cd $$PWD/src/leveldb && CC=$$QMAKE_CC CXX=$$QMAKE_CXX $(MAKE) OPT=\"$$QMAKE_CXXFLAGS\" libleveldb.a } else { # make an educated guess about what the ranlib command is called isEmpty(QMAKE_RANLIB) { QMAKE_RANLIB = $$replace(QMAKE_STRIP, strip, ranlib) } LIBS += -lshlwapi - genleveldb.commands = cd $$PWD/src/leveldb && CC=$$QMAKE_CC CXX=$$QMAKE_CXX TARGET_OS=OS_WINDOWS_CROSSCOMPILE $(MAKE) OPT=\"$$QMAKE_CXXFLAGS\" libleveldb.a libmemenv.a && $$QMAKE_RANLIB $$PWD/src/leveldb/libleveldb.a && $$QMAKE_RANLIB $$PWD/src/leveldb/libmemenv.a + genleveldb.commands = cd $$PWD/src/leveldb && CC=$$QMAKE_CC CXX=$$QMAKE_CXX TARGET_OS=OS_WINDOWS_CROSSCOMPILE $(MAKE) OPT=\"$$QMAKE_CXXFLAGS\" libleveldb.a && $$QMAKE_RANLIB $$PWD/src/leveldb/libleveldb.a } genleveldb.target = $$PWD/src/leveldb/libleveldb.a genleveldb.depends = FORCE PRE_TARGETDEPS += $$PWD/src/leveldb/libleveldb.a QMAKE_EXTRA_TARGETS += genleveldb +} # Gross ugly hack that depends on qmake internals, unfortunately there is no other way to do it. -QMAKE_CLEAN += $$PWD/src/leveldb/libleveldb.a; cd $$PWD/src/leveldb ; $(MAKE) clean +QMAKE_CLEAN += $$PWD/src/leveldb/libleveldb.a; cd $$PWD/src/leveldb && $(MAKE) clean || true # regenerate src/build.h !win32|contains(USE_BUILD_INFO, 1) { diff --git a/src/leveldb.cpp b/src/leveldb.cpp index b41764f..f71e801 100644 --- a/src/leveldb.cpp +++ b/src/leveldb.cpp @@ -8,7 +8,9 @@ #include #include #include +#ifndef LEVELDB_WITHOUT_MEMENV #include +#endif #include @@ -42,8 +44,12 @@ CLevelDB::CLevelDB(const boost::filesystem::path &path, size_t nCacheSize, bool options = GetOptions(nCacheSize); options.create_if_missing = true; if (fMemory) { +#ifndef LEVELDB_WITHOUT_MEMENV penv = leveldb::NewMemEnv(leveldb::Env::Default()); options.env = penv; +#else + throw std::runtime_error("CLevelDB(): compiled without memenv support"); +#endif } else { if (fWipe) { printf("Wiping LevelDB in %s\n", path.string().c_str()); diff --git a/src/makefile.unix b/src/makefile.unix index ece2f59..4cbeaba 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -36,6 +36,10 @@ LIBS += \ -l ssl \ -l crypto +TESTLIBS += \ + -Wl,-B$(LMODE) \ + -l boost_unit_test_framework$(BOOST_LIB_SUFFIX) + ifndef USE_UPNP override USE_UPNP = - endif @@ -100,8 +104,7 @@ xCXXFLAGS=-O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-para # adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work. xLDFLAGS=$(LDHARDENING) $(LDFLAGS) -OBJS= \ - leveldb/libleveldb.a \ +BASEOBJS := \ obj/alert.o \ obj/version.o \ obj/checkpoints.o \ @@ -110,7 +113,6 @@ OBJS= \ obj/crypter.o \ obj/key.o \ obj/db.o \ - obj/init.o \ obj/irc.o \ obj/keystore.o \ obj/main.o \ @@ -131,24 +133,43 @@ OBJS= \ obj/hash.o \ obj/bloom.o \ obj/noui.o \ - obj/leveldb.o \ obj/txdb.o +OBJS := \ + obj/leveldb.o \ + obj/init.o \ + $(BASEOBJS) + +TESTOBJS := \ + obj-test/leveldb.o \ + $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp)) \ + $(BASEOBJS) + all: bitcoind test check: test_bitcoin FORCE ./test_bitcoin +ifdef USE_SYSTEM_LEVELDB + LIBS += -lleveldb + TESTLIBS += -lmemenv +else # # LevelDB support # MAKEOVERRIDES = -LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a +LIBS += $(CURDIR)/leveldb/libleveldb.a +TESTLIBS += $(CURDIR)/leveldb/libmemenv.a DEFS += $(addprefix -I,$(CURDIR)/leveldb/include) DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers) leveldb/libleveldb.a: - @echo "Building LevelDB ..." && cd leveldb && $(MAKE) CC=$(CC) CXX=$(CXX) OPT="$(xCXXFLAGS)" libleveldb.a libmemenv.a && cd .. + @echo "Building LevelDB ..." && cd leveldb && $(MAKE) CC=$(CC) CXX=$(CXX) OPT="$(xCXXFLAGS)" libleveldb.a && cd .. +leveldb/libmemenv.a: + @echo "Building LevelDB memenv ..." && cd leveldb && $(MAKE) CC=$(CC) CXX=$(CXX) OPT="$(xCXXFLAGS)" libmemenv.a && cd .. +OBJS += leveldb/libleveldb.a +TESTOBJS += leveldb/libmemenv.a +endif # auto-generated dependencies: -include obj/*.P @@ -159,27 +180,29 @@ obj/build.h: FORCE version.cpp: obj/build.h DEFS += -DHAVE_BUILD_INFO -obj/%.o: %.cpp - $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $< +P_TO_D = \ @cp $(@:%.o=%.d) $(@:%.o=%.P); \ - sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ + sed -e 's/\#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ rm -f $(@:%.o=%.d) -bitcoind: $(OBJS:obj/%=obj/%) - $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS) +obj/%.o: %.cpp + $(CXX) -c $(xCXXFLAGS) -DLEVELDB_WITHOUT_MEMENV -MMD -MF $(@:%.o=%.d) -o $@ $< + $(P_TO_D) -TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp)) +bitcoind: $(OBJS) + $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS) obj-test/%.o: test/%.cpp $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $< - @cp $(@:%.o=%.d) $(@:%.o=%.P); \ - sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ - -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ - rm -f $(@:%.o=%.d) + $(P_TO_D) + +obj-test/leveldb.o: leveldb.cpp + $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $< + $(P_TO_D) -test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) - $(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(xLDFLAGS) $(LIBS) +test_bitcoin: $(TESTOBJS) + $(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ $(TESTLIBS) $(xLDFLAGS) $(LIBS) clean: -rm -f bitcoind test_bitcoin