Remove UPNP support & do some cleanup.
[novacoin.git] / src / makefile.unix
1 # Copyright (c) 2009-2010 Satoshi Nakamoto
2 # Distributed under the MIT/X11 software license, see the accompanying
3 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 USE_LEVELDB:=0
6 USE_IPV6:=1
7
8 LINK:=$(CXX)
9 ARCH:=$(system lscpu | head -n 1 | awk '{print $2}')
10
11 DEFS=-DBOOST_SPIRIT_THREADSAFE -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
12
13 DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
14 LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
15
16 LMODE = dynamic
17 LMODE2 = dynamic
18 ifdef STATIC
19         LMODE = static
20         ifeq (${STATIC}, all)
21                 LMODE2 = static
22         endif
23 endif
24
25 # for boost 1.37, add -mt to the boost libraries
26 LIBS += \
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) \
33    -l ssl \
34    -l crypto
35
36 ifneq (${USE_IPV6}, -)
37         DEFS += -DUSE_IPV6=$(USE_IPV6)
38 endif
39
40 LIBS+= \
41  -Wl,-B$(LMODE2) \
42    -l z \
43    -l dl \
44    -l pthread
45
46
47 # Hardening
48 # Make some classes of vulnerabilities unexploitable in case one is discovered.
49 #
50     # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
51     # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
52     # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
53     HARDENING=-fno-stack-protector
54
55     # Stack Canaries
56     # Put numbers at the beginning of each stack frame and check that they are the same.
57     # If a stack buffer if overflowed, it writes over the canary number and then on return
58     # when that number is checked, it won't be the same and the program will exit with
59     # a "Stack smashing detected" error instead of being exploited.
60     HARDENING+=-fstack-protector-all -Wstack-protector
61
62     # Make some important things such as the global offset table read only as soon as
63     # the dynamic linker is finished building it. This will prevent overwriting of addresses
64     # which would later be jumped to.
65     LDHARDENING+=-Wl,-z,relro -Wl,-z,now
66
67     # Build position independent code to take advantage of Address Space Layout Randomization
68     # offered by some kernels.
69     # see doc/build-unix.txt for more information.
70     ifdef PIE
71         HARDENING+=-fPIE
72         LDHARDENING+=-pie
73     endif
74
75     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
76     # the source such overflowing a statically defined buffer.
77     HARDENING+=-D_FORTIFY_SOURCE=2
78 #
79
80
81 DEBUGFLAGS=-g
82
83
84 ifeq (${ARCH}, i686)
85     EXT_OPTIONS=-msse2
86 endif
87
88 xOPT_LEVEL=-O2
89 ifeq (${USE_O3}, 1)
90     xOPT_LEVEL=-O3
91 endif
92
93 ifeq  (${USE_SSSE3}, 1)
94 # Intrinsic implementation of block copy
95 DEFS += -DUSE_SSSE3
96 xOPT_LEVEL += -mssse3
97 endif
98
99 # CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only
100 # adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work.
101 xCXXFLAGS=$(xOPT_LEVEL) $(EXT_OPTIONS) -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter \
102     $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
103
104 # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
105 # adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
106 xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
107
108 OBJS= \
109     obj/alert.o \
110     obj/version.o \
111     obj/checkpoints.o \
112     obj/netbase.o \
113     obj/addrman.o \
114     obj/crypter.o \
115     obj/key.o \
116     obj/db.o \
117     obj/init.o \
118     obj/irc.o \
119     obj/keystore.o \
120     obj/miner.o \
121     obj/main.o \
122     obj/net.o \
123     obj/ntp.o \
124     obj/stun.o \
125     obj/protocol.o \
126     obj/bitcoinrpc.o \
127     obj/rpcdump.o \
128     obj/rpcnet.o \
129     obj/rpcmining.o \
130     obj/rpcwallet.o \
131     obj/rpcblockchain.o \
132     obj/rpcrawtransaction.o \
133     obj/script.o \
134     obj/sync.o \
135     obj/util.o \
136     obj/wallet.o \
137     obj/walletdb.o \
138     obj/noui.o \
139     obj/kernel.o
140
141 all: novacoind
142
143 #
144 # LevelDB support
145 #
146 ifeq (${USE_LEVELDB}, 1)
147 LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a
148 DEFS += $(addprefix -I,$(CURDIR)/leveldb/include) -DUSE_LEVELDB
149 DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers)
150 OBJS += obj/txdb-leveldb.o
151 leveldb/libleveldb.a:
152         @echo "Building LevelDB ..."; cd leveldb; make libleveldb.a libmemenv.a; cd ..;
153 obj/txdb-leveldb.o: leveldb/libleveldb.a
154 endif
155 ifneq (${USE_LEVELDB}, 1)
156 OBJS += obj/txdb-bdb.o
157 endif
158
159 ifeq (${USE_ASM}, 1)
160 # Assembler implementation
161 OBJS += crypto/scrypt/asm/obj/scrypt-arm.o crypto/scrypt/asm/obj/scrypt-x86.o crypto/scrypt/asm/obj/scrypt-x86_64.o crypto/scrypt/asm/obj/asm-wrapper.o
162 OBJS += crypto/sha2/asm/obj/sha2-arm.o crypto/sha2/asm/obj/sha2-x86.o crypto/sha2/asm/obj/sha2-x86_64.o
163
164 crypto/scrypt/asm/obj/scrypt-x86.o: crypto/scrypt/asm/scrypt-x86.S
165         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
166
167 crypto/scrypt/asm/obj/scrypt-x86_64.o: crypto/scrypt/asm/scrypt-x86_64.S
168         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
169
170 crypto/scrypt/asm/obj/scrypt-arm.o: crypto/scrypt/asm/scrypt-arm.S
171         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
172
173 crypto/scrypt/asm/obj/asm-wrapper.o: crypto/scrypt/asm/asm-wrapper.cpp
174         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
175
176 crypto/sha2/asm/obj/sha2-x86.o: crypto/sha2/asm/sha2-x86.S
177         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
178
179 crypto/sha2/asm/obj/sha2-x86_64.o: crypto/sha2/asm/sha2-x86_64.S
180         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
181
182 crypto/sha2/asm/obj/sha2-arm.o: crypto/sha2/asm/sha2-arm.S
183         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
184
185 DEFS += -DUSE_ASM
186
187 else
188 ifeq  (${USE_SSE2}, 1)
189 # Intrinsic implementation
190 DEFS += -DUSE_SSE2
191 OBJS += crypto/scrypt/intrin/obj/scrypt-sse2.o
192
193 crypto/scrypt/intrin/obj/scrypt-sse2.o: crypto/scrypt/intrin/scrypt-sse2.cpp
194         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
195 else
196 # Generic implementation
197 OBJS += crypto/scrypt/generic/obj/scrypt-generic.o
198
199 crypto/scrypt/generic/obj/scrypt-generic.o: crypto/scrypt/generic/scrypt-generic.cpp
200         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
201 endif
202 endif
203
204
205 # auto-generated dependencies:
206 -include obj/*.P
207
208 obj/build.h: FORCE
209         /bin/sh ../share/genbuild.sh obj/build.h
210 version.cpp: obj/build.h
211 DEFS += -DHAVE_BUILD_INFO
212
213
214 obj/%.o: %.cpp
215         $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
216         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
217           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
218               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
219           rm -f $(@:%.o=%.d)
220
221 novacoind: $(OBJS:obj/%=obj/%)
222         $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
223
224 clean:
225         -rm -f novacoind
226         -rm -f obj/*.o
227         -rm -f obj/*.P
228         -rm -f obj/*.d
229         -rm -f crypto/scrypt/asm/obj/*.o
230         -rm -f crypto/scrypt/asm/obj/*.P
231         -rm -f crypto/scrypt/asm/obj/*.d
232         -rm -f crypto/scrypt/intrin/obj/*.o
233         -rm -f crypto/scrypt/intrin/obj/*.P
234         -rm -f crypto/scrypt/intrin/obj/*.d
235         -rm -f crypto/scrypt/generic/obj/*.o
236         -rm -f crypto/scrypt/generic/obj/*.P
237         -rm -f crypto/scrypt/generic/obj/*.d
238         -rm -f crypto/sha2/asm/obj/*.o
239         -rm -f crypto/sha2/asm/obj/*.P
240         -rm -f crypto/sha2/asm/obj/*.d
241         -rm -f obj/build.h
242
243 FORCE: