1 # Copyright (c) 2009-2010 Satoshi Nakamoto
2 # Distributed under the MIT/X11 software license, see the accompanying
3 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
10 DEFS=-DBOOST_SPIRIT_THREADSAFE
12 DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
13 LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
15 TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
25 TESTDEFS += -DBOOST_TEST_DYN_LINK
28 # for boost 1.37, add -mt to the boost libraries
31 -l boost_system$(BOOST_LIB_SUFFIX) \
32 -l boost_filesystem$(BOOST_LIB_SUFFIX) \
33 -l boost_program_options$(BOOST_LIB_SUFFIX) \
34 -l boost_thread$(BOOST_LIB_SUFFIX) \
35 -l db_cxx$(BDB_LIB_SUFFIX) \
42 ifneq (${USE_UPNP}, -)
44 DEFS += -DUSE_UPNP=$(USE_UPNP)
47 ifneq (${USE_IPV6}, -)
48 DEFS += -DUSE_IPV6=$(USE_IPV6)
59 # Make some classes of vulnerabilities unexploitable in case one is discovered.
61 # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
62 # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
63 # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
64 HARDENING=-fno-stack-protector
67 # Put numbers at the beginning of each stack frame and check that they are the same.
68 # If a stack buffer if overflowed, it writes over the canary number and then on return
69 # when that number is checked, it won't be the same and the program will exit with
70 # a "Stack smashing detected" error instead of being exploited.
71 HARDENING+=-fstack-protector-all -Wstack-protector
73 # Make some important things such as the global offset table read only as soon as
74 # the dynamic linker is finished building it. This will prevent overwriting of addresses
75 # which would later be jumped to.
76 LDHARDENING+=-Wl,-z,relro -Wl,-z,now
78 # Build position independent code to take advantage of Address Space Layout Randomization
79 # offered by some kernels.
80 # see doc/build-unix.txt for more information.
86 # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
87 # the source such overflowing a statically defined buffer.
88 HARDENING+=-D_FORTIFY_SOURCE=2
94 # CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only
95 # adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work.
96 xCXXFLAGS=-O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \
97 $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
99 # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
100 # adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
101 xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
123 obj/rpcblockchain.o \
124 obj/rpcrawtransaction.o \
135 # auto-generated dependencies:
137 -include obj-test/*.P
140 /bin/sh ../share/genbuild.sh obj/build.h
141 version.cpp: obj/build.h
142 DEFS += -DHAVE_BUILD_INFO
145 $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
146 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
147 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
148 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
151 bitcoind: $(OBJS:obj/%=obj/%)
152 $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
154 TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
156 obj-test/%.o: test/%.cpp
157 $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
158 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
159 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
160 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
163 test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
164 $(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(xLDFLAGS) $(LIBS)
167 -rm -f bitcoind test_bitcoin