-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile.unix
384 lines (329 loc) · 10.4 KB
/
makefile.unix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# Copyright (c) 2009-2010 Satoshi Nakamoto
# Distributed under the MIT/X11 software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
INCLUDEPATHS= \
-I"$(CURDIR)" \
-I"$(CURDIR)/obj" \
-I"$(CURDIR)/tor" \
-I"$(CURDIR)/tor/adapter" \
-I"$(CURDIR)/tor/common" \
-I"$(CURDIR)/tor/ext" \
-I"$(CURDIR)/tor/ext/curve25519_donna" \
-I"$(CURDIR)/tor/or" \
-I"$(INC_LINUX)" \
-I"$(CURDIR)/leveldb/include" \
-I"$(CURDIR)/leveldb/helpers" \
-I"$(CURDIR)/json" \
-I"$(CURDIR)/secp256k1/include"
CFLAGS += $(INCLUDEPATHS)
USE_UPNP:=-
USE_IPV6:=-
STATIC:=1
LINK:=$(CXX)
ARCH:=$(system lscpu | head -n 1 | awk '{print $2}')
DEFS=-DBOOST_SPIRIT_THREADSAFE
DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
LIBS += $(addprefix -L,"$(CURDIR)/secp256k1/lib")
TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
LMODE = dynamic
LMODE2 = dynamic
ifdef STATIC
LMODE = static
ifeq (${STATIC}, all)
LMODE2 = static
endif
else
TESTDEFS += -DBOOST_TEST_DYN_LINK
endif
# for boost 1.37, add -mt to the boost libraries
LIBS += \
-Wl,-B$(LMODE) \
-l boost_system$(BOOST_LIB_SUFFIX) \
-l boost_filesystem$(BOOST_LIB_SUFFIX) \
-l boost_program_options$(BOOST_LIB_SUFFIX) \
-l boost_thread$(BOOST_LIB_SUFFIX) \
-l db_cxx$(BDB_LIB_SUFFIX) \
-l ssl \
-l crypto \
-l secp256k1 \
-l gmp
ifndef USE_UPNP
override USE_UPNP = -
endif
ifneq (${USE_UPNP}, -)
LIBS += -l miniupnpc
DEFS += -DUSE_UPNP=$(USE_UPNP)
endif
LIBS+= \
-Wl,-B$(LMODE2) \
-l event \
-l z \
-l dl \
-l pthread \
TESTLIBS += \
-Wl,-B$(LMODE) \
-l boost_unit_test_framework$(BOOST_LIB_SUFFIX)
# Hardening
# Make some classes of vulnerabilities unexploitable in case one is discovered.
#
# This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
# -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
# see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
HARDENING=-fno-stack-protector
# Stack Canaries
# Put numbers at the beginning of each stack frame and check that they are the same.
# If a stack buffer if overflowed, it writes over the canary number and then on return
# when that number is checked, it won't be the same and the program will exit with
# a "Stack smashing detected" error instead of being exploited.
HARDENING+=-fstack-protector-all -Wstack-protector
# Make some important things such as the global offset table read only as soon as
# the dynamic linker is finished building it. This will prevent overwriting of addresses
# which would later be jumped to.
LDHARDENING+=-Wl,-z,relro -Wl,-z,now
# Build position independent code to take advantage of Address Space Layout Randomization
# offered by some kernels.
# see doc/build-unix.txt for more information.
ifdef PIE
HARDENING+=-fPIE
LDHARDENING+=-pie
endif
# -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
# the source such overflowing a statically defined buffer.
HARDENING+=-D_FORTIFY_SOURCE=2
#
DEBUGFLAGS=-g
ifeq (${ARCH}, i686)
EXT_OPTIONS=-msse2
endif
# CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only
# adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work.
xCXXFLAGS=-O2 $(EXT_OPTIONS) -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter \
$(DEBUGFLAGS) $(DEFS) $(HARDENING) $(INCLUDEPATHS) $(CXXFLAGS)
# LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
# adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
OBJS= \
obj/address.o \
obj/addressmap.o \
obj/aes.o \
obj/backtrace.o \
obj/buffers.o \
obj/channel.o \
obj/channeltls.o \
obj/circpathbias.o \
obj/circuitbuild.o \
obj/circuitlist.o \
obj/circuitmux.o \
obj/circuitmux_ewma.o \
obj/circuitstats.o \
obj/circuituse.o \
obj/command.o \
obj/tor_compat.o \
obj/compat_libevent.o \
obj/config.o \
obj/config_codedigest.o \
obj/confparse.o \
obj/connection.o \
obj/connection_edge.o \
obj/connection_or.o \
obj/container.o \
obj/control.o \
obj/cpuworker.o \
obj/crypto.o \
obj/csiphash.o \
obj/crypto_curve25519.o \
obj/crypto_format.o \
obj/curve25519-donna.o \
obj/di_ops.o \
obj/directory.o \
obj/dirserv.o \
obj/dirvote.o \
obj/dns.o \
obj/dnsserv.o \
obj/entrynodes.o \
obj/ext_orport.o \
obj/fp_pair.o \
obj/geoip.o \
obj/hibernate.o \
obj/log.o \
obj/memarea.o \
obj/mempool.o \
obj/microdesc.o \
obj/networkstatus.o \
obj/nodelist.o \
obj/onion.o \
obj/onion_fast.o \
obj/onion_main.o \
obj/onion_ntor.o \
obj/onion_tap.o \
obj/policies.o \
obj/procmon.o \
obj/reasons.o \
obj/relay.o \
obj/rendclient.o \
obj/rendcommon.o \
obj/rendmid.o \
obj/rendservice.o \
obj/rephist.o \
obj/replaycache.o \
obj/router.o \
obj/routerlist.o \
obj/routerparse.o \
obj/routerset.o \
obj/sandbox.o \
obj/statefile.o \
obj/status.o \
obj/tor_util.o \
obj/torgzip.o \
obj/tortls.o \
obj/tor_main.o \
obj/transports.o \
obj/util_codedigest.o \
obj/util_process.o \
obj/alert.o \
obj/version.o \
obj/checkpoints.o \
obj/netbase.o \
obj/addrman.o \
obj/crypter.o \
obj/key.o \
obj/eckey.o \
obj/extkey.o \
obj/db.o \
obj/init.o \
obj/eclipsed.o \
obj/keystore.o \
obj/miner.o \
obj/main.o \
obj/net.o \
obj/protocol.o \
obj/rpcprotocol.o \
obj/rpcserver.o \
obj/rpcclient.o \
obj/rpcdump.o \
obj/rpcnet.o \
obj/rpcmining.o \
obj/rpcwallet.o \
obj/rpcblockchain.o \
obj/rpcrawtransaction.o \
obj/rpcsmessage.o \
obj/rpcextkey.o \
obj/rpcmnemonic.o \
obj/script.o \
obj/sync.o \
obj/util.o \
obj/hash.o \
obj/wallet.o \
obj/walletdb.o \
obj/noui.o \
obj/kernel.o \
obj/pbkdf2.o \
obj/scrypt.o \
obj/scrypt-arm.o \
obj/scrypt-x86.o \
obj/scrypt-x86_64.o \
obj/smessage.o \
obj/stealth.o \
obj/sigringu.o \
obj/core.o \
obj/txmempool.o \
obj/chainparams.o \
obj/state.o \
obj/bloom.o
all: eclipsed
test check: test_eclipse FORCE
./test_eclipse
LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a
DEFS += $(addprefix -I,$(CURDIR)/leveldb/include)
DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers)
OBJS += obj/txdb-leveldb.o
leveldb/libleveldb.a:
@echo "Building LevelDB ..."; cd leveldb; make libleveldb.a libmemenv.a; cd ..;
obj/txdb-leveldb.o: leveldb/libleveldb.a
LIBS += $(CURDIR)/secp256k1/lib/libsecp256k1.a /usr/local/lib/libgmp.a
# auto-generated dependencies:
-include obj/*.P
obj/build.h: FORCE
/bin/sh ../share/genbuild.sh obj/build.h
version.cpp: obj/build.h
DEFS += -DHAVE_BUILD_INFO
obj/%.o: %.cpp
$(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
rm -f $(@:%.o=%.d)
obj/%.o: json/%.cpp
$(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
rm -f $(@:%.o=%.d)
obj/%.o: %.c
$(CC) -c $(CFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
rm -f $(@:%.o=%.d)
obj/%.o: tor/common/%.c
$(CC) -c $(CFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
rm -f $(@:%.o=%.d)
obj/%.o: tor/ext/%.c
$(CC) -c $(CFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
rm -f $(@:%.o=%.d)
obj/%.o: tor/ext/curve25519_donna/%.c
$(CC) -c $(CFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
rm -f $(@:%.o=%.d)
obj/%.o: tor/or/%.c
$(CC) -c $(CFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
rm -f $(@:%.o=%.d)
obj/eclipse.o: tor/adapter/eclipse.cpp
$(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
rm -f $(@:%.o=%.d)
obj/scrypt-x86.o: scrypt-x86.S
$(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
obj/scrypt-x86_64.o: scrypt-x86_64.S
$(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
obj/scrypt-arm.o: scrypt-arm.S
$(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
secp256k1/lib/libsecp256k1.a:
cd secp256k1/secp256k1; ./autogen.sh; ./configure --prefix=`pwd`/..; make; make install
eclipsed: secp256k1/lib/libsecp256k1.a leveldb/libleveldb.a \
$(OBJS:obj/%=obj/%) obj/eclipse.o
$(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ $(xLDFLAGS) $(LIBS)
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
xTESTCXXFLAGS = -std=c++11
obj-test/%.o: test/%.cpp
$(CXX) -c $(TESTDEFS) $(xTESTCXXFLAGS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
rm -f $(@:%.o=%.d)
test_eclipse: $(TESTOBJS) $(filter-out obj/init.o obj/eclipsed.o,$(OBJS:obj/%=obj/%))
$(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ $(TESTLIBS) $(xLDFLAGS) $(LIBS)
clean:
-rm -f eclipsed
-rm -f obj/*.o
-rm -f obj/*.P
-rm -f obj/build.h
-rm -f test_eclipse
-rm -f obj-test/*.o
-rm -f obj-test/*.P
-cd leveldb && $(MAKE) clean || true
FORCE: