]>
Commit | Line | Data |
---|---|---|
0a61b0df | 1 | # Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | # Distributed under the MIT/X11 software license, see the accompanying | |
90d95b63 | 3 | # file COPYING or http://www.opensource.org/licenses/mit-license.php. |
0a61b0df | 4 | |
3f0950ea MC |
5 | USE_UPNP:=0 |
6 | ||
7b671f52 | 7 | DEFS=-DUSE_IPV6 -DBOOST_SPIRIT_THREADSAFE |
b4d0588d | 8 | |
45771671 | 9 | DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH)) |
7dcd2004 | 10 | LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH)) |
b4d0588d | 11 | |
9e71a5cd GA |
12 | TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data) |
13 | ||
b4d0588d LD |
14 | LMODE = dynamic |
15 | LMODE2 = dynamic | |
16 | ifdef STATIC | |
17 | LMODE = static | |
18 | ifeq (${STATIC}, all) | |
19 | LMODE2 = static | |
20 | endif | |
ca9afa84 LD |
21 | else |
22 | TESTDEFS += -DBOOST_TEST_DYN_LINK | |
b4d0588d | 23 | endif |
8bb5edc1 | 24 | |
0a61b0df | 25 | # for boost 1.37, add -mt to the boost libraries |
7dcd2004 | 26 | LIBS += \ |
b4d0588d LD |
27 | -Wl,-B$(LMODE) \ |
28 | -l boost_system$(BOOST_LIB_SUFFIX) \ | |
29 | -l boost_filesystem$(BOOST_LIB_SUFFIX) \ | |
30 | -l boost_program_options$(BOOST_LIB_SUFFIX) \ | |
31 | -l boost_thread$(BOOST_LIB_SUFFIX) \ | |
32 | -l db_cxx$(BDB_LIB_SUFFIX) \ | |
ed54768f | 33 | -l ssl \ |
8bb5edc1 MC |
34 | -l crypto |
35 | ||
b4d0588d LD |
36 | ifndef USE_UPNP |
37 | override USE_UPNP = - | |
38 | endif | |
39 | ifneq (${USE_UPNP}, -) | |
3f0950ea MC |
40 | LIBS += -l miniupnpc |
41 | DEFS += -DUSE_UPNP=$(USE_UPNP) | |
42 | endif | |
8bb5edc1 MC |
43 | |
44 | LIBS+= \ | |
b4d0588d | 45 | -Wl,-B$(LMODE2) \ |
2fad3d34 | 46 | -l z \ |
1a5364bd RC |
47 | -l dl \ |
48 | -l pthread | |
0a61b0df | 49 | |
8bb5edc1 | 50 | |
3f94dfa2 | 51 | # Hardening |
52 | # Make some classes of vulnerabilities unexploitable in case one is discovered. | |
53 | # | |
1e5f9393 | 54 | # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes |
55 | # -fstack-protector-all to be ignored unless -fno-stack-protector is used first. | |
56 | # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722 | |
57 | HARDENING=-fno-stack-protector | |
58 | ||
3f94dfa2 | 59 | # Stack Canaries |
60 | # Put numbers at the beginning of each stack frame and check that they are the same. | |
61 | # If a stack buffer if overflowed, it writes over the canary number and then on return | |
62 | # when that number is checked, it won't be the same and the program will exit with | |
63 | # a "Stack smashing detected" error instead of being exploited. | |
1e5f9393 | 64 | HARDENING+=-fstack-protector-all -Wstack-protector |
3f94dfa2 | 65 | |
66 | # Make some important things such as the global offset table read only as soon as | |
67 | # the dynamic linker is finished building it. This will prevent overwriting of addresses | |
68 | # which would later be jumped to. | |
f04f2450 | 69 | LDHARDENING+=-Wl,-z,relro -Wl,-z,now |
3f94dfa2 | 70 | |
71 | # Build position independent code to take advantage of Address Space Layout Randomization | |
72 | # offered by some kernels. | |
73 | # see doc/build-unix.txt for more information. | |
74 | ifdef PIE | |
f04f2450 GS |
75 | HARDENING+=-fPIE |
76 | LDHARDENING+=-pie | |
3f94dfa2 | 77 | endif |
78 | ||
79 | # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in | |
80 | # the source such overflowing a statically defined buffer. | |
81 | HARDENING+=-D_FORTIFY_SOURCE=2 | |
82 | # | |
83 | ||
84 | ||
565c4771 | 85 | DEBUGFLAGS=-g |
a6cd0b08 PW |
86 | |
87 | # CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only | |
88 | # adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work. | |
89 | xCXXFLAGS=-O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \ | |
90 | $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS) | |
0a61b0df | 91 | |
f04f2450 GS |
92 | # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only |
93 | # adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work. | |
94 | xLDFLAGS=$(LDHARDENING) $(LDFLAGS) | |
95 | ||
0a61b0df | 96 | OBJS= \ |
a20c0d0f | 97 | obj/version.o \ |
eb5fff9e | 98 | obj/checkpoints.o \ |
67a42f92 | 99 | obj/netbase.o \ |
5fee401f | 100 | obj/addrman.o \ |
e49b83bb | 101 | obj/crypter.o \ |
93db3fce | 102 | obj/key.o \ |
0a61b0df | 103 | obj/db.o \ |
e49b83bb | 104 | obj/init.o \ |
0a61b0df | 105 | obj/irc.o \ |
e89b9f6a | 106 | obj/keystore.o \ |
0a61b0df | 107 | obj/main.o \ |
e49b83bb | 108 | obj/net.o \ |
507fd9d1 | 109 | obj/protocol.o \ |
e122e423 | 110 | obj/bitcoinrpc.o \ |
95d888a6 | 111 | obj/rpcdump.o \ |
70ab73a0 | 112 | obj/rpcnet.o \ |
a2709fad | 113 | obj/rpcrawtransaction.o \ |
e49b83bb | 114 | obj/script.o \ |
7f3ccb59 | 115 | obj/sync.o \ |
e49b83bb | 116 | obj/util.o \ |
5cccb13d | 117 | obj/wallet.o \ |
9eace6b1 | 118 | obj/walletdb.o \ |
5cccb13d | 119 | obj/noui.o |
0a61b0df | 120 | |
121 | ||
565c4771 | 122 | all: bitcoind |
0a61b0df | 123 | |
4ffbdcc0 | 124 | # auto-generated dependencies: |
a1de57a0 | 125 | -include obj/*.P |
34c69036 | 126 | -include obj-test/*.P |
0a61b0df | 127 | |
45771671 | 128 | obj/build.h: FORCE |
8c35bfba | 129 | /bin/sh ../share/genbuild.sh obj/build.h |
45771671 | 130 | version.cpp: obj/build.h |
a20c0d0f PW |
131 | DEFS += -DHAVE_BUILD_INFO |
132 | ||
a1de57a0 | 133 | obj/%.o: %.cpp |
4d9c55da | 134 | $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $< |
4ffbdcc0 GA |
135 | @cp $(@:%.o=%.d) $(@:%.o=%.P); \ |
136 | sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ | |
137 | -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ | |
138 | rm -f $(@:%.o=%.d) | |
0a61b0df | 139 | |
45771671 | 140 | bitcoind: $(OBJS:obj/%=obj/%) |
f04f2450 | 141 | $(CXX) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS) |
0a61b0df | 142 | |
34c69036 | 143 | TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp)) |
1466b8b7 | 144 | |
34c69036 | 145 | obj-test/%.o: test/%.cpp |
4d9c55da | 146 | $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $< |
4ffbdcc0 GA |
147 | @cp $(@:%.o=%.d) $(@:%.o=%.P); \ |
148 | sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ | |
149 | -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ | |
150 | rm -f $(@:%.o=%.d) | |
8baf865c | 151 | |
a1de57a0 | 152 | test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) |
f04f2450 | 153 | $(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(xLDFLAGS) $(LIBS) |
0a61b0df | 154 | |
155 | clean: | |
565c4771 | 156 | -rm -f bitcoind test_bitcoin |
0a61b0df | 157 | -rm -f obj/*.o |
34c69036 | 158 | -rm -f obj-test/*.o |
4ffbdcc0 | 159 | -rm -f obj/*.P |
34c69036 | 160 | -rm -f obj-test/*.P |
a20c0d0f PW |
161 | -rm -f src/build.h |
162 | ||
163 | FORCE: |