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)
asciilifeform_shi...   74 CFLAGS=-lm -DUSE_ASCII_NAMES=0 -O2
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     key.h \
genesis                84     keystore.h \
programmable-vers...   85     knobs.h \
genesis                86     main.h \
genesis                87     net.h \
genesis                88     noui.h \
genesis                89     protocol.h \
genesis                90     bitcoinrpc.h \
asciilifeform_shi...   91     shiva.h \
genesis                92     script.h \
genesis                93     serialize.h \
genesis                94     strlcpy.h \
genesis                95     uint256.h \
genesis                96     util.h \
genesis                97     wallet.h
genesis                98 
genesis                99 OBJS= \
genesis               100     obj/checkpoints.o \
genesis               101     obj/crypter.o \
genesis               102     obj/db.o \
genesis               103     obj/init.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 \
asciilifeform_shi...  109     obj/shiva.o \
genesis               110     obj/script.o \
genesis               111     obj/util.o \
asciilifeform_shi...  112     obj/wallet.o \
asciilifeform_shi...  113     obj-shiva/scheme.o
genesis               114 
genesis               115 
genesis               116 all: bitcoind
genesis               117 
genesis               118 # auto-generated dependencies:
genesis               119 -include obj/nogui/*.P
asciilifeform_shi...  120 -include obj-shiva/*.P
genesis               121 -include obj-test/*.P
genesis               122 
genesis               123 obj/nogui/%.o: %.cpp
genesis               124 	$(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
genesis               125 	@cp $(@:%.o=%.d) $(@:%.o=%.P); \
genesis               126 	  sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
genesis               127 	      -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
genesis               128 	  rm -f $(@:%.o=%.d)
genesis               129 
asciilifeform_shi...  130 obj-shiva/%.o: shiva/%.c
asciilifeform_shi...  131 	$(CC) -c $(TESTDEFS) $(CFLAGS) -MMD -o $@ $<
asciilifeform_shi...  132 	@cp $(@:%.o=%.d) $(@:%.o=%.P); \
asciilifeform_shi...  133 	  sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
asciilifeform_shi...  134 	      -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
asciilifeform_shi...  135 	  rm -f $(@:%.o=%.d)
asciilifeform_shi...  136 
genesis               137 bitcoind: $(OBJS:obj/%=obj/nogui/%)
genesis               138 	$(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
genesis               139 
genesis               140 obj-test/%.o: test/%.cpp
genesis               141 	$(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -o $@ $<
genesis               142 	@cp $(@:%.o=%.d) $(@:%.o=%.P); \
genesis               143 	  sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
genesis               144 	      -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
genesis               145 	  rm -f $(@:%.o=%.d)
genesis               146 
genesis               147 test_bitcoin: obj-test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
genesis               148 	$(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(LDFLAGS) $(LIBS)
genesis               149 
genesis               150 clean:
genesis               151 	-rm -f bitcoind test_bitcoin
genesis               152 	-rm -f obj/*.o
genesis               153 	-rm -f obj/nogui/*.o
asciilifeform_shi...  154 	-rm -f obj-shiva/*.o
asciilifeform_shi...  155 	-rm -f obj-shiva/*.P
genesis               156 	-rm -f obj-test/*.o
genesis               157 	-rm -f obj/*.P
genesis               158 	-rm -f obj/nogui/*.P
genesis               159 	-rm -f obj-test/*.P