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