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