af350f95c53c4970ae656e0c8d96708342aefb3e
[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_UPNP:=0
6 USE_IPV6:=1
7 USE_LEVELDB:=1
8
9 LINK:=$(CXX)
10 ARCH:=$(system lscpu | head -n 1 | awk '{print $2}')
11
12 DEFS=-DBOOST_SPIRIT_THREADSAFE
13
14 DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
15 LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
16
17 TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
18
19 LMODE = dynamic
20 LMODE2 = dynamic
21 ifdef STATIC
22         LMODE = static
23         ifeq (${STATIC}, all)
24                 LMODE2 = static
25         endif
26 else
27         TESTDEFS += -DBOOST_TEST_DYN_LINK
28 endif
29
30 # for boost 1.37, add -mt to the boost libraries
31 LIBS += \
32  -Wl,-B$(LMODE) \
33    -l boost_system$(BOOST_LIB_SUFFIX) \
34    -l boost_filesystem$(BOOST_LIB_SUFFIX) \
35    -l boost_program_options$(BOOST_LIB_SUFFIX) \
36    -l boost_thread$(BOOST_LIB_SUFFIX) \
37    -l db_cxx$(BDB_LIB_SUFFIX) \
38    -l ssl \
39    -l crypto
40
41 ifndef USE_UPNP
42         override USE_UPNP = -
43 endif
44 ifneq (${USE_UPNP}, -)
45         LIBS += -l miniupnpc
46         DEFS += -DUSE_UPNP=$(USE_UPNP)
47 endif
48
49 ifneq (${USE_IPV6}, -)
50         DEFS += -DUSE_IPV6=$(USE_IPV6)
51 endif
52
53 LIBS+= \
54  -Wl,-B$(LMODE2) \
55    -l z \
56    -l dl \
57    -l pthread
58
59
60 # Hardening
61 # Make some classes of vulnerabilities unexploitable in case one is discovered.
62 #
63     # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
64     # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
65     # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
66     HARDENING=-fno-stack-protector
67
68     # Stack Canaries
69     # Put numbers at the beginning of each stack frame and check that they are the same.
70     # If a stack buffer if overflowed, it writes over the canary number and then on return
71     # when that number is checked, it won't be the same and the program will exit with
72     # a "Stack smashing detected" error instead of being exploited.
73     HARDENING+=-fstack-protector-all -Wstack-protector
74
75     # Make some important things such as the global offset table read only as soon as
76     # the dynamic linker is finished building it. This will prevent overwriting of addresses
77     # which would later be jumped to.
78     LDHARDENING+=-Wl,-z,relro -Wl,-z,now
79
80     # Build position independent code to take advantage of Address Space Layout Randomization
81     # offered by some kernels.
82     # see doc/build-unix.txt for more information.
83     ifdef PIE
84         HARDENING+=-fPIE
85         LDHARDENING+=-pie
86     endif
87
88     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
89     # the source such overflowing a statically defined buffer.
90     HARDENING+=-D_FORTIFY_SOURCE=2
91 #
92
93
94 DEBUGFLAGS=-g
95
96
97 ifeq (${ARCH}, i686)
98     EXT_OPTIONS=-msse2
99 endif
100
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=-O2 $(EXT_OPTIONS) -fopenmp -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/miner.o \
124     obj/main.o \
125     obj/net.o \
126     obj/protocol.o \
127     obj/bitcoinrpc.o \
128     obj/rpcdump.o \
129     obj/rpcnet.o \
130     obj/rpcmining.o \
131     obj/rpcwallet.o \
132     obj/rpcblockchain.o \
133     obj/rpcrawtransaction.o \
134     obj/script.o \
135     obj/sync.o \
136     obj/util.o \
137     obj/wallet.o \
138     obj/walletdb.o \
139     obj/noui.o \
140     obj/kernel.o \
141     obj/pbkdf2.o \
142     obj/scrypt.o \
143     obj/scrypt-x86.o \
144     obj/scrypt-x86_64.o \
145     obj/zerocoin/Accumulator.o \
146     obj/zerocoin/AccumulatorProofOfKnowledge.o \
147     obj/zerocoin/Coin.o \
148     obj/zerocoin/CoinSpend.o \
149     obj/zerocoin/Commitment.o \
150     obj/zerocoin/ParamGeneration.o \
151     obj/zerocoin/Params.o \
152     obj/zerocoin/SerialNumberSignatureOfKnowledge.o \
153     obj/zerocoin/SpendMetaData.o \
154     obj/zerocoin/ZeroTest.o
155
156 all: novacoind
157
158 #
159 # LevelDB support
160 #
161 ifeq (${USE_LEVELDB}, 1)
162 LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a
163 DEFS += $(addprefix -I,$(CURDIR)/leveldb/include) -DUSE_LEVELDB
164 DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers)
165 OBJS += obj/txdb-leveldb.o
166 leveldb/libleveldb.a:
167         @echo "Building LevelDB ..."; cd leveldb; make libleveldb.a libmemenv.a; cd ..;
168 obj/txdb-leveldb.o: leveldb/libleveldb.a
169 endif
170 ifneq (${USE_LEVELDB}, 1)
171 OBJS += obj/txdb-bdb.o
172 endif
173
174 test check: test_novacoin FORCE
175         ./test_novacoin
176
177 # auto-generated dependencies:
178 -include obj/*.P
179 -include obj-test/*.P
180
181 obj/build.h: FORCE
182         /bin/sh ../share/genbuild.sh obj/build.h
183 version.cpp: obj/build.h
184 DEFS += -DHAVE_BUILD_INFO
185
186 obj/scrypt-x86.o: scrypt-x86.S
187         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
188
189 obj/scrypt-x86_64.o: scrypt-x86_64.S
190         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
191
192 obj/%.o: %.cpp
193         $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
194         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
195           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
196               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
197           rm -f $(@:%.o=%.d)
198
199 obj/zerocoin/%.o: zerocoin/%.cpp
200         $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
201         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
202           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
203               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
204           rm -f $(@:%.o=%.d)
205
206 novacoind: $(OBJS:obj/%=obj/%)
207         $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
208
209 TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
210
211 obj-test/%.o: test/%.cpp
212         $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
213         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
214           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
215               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
216           rm -f $(@:%.o=%.d)
217
218 test_novacoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
219         $(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(xLDFLAGS) $(LIBS)
220
221 clean:
222         -rm -f novacoind test_novacoin
223         -rm -f obj/*.o
224         -rm -f obj/zerocoin/*.o
225         -rm -f obj-test/*.o
226         -rm -f obj/*.P
227         -rm -f obj/zerocoin/*.P
228         -rm -f obj-test/*.P
229         -rm -f obj/build.h
230
231 FORCE: