genesis 1 # Copyright (c) 2009-2010 Satoshi Nakamoto
genesis 2 # Distributed under the MIT/X11 software license, see the accompanying
genesis 3 # file license.txt or http://www.opensource.org/licenses/mit-license.php.
genesis 4
genesis 5 DEFS=-DNOPCH
genesis 6
genesis 7 DEFS += $(addprefix -I,$(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
genesis 8 LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
genesis 9
genesis 10 LMODE = dynamic
genesis 11 LMODE2 = dynamic
genesis 12 ifdef STATIC
genesis 13 LMODE = static
genesis 14 ifeq (${STATIC}, all)
genesis 15 LMODE2 = static
genesis 16 endif
genesis 17 else
genesis 18 TESTDEFS += -DBOOST_TEST_DYN_LINK
genesis 19 endif
genesis 20
genesis 21 # for boost 1.37, add -mt to the boost libraries
genesis 22 LIBS += \
genesis 23 -Wl,-B$(LMODE) \
genesis 24 -l boost_system$(BOOST_LIB_SUFFIX) \
genesis 25 -l boost_filesystem$(BOOST_LIB_SUFFIX) \
genesis 26 -l boost_program_options$(BOOST_LIB_SUFFIX) \
genesis 27 -l boost_thread$(BOOST_LIB_SUFFIX) \
genesis 28 -l db_cxx$(BDB_LIB_SUFFIX) \
genesis 29 -l ssl \
bitcoin-v0_5_3_1-... 30 -l crypto \
bitcoin-v0_5_3_1-... 31 -static-libgcc
genesis 32
genesis 33 LIBS+= \
genesis 34 -Wl,-B$(LMODE2) \
genesis 35 -l pthread
genesis 36
genesis 37
genesis 38 # Hardening
genesis 39 # Make some classes of vulnerabilities unexploitable in case one is discovered.
genesis 40 #
genesis 41 # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
genesis 42 # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
genesis 43 # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
genesis 44 HARDENING=-fno-stack-protector
genesis 45
genesis 46 # Stack Canaries
genesis 47 # Put numbers at the beginning of each stack frame and check that they are the same.
genesis 48 # If a stack buffer if overflowed, it writes over the canary number and then on return
genesis 49 # when that number is checked, it won't be the same and the program will exit with
genesis 50 # a "Stack smashing detected" error instead of being exploited.
genesis 51 HARDENING+=-fstack-protector-all -Wstack-protector
genesis 52
genesis 53 # Make some important things such as the global offset table read only as soon as
genesis 54 # the dynamic linker is finished building it. This will prevent overwriting of addresses
genesis 55 # which would later be jumped to.
genesis 56 HARDENING+=-Wl,-z,relro -Wl,-z,now
genesis 57
genesis 58 # Build position independent code to take advantage of Address Space Layout Randomization
genesis 59 # offered by some kernels.
genesis 60 # see doc/build-unix.txt for more information.
genesis 61 ifdef PIE
genesis 62 HARDENING+=-fPIE -pie
genesis 63 endif
genesis 64
genesis 65 # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
genesis 66 # the source such overflowing a statically defined buffer.
genesis 67 HARDENING+=-D_FORTIFY_SOURCE=2
genesis 68 #
genesis 69
genesis 70
genesis 71 DEBUGFLAGS=-g
genesis 72 CXXFLAGS=-O2
genesis 73 xCXXFLAGS=-pthread -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
genesis 74 HEADERS = \
genesis 75 base58.h \
genesis 76 bignum.h \
genesis 77 checkpoints.h \
genesis 78 crypter.h \
genesis 79 db.h \
genesis 80 headers.h \
genesis 81 init.h \
genesis 82 key.h \
genesis 83 keystore.h \
genesis 84 main.h \
genesis 85 net.h \
genesis 86 noui.h \
genesis 87 protocol.h \
genesis 88 bitcoinrpc.h \
genesis 89 script.h \
genesis 90 serialize.h \
genesis 91 strlcpy.h \
genesis 92 uint256.h \
genesis 93 util.h \
genesis 94 wallet.h
genesis 95
genesis 96 OBJS= \
genesis 97 obj/checkpoints.o \
genesis 98 obj/crypter.o \
genesis 99 obj/db.o \
genesis 100 obj/init.o \
genesis 101 obj/keystore.o \
genesis 102 obj/main.o \
genesis 103 obj/net.o \
genesis 104 obj/protocol.o \
genesis 105 obj/bitcoinrpc.o \
genesis 106 obj/script.o \
genesis 107 obj/util.o \
genesis 108 obj/wallet.o
genesis 109
genesis 110
genesis 111 all: bitcoind
genesis 112
genesis 113 # auto-generated dependencies:
genesis 114 -include obj/nogui/*.P
genesis 115 -include obj-test/*.P
genesis 116
genesis 117 obj/nogui/%.o: %.cpp
genesis 118 $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
genesis 119 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
genesis 120 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
genesis 121 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
genesis 122 rm -f $(@:%.o=%.d)
genesis 123
genesis 124 bitcoind: $(OBJS:obj/%=obj/nogui/%)
genesis 125 $(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
genesis 126
genesis 127 obj-test/%.o: test/%.cpp
genesis 128 $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -o $@ $<
genesis 129 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
genesis 130 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
genesis 131 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
genesis 132 rm -f $(@:%.o=%.d)
genesis 133
genesis 134 test_bitcoin: obj-test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
genesis 135 $(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(LDFLAGS) $(LIBS)
genesis 136
genesis 137 clean:
genesis 138 -rm -f bitcoind test_bitcoin
genesis 139 -rm -f obj/*.o
genesis 140 -rm -f obj/nogui/*.o
genesis 141 -rm -f obj-test/*.o
genesis 142 -rm -f obj/*.P
genesis 143 -rm -f obj/nogui/*.P
genesis 144 -rm -f obj-test/*.P