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