Back to home page

Bitcoin sources

 
 

    


0001 # Copyright (c) 2009-2010 Satoshi Nakamoto
0002 # Distributed under the MIT/X11 software license, see the accompanying
0003 # file license.txt or http://www.opensource.org/licenses/mit-license.php.
0004 
0005 DEFS=-DNOPCH
0006 
0007 DEFS += $(addprefix -I,$(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
0008 LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
0009 
0010 LMODE = dynamic
0011 LMODE2 = dynamic
0012 ifdef STATIC
0013         LMODE = static
0014         ifeq (${STATIC}, all)
0015                 LMODE2 = static
0016         endif
0017 else
0018         TESTDEFS += -DBOOST_TEST_DYN_LINK
0019 endif
0020 
0021 # for boost 1.37, add -mt to the boost libraries
0022 LIBS += \
0023  -Wl,-B$(LMODE) \
0024    -l boost_system$(BOOST_LIB_SUFFIX) \
0025    -l boost_filesystem$(BOOST_LIB_SUFFIX) \
0026    -l boost_program_options$(BOOST_LIB_SUFFIX) \
0027    -l boost_thread$(BOOST_LIB_SUFFIX) \
0028    -l db_cxx$(BDB_LIB_SUFFIX) \
0029    -l ssl \
0030    -l crypto
0031 
0032 LIBS+= \
0033  -Wl,-B$(LMODE2) \
0034    -l z \
0035    -l dl \
0036    -l pthread
0037 
0038 
0039 # Hardening
0040 # Make some classes of vulnerabilities unexploitable in case one is discovered.
0041 #
0042     # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
0043     # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
0044     # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
0045     HARDENING=-fno-stack-protector
0046 
0047     # Stack Canaries
0048     # Put numbers at the beginning of each stack frame and check that they are the same.
0049     # If a stack buffer if overflowed, it writes over the canary number and then on return
0050     # when that number is checked, it won't be the same and the program will exit with
0051     # a "Stack smashing detected" error instead of being exploited.
0052     HARDENING+=-fstack-protector-all -Wstack-protector
0053 
0054     # Make some important things such as the global offset table read only as soon as
0055     # the dynamic linker is finished building it. This will prevent overwriting of addresses
0056     # which would later be jumped to.
0057     HARDENING+=-Wl,-z,relro -Wl,-z,now
0058 
0059     # Build position independent code to take advantage of Address Space Layout Randomization
0060     # offered by some kernels.
0061     # see doc/build-unix.txt for more information.
0062     ifdef PIE
0063         HARDENING+=-fPIE -pie
0064     endif
0065 
0066     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
0067     # the source such overflowing a statically defined buffer.
0068     HARDENING+=-D_FORTIFY_SOURCE=2
0069 #
0070 
0071 
0072 DEBUGFLAGS=-g
0073 CXXFLAGS=-O2
0074 xCXXFLAGS=-pthread -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
0075 HEADERS = \
0076     base58.h \
0077     bignum.h \
0078     checkpoints.h \
0079     crypter.h \
0080     db.h \
0081     headers.h \
0082     init.h \
0083     irc.h \
0084     key.h \
0085     keystore.h \
0086     main.h \
0087     net.h \
0088     noui.h \
0089     protocol.h \
0090     bitcoinrpc.h \
0091     script.h \
0092     serialize.h \
0093     strlcpy.h \
0094     uint256.h \
0095     util.h \
0096     wallet.h
0097 
0098 OBJS= \
0099     obj/checkpoints.o \
0100     obj/crypter.o \
0101     obj/db.o \
0102     obj/init.o \
0103     obj/irc.o \
0104     obj/keystore.o \
0105     obj/main.o \
0106     obj/net.o \
0107     obj/protocol.o \
0108     obj/bitcoinrpc.o \
0109     obj/script.o \
0110     obj/util.o \
0111     obj/wallet.o
0112 
0113 
0114 all: bitcoind
0115 
0116 # auto-generated dependencies:
0117 -include obj/nogui/*.P
0118 -include obj-test/*.P
0119 
0120 obj/nogui/%.o: %.cpp
0121         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
0122         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
0123           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
0124               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
0125           rm -f $(@:%.o=%.d)
0126 
0127 bitcoind: $(OBJS:obj/%=obj/nogui/%)
0128         $(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
0129 
0130 obj-test/%.o: test/%.cpp
0131         $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -o $@ $<
0132         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
0133           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
0134               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
0135           rm -f $(@:%.o=%.d)
0136 
0137 test_bitcoin: obj-test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
0138         $(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(LDFLAGS) $(LIBS)
0139 
0140 clean:
0141         -rm -f bitcoind test_bitcoin
0142         -rm -f obj/*.o
0143         -rm -f obj/nogui/*.o
0144         -rm -f obj-test/*.o
0145         -rm -f obj/*.P
0146         -rm -f obj/nogui/*.P
0147         -rm -f obj-test/*.P