2010-08-29 18:58:15 +02:00
|
|
|
# Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
|
|
# Distributed under the MIT/X11 software license, see the accompanying
|
2012-07-22 23:49:09 +02:00
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2011-07-05 18:19:34 +02:00
|
|
|
USE_UPNP:=0
|
2012-06-08 18:35:58 +02:00
|
|
|
USE_IPV6:=1
|
2011-07-05 18:19:34 +02:00
|
|
|
|
2012-08-08 04:20:08 +02:00
|
|
|
LINK:=$(CXX)
|
|
|
|
|
2012-06-08 18:35:58 +02:00
|
|
|
DEFS=-DBOOST_SPIRIT_THREADSAFE
|
2011-10-09 20:23:20 +02:00
|
|
|
|
2012-04-11 03:51:08 +02:00
|
|
|
DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
|
2012-02-15 22:05:55 +01:00
|
|
|
LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
|
2011-10-09 20:23:20 +02:00
|
|
|
|
2012-04-26 17:20:44 +02:00
|
|
|
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
|
|
|
|
|
2011-10-09 20:23:20 +02:00
|
|
|
LMODE = dynamic
|
|
|
|
LMODE2 = dynamic
|
|
|
|
ifdef STATIC
|
|
|
|
LMODE = static
|
|
|
|
ifeq (${STATIC}, all)
|
|
|
|
LMODE2 = static
|
|
|
|
endif
|
2012-01-23 17:37:48 +01:00
|
|
|
else
|
|
|
|
TESTDEFS += -DBOOST_TEST_DYN_LINK
|
2011-10-09 20:23:20 +02:00
|
|
|
endif
|
2011-03-26 13:01:27 +01:00
|
|
|
|
2010-08-29 18:58:15 +02:00
|
|
|
# for boost 1.37, add -mt to the boost libraries
|
2012-02-15 22:05:55 +01:00
|
|
|
LIBS += \
|
2011-10-09 20:23:20 +02:00
|
|
|
-Wl,-B$(LMODE) \
|
|
|
|
-l boost_system$(BOOST_LIB_SUFFIX) \
|
|
|
|
-l boost_filesystem$(BOOST_LIB_SUFFIX) \
|
|
|
|
-l boost_program_options$(BOOST_LIB_SUFFIX) \
|
|
|
|
-l boost_thread$(BOOST_LIB_SUFFIX) \
|
|
|
|
-l db_cxx$(BDB_LIB_SUFFIX) \
|
2010-10-11 20:23:41 +02:00
|
|
|
-l ssl \
|
2011-03-26 13:01:27 +01:00
|
|
|
-l crypto
|
|
|
|
|
2011-10-09 20:23:20 +02:00
|
|
|
ifndef USE_UPNP
|
|
|
|
override USE_UPNP = -
|
|
|
|
endif
|
|
|
|
ifneq (${USE_UPNP}, -)
|
2011-07-05 18:19:34 +02:00
|
|
|
LIBS += -l miniupnpc
|
|
|
|
DEFS += -DUSE_UPNP=$(USE_UPNP)
|
|
|
|
endif
|
2011-03-26 13:01:27 +01:00
|
|
|
|
2012-06-08 18:35:58 +02:00
|
|
|
ifneq (${USE_IPV6}, -)
|
2012-06-08 18:43:06 +02:00
|
|
|
DEFS += -DUSE_IPV6=$(USE_IPV6)
|
2012-06-08 18:35:58 +02:00
|
|
|
endif
|
|
|
|
|
2011-03-26 13:01:27 +01:00
|
|
|
LIBS+= \
|
2011-10-09 20:23:20 +02:00
|
|
|
-Wl,-B$(LMODE2) \
|
2010-10-14 15:33:03 +02:00
|
|
|
-l z \
|
2011-04-23 01:16:19 +02:00
|
|
|
-l dl \
|
|
|
|
-l pthread
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2011-03-26 13:01:27 +01:00
|
|
|
|
2011-09-08 18:50:54 +02:00
|
|
|
# Hardening
|
|
|
|
# Make some classes of vulnerabilities unexploitable in case one is discovered.
|
|
|
|
#
|
2011-10-17 02:38:23 +02:00
|
|
|
# This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
|
|
|
|
# -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
|
|
|
|
# see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
|
|
|
|
HARDENING=-fno-stack-protector
|
|
|
|
|
2011-09-08 18:50:54 +02:00
|
|
|
# Stack Canaries
|
|
|
|
# Put numbers at the beginning of each stack frame and check that they are the same.
|
|
|
|
# If a stack buffer if overflowed, it writes over the canary number and then on return
|
|
|
|
# when that number is checked, it won't be the same and the program will exit with
|
|
|
|
# a "Stack smashing detected" error instead of being exploited.
|
2011-10-17 02:38:23 +02:00
|
|
|
HARDENING+=-fstack-protector-all -Wstack-protector
|
2011-09-08 18:50:54 +02:00
|
|
|
|
|
|
|
# Make some important things such as the global offset table read only as soon as
|
|
|
|
# the dynamic linker is finished building it. This will prevent overwriting of addresses
|
|
|
|
# which would later be jumped to.
|
2012-06-24 14:02:14 +02:00
|
|
|
LDHARDENING+=-Wl,-z,relro -Wl,-z,now
|
2011-09-08 18:50:54 +02:00
|
|
|
|
|
|
|
# Build position independent code to take advantage of Address Space Layout Randomization
|
|
|
|
# offered by some kernels.
|
|
|
|
# see doc/build-unix.txt for more information.
|
|
|
|
ifdef PIE
|
2012-06-24 14:02:14 +02:00
|
|
|
HARDENING+=-fPIE
|
|
|
|
LDHARDENING+=-pie
|
2011-09-08 18:50:54 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
# -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
|
|
|
|
# the source such overflowing a statically defined buffer.
|
|
|
|
HARDENING+=-D_FORTIFY_SOURCE=2
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2011-09-26 16:04:04 +02:00
|
|
|
DEBUGFLAGS=-g
|
2012-05-12 23:03:01 +02:00
|
|
|
|
|
|
|
# CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only
|
|
|
|
# adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work.
|
2012-09-30 15:26:41 +02:00
|
|
|
xCXXFLAGS=-O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \
|
2012-05-12 23:03:01 +02:00
|
|
|
$(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2012-06-24 14:02:14 +02:00
|
|
|
# LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
|
|
|
|
# adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
|
|
|
|
xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
|
|
|
|
|
2010-08-29 18:58:15 +02:00
|
|
|
OBJS= \
|
2012-08-28 23:04:54 +02:00
|
|
|
obj/alert.o \
|
2012-04-07 02:06:53 +02:00
|
|
|
obj/version.o \
|
2011-09-08 22:50:58 +02:00
|
|
|
obj/checkpoints.o \
|
2012-01-03 23:33:31 +01:00
|
|
|
obj/netbase.o \
|
2012-01-04 23:39:45 +01:00
|
|
|
obj/addrman.o \
|
2011-08-11 17:19:36 +02:00
|
|
|
obj/crypter.o \
|
2011-07-11 21:30:40 +02:00
|
|
|
obj/key.o \
|
2010-08-29 18:58:15 +02:00
|
|
|
obj/db.o \
|
2011-08-11 17:19:36 +02:00
|
|
|
obj/init.o \
|
2010-08-29 18:58:15 +02:00
|
|
|
obj/irc.o \
|
2011-06-01 18:27:05 +02:00
|
|
|
obj/keystore.o \
|
2010-08-29 18:58:15 +02:00
|
|
|
obj/main.o \
|
2011-08-11 17:19:36 +02:00
|
|
|
obj/net.o \
|
2011-08-11 18:14:53 +02:00
|
|
|
obj/protocol.o \
|
2011-09-18 12:41:48 +02:00
|
|
|
obj/bitcoinrpc.o \
|
2011-07-13 11:56:38 +02:00
|
|
|
obj/rpcdump.o \
|
2012-06-29 05:18:38 +02:00
|
|
|
obj/rpcnet.o \
|
2012-08-21 08:21:33 +02:00
|
|
|
obj/rpcmining.o \
|
2012-08-21 16:38:57 +02:00
|
|
|
obj/rpcwallet.o \
|
2012-08-21 17:03:38 +02:00
|
|
|
obj/rpcblockchain.o \
|
2012-05-31 22:01:16 +02:00
|
|
|
obj/rpcrawtransaction.o \
|
2011-08-11 17:19:36 +02:00
|
|
|
obj/script.o \
|
2012-05-11 17:00:03 +02:00
|
|
|
obj/sync.o \
|
2011-08-11 17:19:36 +02:00
|
|
|
obj/util.o \
|
2012-04-04 13:19:30 +02:00
|
|
|
obj/wallet.o \
|
2012-04-15 23:39:49 +02:00
|
|
|
obj/walletdb.o \
|
2012-10-16 22:23:39 +02:00
|
|
|
obj/noui.o \
|
|
|
|
obj/leveldb.o \
|
|
|
|
obj/txdb.o
|
2010-08-29 18:58:15 +02:00
|
|
|
|
|
|
|
|
2011-09-26 16:04:04 +02:00
|
|
|
all: bitcoind
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2012-09-18 17:38:19 +02:00
|
|
|
test check: test_bitcoin FORCE
|
|
|
|
./test_bitcoin
|
|
|
|
|
2012-08-30 21:13:50 +02:00
|
|
|
#
|
|
|
|
# LevelDB support
|
|
|
|
#
|
|
|
|
LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a
|
2012-10-16 22:23:39 +02:00
|
|
|
DEFS += $(addprefix -I,$(CURDIR)/leveldb/include)
|
2012-08-30 21:13:50 +02:00
|
|
|
DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers)
|
|
|
|
leveldb/libleveldb.a:
|
2012-10-28 22:38:22 +01:00
|
|
|
@echo "Building LevelDB ..." && cd leveldb && make libleveldb.a libmemenv.a && cd ..
|
2012-09-03 19:05:30 +02:00
|
|
|
obj/leveldb.o: leveldb/libleveldb.a
|
2012-08-30 21:13:50 +02:00
|
|
|
|
2011-10-05 17:28:08 +02:00
|
|
|
# auto-generated dependencies:
|
2012-01-13 02:02:47 +01:00
|
|
|
-include obj/*.P
|
2012-01-23 20:27:08 +01:00
|
|
|
-include obj-test/*.P
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2012-04-11 03:51:08 +02:00
|
|
|
obj/build.h: FORCE
|
2012-05-17 17:15:28 +02:00
|
|
|
/bin/sh ../share/genbuild.sh obj/build.h
|
2012-04-11 03:51:08 +02:00
|
|
|
version.cpp: obj/build.h
|
2012-04-07 02:06:53 +02:00
|
|
|
DEFS += -DHAVE_BUILD_INFO
|
|
|
|
|
2012-01-13 02:02:47 +01:00
|
|
|
obj/%.o: %.cpp
|
2012-07-03 17:30:43 +02:00
|
|
|
$(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
|
2011-10-05 17:28:08 +02:00
|
|
|
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
|
|
|
|
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
|
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
|
|
|
|
rm -f $(@:%.o=%.d)
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2012-04-11 03:51:08 +02:00
|
|
|
bitcoind: $(OBJS:obj/%=obj/%)
|
2012-08-08 04:20:08 +02:00
|
|
|
$(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2012-01-23 20:27:08 +01:00
|
|
|
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
|
2011-10-12 01:50:06 +02:00
|
|
|
|
2012-01-23 20:27:08 +01:00
|
|
|
obj-test/%.o: test/%.cpp
|
2012-07-03 17:30:43 +02:00
|
|
|
$(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
|
2011-10-05 17:28:08 +02:00
|
|
|
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
|
|
|
|
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
|
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
|
|
|
|
rm -f $(@:%.o=%.d)
|
2011-06-27 20:05:02 +02:00
|
|
|
|
2012-01-13 02:02:47 +01:00
|
|
|
test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
|
2012-08-08 04:20:08 +02:00
|
|
|
$(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(xLDFLAGS) $(LIBS)
|
2010-08-29 18:58:15 +02:00
|
|
|
|
|
|
|
clean:
|
2011-09-26 16:04:04 +02:00
|
|
|
-rm -f bitcoind test_bitcoin
|
2010-08-29 18:58:15 +02:00
|
|
|
-rm -f obj/*.o
|
2012-01-23 20:27:08 +01:00
|
|
|
-rm -f obj-test/*.o
|
2011-10-05 17:28:08 +02:00
|
|
|
-rm -f obj/*.P
|
2012-01-23 20:27:08 +01:00
|
|
|
-rm -f obj-test/*.P
|
2012-09-20 16:28:13 +02:00
|
|
|
-rm -f obj/build.h
|
2012-04-07 02:06:53 +02:00
|
|
|
|
|
|
|
FORCE:
|