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 \
genesis                30    -l crypto
genesis                31 
genesis                32 LIBS+= \
genesis                33  -Wl,-B$(LMODE2) \
genesis                34    -l z \
genesis                35    -l dl \
genesis                36    -l pthread
genesis                37 
genesis                38 
genesis                39 # Hardening
genesis                40 # Make some classes of vulnerabilities unexploitable in case one is discovered.
genesis                41 #
genesis                42     # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
genesis                43     # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
genesis                44     # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
genesis                45     HARDENING=-fno-stack-protector
genesis                46 
genesis                47     # Stack Canaries
genesis                48     # Put numbers at the beginning of each stack frame and check that they are the same.
genesis                49     # If a stack buffer if overflowed, it writes over the canary number and then on return
genesis                50     # when that number is checked, it won't be the same and the program will exit with
genesis                51     # a "Stack smashing detected" error instead of being exploited.
genesis                52     HARDENING+=-fstack-protector-all -Wstack-protector
genesis                53 
genesis                54     # Make some important things such as the global offset table read only as soon as
genesis                55     # the dynamic linker is finished building it. This will prevent overwriting of addresses
genesis                56     # which would later be jumped to.
genesis                57     HARDENING+=-Wl,-z,relro -Wl,-z,now
genesis                58 
genesis                59     # Build position independent code to take advantage of Address Space Layout Randomization
genesis                60     # offered by some kernels.
genesis                61     # see doc/build-unix.txt for more information.
genesis                62     ifdef PIE
genesis                63         HARDENING+=-fPIE -pie
genesis                64     endif
genesis                65 
genesis                66     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
genesis                67     # the source such overflowing a statically defined buffer.
genesis                68     HARDENING+=-D_FORTIFY_SOURCE=2
genesis                69 #
genesis                70 
genesis                71 
genesis                72 DEBUGFLAGS=-g
genesis                73 CXXFLAGS=-O2
genesis                74 xCXXFLAGS=-pthread -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
genesis                75 HEADERS = \
genesis                76     base58.h \
genesis                77     bignum.h \
genesis                78     checkpoints.h \
genesis                79     crypter.h \
genesis                80     db.h \
genesis                81     headers.h \
genesis                82     init.h \
genesis                83     irc.h \
genesis                84     key.h \
genesis                85     keystore.h \
genesis                86     main.h \
genesis                87     net.h \
genesis                88     noui.h \
genesis                89     protocol.h \
genesis                90     bitcoinrpc.h \
genesis                91     script.h \
genesis                92     serialize.h \
genesis                93     strlcpy.h \
genesis                94     uint256.h \
genesis                95     util.h \
genesis                96     wallet.h
genesis                97 
genesis                98 OBJS= \
genesis                99     obj/checkpoints.o \
genesis               100     obj/crypter.o \
genesis               101     obj/db.o \
genesis               102     obj/init.o \
genesis               103     obj/irc.o \
genesis               104     obj/keystore.o \
genesis               105     obj/main.o \
genesis               106     obj/net.o \
genesis               107     obj/protocol.o \
genesis               108     obj/bitcoinrpc.o \
genesis               109     obj/script.o \
genesis               110     obj/util.o \
genesis               111     obj/wallet.o
genesis               112 
genesis               113 
genesis               114 all: bitcoind
genesis               115 
genesis               116 # auto-generated dependencies:
genesis               117 -include obj/nogui/*.P
genesis               118 -include obj-test/*.P
genesis               119 
genesis               120 obj/nogui/%.o: %.cpp
genesis               121 	$(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
genesis               122 	@cp $(@:%.o=%.d) $(@:%.o=%.P); \
genesis               123 	  sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
genesis               124 	      -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
genesis               125 	  rm -f $(@:%.o=%.d)
genesis               126 
genesis               127 bitcoind: $(OBJS:obj/%=obj/nogui/%)
genesis               128 	$(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
genesis               129 
genesis               130 obj-test/%.o: test/%.cpp
genesis               131 	$(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -o $@ $<
genesis               132 	@cp $(@:%.o=%.d) $(@:%.o=%.P); \
genesis               133 	  sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
genesis               134 	      -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
genesis               135 	  rm -f $(@:%.o=%.d)
genesis               136 
genesis               137 test_bitcoin: obj-test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
genesis               138 	$(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(LDFLAGS) $(LIBS)
genesis               139 
genesis               140 clean:
genesis               141 	-rm -f bitcoind test_bitcoin
genesis               142 	-rm -f obj/*.o
genesis               143 	-rm -f obj/nogui/*.o
genesis               144 	-rm -f obj-test/*.o
genesis               145 	-rm -f obj/*.P
genesis               146 	-rm -f obj/nogui/*.P
genesis               147 	-rm -f obj-test/*.P