Remove netbase.h from util header: create timedata files.
[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_LEVELDB:=0
6
7 # CC=clang
8 # CXX=clang++
9
10 LINK:=$(CXX)
11 ARCH:=$(shell uname -m)
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
38 LIBS+= \
39  -Wl,-B$(LMODE2) \
40    -l z \
41    -l dl \
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
82 ifeq (${ARCH}, i686)
83     EXT_OPTIONS=-msse2
84 endif
85
86 xOPT_LEVEL=-O2
87 ifeq (${USE_O3}, 1)
88     xOPT_LEVEL=-O3
89 endif
90
91 # CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only
92 # adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work.
93 xCXXFLAGS=$(xOPT_LEVEL) $(EXT_OPTIONS) -std=c++11 -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter \
94     $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
95
96 # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
97 # adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
98 xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
99
100 OBJS= \
101     obj/alert.o \
102     obj/version.o \
103     obj/checkpoints.o \
104     obj/netbase.o \
105     obj/addrman.o \
106     obj/crypter.o \
107     obj/base58.o \
108     obj/key.o \
109     obj/db.o \
110     obj/init.o \
111     obj/irc.o \
112     obj/keystore.o \
113     obj/miner.o \
114     obj/main.o \
115     obj/net.o \
116     obj/ntp.o \
117     obj/stun.o \
118     obj/protocol.o \
119     obj/bitcoinrpc.o \
120     obj/rpccrypt.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/timedata.o \
130     obj/util.o \
131     obj/wallet.o \
132     obj/walletdb.o \
133     obj/noui.o \
134     obj/kernel.o \
135     obj/uint256.o \
136     obj/kernel_worker.o \
137     obj/ecies.o \
138     obj/cryptogram.o \
139     obj/ipcollector.o \
140     obj/serialize.o
141
142 all: novacoind
143
144 #
145 # LevelDB support
146 #
147 ifeq (${USE_LEVELDB}, 1)
148 LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a
149 DEFS += $(addprefix -I,$(CURDIR)/leveldb/include) -DUSE_LEVELDB
150 DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers)
151 OBJS += obj/txdb-leveldb.o
152 leveldb/libleveldb.a:
153         @echo "Building LevelDB ..."; cd leveldb; CC=$(CC) CXX=$(CXX) make libleveldb.a libmemenv.a; cd ..;
154 obj/txdb-leveldb.o: leveldb/libleveldb.a
155 endif
156 ifneq (${USE_LEVELDB}, 1)
157 OBJS += obj/txdb-bdb.o
158 endif
159
160 ifeq (${USE_ASM}, 1)
161 # Assembler implementation
162 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
163
164 crypto/scrypt/asm/obj/scrypt-x86.o: crypto/scrypt/asm/scrypt-x86.S
165         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
166
167 crypto/scrypt/asm/obj/scrypt-x86_64.o: crypto/scrypt/asm/scrypt-x86_64.S
168         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
169
170 crypto/scrypt/asm/obj/scrypt-arm.o: crypto/scrypt/asm/scrypt-arm.S
171         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
172
173 crypto/scrypt/asm/obj/asm-wrapper.o: crypto/scrypt/asm/asm-wrapper.cpp
174         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
175
176 DEFS += -DUSE_ASM
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
196 # auto-generated dependencies:
197 -include obj/*.P
198
199 obj/build.h: FORCE
200         /bin/sh ../share/genbuild.sh obj/build.h
201 version.cpp: obj/build.h
202 DEFS += -DHAVE_BUILD_INFO
203
204
205 obj/%.o: %.cpp
206         $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
207         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
208           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
209               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
210           rm -f $(@:%.o=%.d)
211
212 novacoind: $(OBJS:obj/%=obj/%)
213         $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
214
215 clean:
216         -rm -f novacoind
217         -rm -f obj/*.o
218         -rm -f obj/*.P
219         -rm -f obj/*.d
220         -rm -f crypto/scrypt/asm/obj/*.o
221         -rm -f crypto/scrypt/asm/obj/*.P
222         -rm -f crypto/scrypt/asm/obj/*.d
223         -rm -f crypto/scrypt/intrin/obj/*.o
224         -rm -f crypto/scrypt/intrin/obj/*.P
225         -rm -f crypto/scrypt/intrin/obj/*.d
226         -rm -f crypto/scrypt/generic/obj/*.o
227         -rm -f crypto/scrypt/generic/obj/*.P
228         -rm -f crypto/scrypt/generic/obj/*.d
229         -rm -f obj/build.h
230
231 FORCE: