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