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