1 # Copyright (c) 2009-2010 Satoshi Nakamoto
2 # Distributed under the MIT/X11 software license, see the accompanying
3 # file license.txt or http://www.opensource.org/licenses/mit-license.php.
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))
20 TESTDEFS += -DBOOST_TEST_DYN_LINK
23 # for boost 1.37, add -mt to the boost libraries
26 -l boost_system$(BOOST_LIB_SUFFIX) \
27 -l boost_filesystem$(BOOST_LIB_SUFFIX) \
28 -l boost_program_options$(BOOST_LIB_SUFFIX) \
29 -l boost_thread$(BOOST_LIB_SUFFIX) \
30 -l db_cxx$(BDB_LIB_SUFFIX) \
37 ifneq (${USE_UPNP}, -)
39 DEFS += -DUSE_UPNP=$(USE_UPNP)
50 # Make some classes of vulnerabilities unexploitable in case one is discovered.
52 # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
53 # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
54 # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
55 HARDENING=-fno-stack-protector
58 # Put numbers at the beginning of each stack frame and check that they are the same.
59 # If a stack buffer if overflowed, it writes over the canary number and then on return
60 # when that number is checked, it won't be the same and the program will exit with
61 # a "Stack smashing detected" error instead of being exploited.
62 HARDENING+=-fstack-protector-all -Wstack-protector
64 # Make some important things such as the global offset table read only as soon as
65 # the dynamic linker is finished building it. This will prevent overwriting of addresses
66 # which would later be jumped to.
67 HARDENING+=-Wl,-z,relro -Wl,-z,now
69 # Build position independent code to take advantage of Address Space Layout Randomization
70 # offered by some kernels.
71 # see doc/build-unix.txt for more information.
76 # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
77 # the source such overflowing a statically defined buffer.
78 HARDENING+=-D_FORTIFY_SOURCE=2
84 xCXXFLAGS=-pthread -Wextra -Wno-sign-compare -Wno-char-subscripts -Wno-invalid-offsetof -Wformat -Wformat-security \
85 $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
111 # auto-generated dependencies:
113 -include obj-test/*.P
116 ../share/genbuild.sh obj/build.h
117 version.cpp: obj/build.h
118 DEFS += -DHAVE_BUILD_INFO
121 $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
122 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
123 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
124 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
127 bitcoind: $(OBJS:obj/%=obj/%)
128 $(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
130 TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
132 obj-test/%.o: test/%.cpp
133 $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -o $@ $<
134 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
135 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
136 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
139 test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
140 $(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(LDFLAGS) $(LIBS)
143 -rm -f bitcoind test_bitcoin