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.
10 ARCH:=$(system lscpu | head -n 1 | awk '{print $2}')
12 DEFS=-DBOOST_SPIRIT_THREADSAFE
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))
17 TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
27 TESTDEFS += -DBOOST_TEST_DYN_LINK
30 # for boost 1.37, add -mt to the boost libraries
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) \
44 ifneq (${USE_UPNP}, -)
46 DEFS += -DUSE_UPNP=$(USE_UPNP)
49 ifneq (${USE_IPV6}, -)
50 DEFS += -DUSE_IPV6=$(USE_IPV6)
61 # Make some classes of vulnerabilities unexploitable in case one is discovered.
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
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
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
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.
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
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)
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)
132 obj/rpcblockchain.o \
133 obj/rpcrawtransaction.o \
145 obj/scrypt-x86_64.o \
146 obj/zerocoin/Accumulator.o \
147 obj/zerocoin/AccumulatorProofOfKnowledge.o \
148 obj/zerocoin/Coin.o \
149 obj/zerocoin/CoinSpend.o \
150 obj/zerocoin/Commitment.o \
151 obj/zerocoin/ParamGeneration.o \
152 obj/zerocoin/Params.o \
153 obj/zerocoin/SerialNumberSignatureOfKnowledge.o \
154 obj/zerocoin/SpendMetaData.o \
155 obj/zerocoin/ZeroTest.o
162 ifeq (${USE_LEVELDB}, 1)
163 LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a
164 DEFS += $(addprefix -I,$(CURDIR)/leveldb/include) -DUSE_LEVELDB
165 DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers)
166 OBJS += obj/txdb-leveldb.o
167 leveldb/libleveldb.a:
168 @echo "Building LevelDB ..."; cd leveldb; make libleveldb.a libmemenv.a; cd ..;
169 obj/txdb-leveldb.o: leveldb/libleveldb.a
171 ifneq (${USE_LEVELDB}, 1)
172 OBJS += obj/txdb-bdb.o
175 test check: test_novacoin FORCE
178 # auto-generated dependencies:
180 -include obj-test/*.P
183 /bin/sh ../share/genbuild.sh obj/build.h
184 version.cpp: obj/build.h
185 DEFS += -DHAVE_BUILD_INFO
187 obj/scrypt-x86.o: scrypt-x86.S
188 $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
190 obj/scrypt-x86_64.o: scrypt-x86_64.S
191 $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
194 $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
195 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
196 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
197 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
200 obj/zerocoin/%.o: zerocoin/%.cpp
201 $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
202 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
203 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
204 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
207 novacoind: $(OBJS:obj/%=obj/%)
208 $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
210 TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
212 obj-test/%.o: test/%.cpp
213 $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
214 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
215 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
216 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
219 test_novacoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
220 $(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(xLDFLAGS) $(LIBS)
223 -rm -f novacoind test_novacoin
225 -rm -f obj/zerocoin/*.o
228 -rm -f obj/zerocoin/*.P