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.
7 DEFS=-DUSE_IPV6 -DBOOST_SPIRIT_THREADSAFE
9 DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
10 LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
12 TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
22 TESTDEFS += -DBOOST_TEST_DYN_LINK
25 # for boost 1.37, add -mt to the boost libraries
28 -l boost_system$(BOOST_LIB_SUFFIX) \
29 -l boost_filesystem$(BOOST_LIB_SUFFIX) \
30 -l boost_program_options$(BOOST_LIB_SUFFIX) \
31 -l boost_thread$(BOOST_LIB_SUFFIX) \
32 -l db_cxx$(BDB_LIB_SUFFIX) \
39 ifneq (${USE_UPNP}, -)
41 DEFS += -DUSE_UPNP=$(USE_UPNP)
52 # Make some classes of vulnerabilities unexploitable in case one is discovered.
54 # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
55 # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
56 # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
57 HARDENING=-fno-stack-protector
60 # Put numbers at the beginning of each stack frame and check that they are the same.
61 # If a stack buffer if overflowed, it writes over the canary number and then on return
62 # when that number is checked, it won't be the same and the program will exit with
63 # a "Stack smashing detected" error instead of being exploited.
64 HARDENING+=-fstack-protector-all -Wstack-protector
66 # Make some important things such as the global offset table read only as soon as
67 # the dynamic linker is finished building it. This will prevent overwriting of addresses
68 # which would later be jumped to.
69 LDHARDENING+=-Wl,-z,relro -Wl,-z,now
71 # Build position independent code to take advantage of Address Space Layout Randomization
72 # offered by some kernels.
73 # see doc/build-unix.txt for more information.
79 # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
80 # the source such overflowing a statically defined buffer.
81 HARDENING+=-D_FORTIFY_SOURCE=2
87 # CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only
88 # adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work.
89 xCXXFLAGS=-O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \
90 $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
92 # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
93 # adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
94 xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
114 obj/rpcrawtransaction.o \
125 # auto-generated dependencies:
127 -include obj-test/*.P
130 /bin/sh ../share/genbuild.sh obj/build.h
131 version.cpp: obj/build.h
132 DEFS += -DHAVE_BUILD_INFO
135 $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
136 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
137 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
138 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
141 bitcoind: $(OBJS:obj/%=obj/%)
142 $(CXX) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
144 TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
146 obj-test/%.o: test/%.cpp
147 $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
148 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
149 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
150 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
153 test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
154 $(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(xLDFLAGS) $(LIBS)
157 -rm -f bitcoind test_bitcoin