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