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    -static-libgcc
0032 
0033 LIBS+= \
0034  -Wl,-B$(LMODE2) \
0035    -l pthread
0036 
0037 
0038 # Hardening
0039 # Make some classes of vulnerabilities unexploitable in case one is discovered.
0040 #
0041     # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
0042     # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
0043     # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
0044     HARDENING=-fno-stack-protector
0045 
0046     # Stack Canaries
0047     # Put numbers at the beginning of each stack frame and check that they are the same.
0048     # If a stack buffer if overflowed, it writes over the canary number and then on return
0049     # when that number is checked, it won't be the same and the program will exit with
0050     # a "Stack smashing detected" error instead of being exploited.
0051     HARDENING+=-fstack-protector-all -Wstack-protector
0052 
0053     # Make some important things such as the global offset table read only as soon as
0054     # the dynamic linker is finished building it. This will prevent overwriting of addresses
0055     # which would later be jumped to.
0056     HARDENING+=-Wl,-z,relro -Wl,-z,now
0057 
0058     # Build position independent code to take advantage of Address Space Layout Randomization
0059     # offered by some kernels.
0060     # see doc/build-unix.txt for more information.
0061     ifdef PIE
0062         HARDENING+=-fPIE -pie
0063     endif
0064 
0065     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
0066     # the source such overflowing a statically defined buffer.
0067     HARDENING+=-D_FORTIFY_SOURCE=2
0068 #
0069 
0070 
0071 DEBUGFLAGS=-g
0072 CXXFLAGS=-O2
0073 xCXXFLAGS=-pthread -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
0074 HEADERS = \
0075     base58.h \
0076     bignum.h \
0077     checkpoints.h \
0078     crypter.h \
0079     db.h \
0080     headers.h \
0081     init.h \
0082     key.h \
0083     keystore.h \
0084     knobs.h \
0085     main.h \
0086     net.h \
0087     noui.h \
0088     protocol.h \
0089     bitcoinrpc.h \
0090     script.h \
0091     serialize.h \
0092     strlcpy.h \
0093     uint256.h \
0094     util.h \
0095     wallet.h
0096 
0097 OBJS= \
0098     obj/checkpoints.o \
0099     obj/crypter.o \
0100     obj/db.o \
0101     obj/init.o \
0102     obj/keystore.o \
0103     obj/main.o \
0104     obj/net.o \
0105     obj/protocol.o \
0106     obj/bitcoinrpc.o \
0107     obj/script.o \
0108     obj/util.o \
0109     obj/wallet.o
0110 
0111 
0112 all: bitcoind
0113 
0114 # auto-generated dependencies:
0115 -include obj/nogui/*.P
0116 -include obj-test/*.P
0117 
0118 obj/nogui/%.o: %.cpp
0119         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
0120         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
0121           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
0122               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
0123           rm -f $(@:%.o=%.d)
0124 
0125 bitcoind: $(OBJS:obj/%=obj/nogui/%)
0126         $(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
0127 
0128 obj-test/%.o: test/%.cpp
0129         $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -o $@ $<
0130         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
0131           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
0132               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
0133           rm -f $(@:%.o=%.d)
0134 
0135 test_bitcoin: obj-test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
0136         $(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(LDFLAGS) $(LIBS)
0137 
0138 clean:
0139         -rm -f bitcoind test_bitcoin
0140         -rm -f obj/*.o
0141         -rm -f obj/nogui/*.o
0142         -rm -f obj-test/*.o
0143         -rm -f obj/*.P
0144         -rm -f obj/nogui/*.P
0145         -rm -f obj-test/*.P