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 -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
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))
26 # for boost 1.37, add -mt to the boost libraries
29 -l boost_system$(BOOST_LIB_SUFFIX) \
30 -l boost_filesystem$(BOOST_LIB_SUFFIX) \
31 -l boost_program_options$(BOOST_LIB_SUFFIX) \
32 -l boost_thread$(BOOST_LIB_SUFFIX) \
33 -l db_cxx$(BDB_LIB_SUFFIX) \
40 ifneq (${USE_UPNP}, -)
42 DEFS += -DUSE_UPNP=$(USE_UPNP)
45 ifneq (${USE_IPV6}, -)
46 DEFS += -DUSE_IPV6=$(USE_IPV6)
57 # Make some classes of vulnerabilities unexploitable in case one is discovered.
59 # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
60 # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
61 # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
62 HARDENING=-fno-stack-protector
65 # Put numbers at the beginning of each stack frame and check that they are the same.
66 # If a stack buffer if overflowed, it writes over the canary number and then on return
67 # when that number is checked, it won't be the same and the program will exit with
68 # a "Stack smashing detected" error instead of being exploited.
69 HARDENING+=-fstack-protector-all -Wstack-protector
71 # Make some important things such as the global offset table read only as soon as
72 # the dynamic linker is finished building it. This will prevent overwriting of addresses
73 # which would later be jumped to.
74 LDHARDENING+=-Wl,-z,relro -Wl,-z,now
76 # Build position independent code to take advantage of Address Space Layout Randomization
77 # offered by some kernels.
78 # see doc/build-unix.txt for more information.
84 # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
85 # the source such overflowing a statically defined buffer.
86 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=$(xOPT_LEVEL) $(EXT_OPTIONS) -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)
134 obj/rpcblockchain.o \
135 obj/rpcrawtransaction.o \
149 ifeq (${USE_LEVELDB}, 1)
150 LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a
151 DEFS += $(addprefix -I,$(CURDIR)/leveldb/include) -DUSE_LEVELDB
152 DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers)
153 OBJS += obj/txdb-leveldb.o
154 leveldb/libleveldb.a:
155 @echo "Building LevelDB ..."; cd leveldb; make libleveldb.a libmemenv.a; cd ..;
156 obj/txdb-leveldb.o: leveldb/libleveldb.a
158 ifneq (${USE_LEVELDB}, 1)
159 OBJS += obj/txdb-bdb.o
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
166 crypto/scrypt/asm/obj/scrypt-x86.o: crypto/scrypt/asm/scrypt-x86.S
167 $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
169 crypto/scrypt/asm/obj/scrypt-x86_64.o: crypto/scrypt/asm/scrypt-x86_64.S
170 $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
172 crypto/scrypt/asm/obj/scrypt-arm.o: crypto/scrypt/asm/scrypt-arm.S
173 $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
175 crypto/scrypt/asm/obj/asm-wrapper.o: crypto/scrypt/asm/asm-wrapper.cpp
176 $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
178 ifeq (${USE_SSE2}, 1)
179 # Intrinsic implementation
181 OBJS += crypto/scrypt/intrin/obj/scrypt-sse2.o
183 crypto/scrypt/intrin/obj/scrypt-sse2.o: crypto/scrypt/intrin/scrypt-sse2.cpp
184 $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
186 # Generic implementation
187 OBJS += crypto/scrypt/generic/obj/scrypt-generic.o
189 crypto/scrypt/generic/obj/scrypt-generic.o: crypto/scrypt/generic/scrypt-generic.cpp
190 $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
195 # auto-generated dependencies:
199 /bin/sh ../share/genbuild.sh obj/build.h
200 version.cpp: obj/build.h
201 DEFS += -DHAVE_BUILD_INFO
205 $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
206 @cp $(@:%.o=%.d) $(@:%.o=%.P); \
207 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
208 -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
211 novacoind: $(OBJS:obj/%=obj/%)
212 $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
219 -rm -f crypto/scrypt/asm/obj/*.o
220 -rm -f crypto/scrypt/asm/obj/*.P
221 -rm -f crypto/scrypt/asm/obj/*.d
222 -rm -f crypto/scrypt/intrin/obj/*.o
223 -rm -f crypto/scrypt/intrin/obj/*.P
224 -rm -f crypto/scrypt/intrin/obj/*.d
225 -rm -f crypto/scrypt/generic/obj/*.o
226 -rm -f crypto/scrypt/generic/obj/*.P
227 -rm -f crypto/scrypt/generic/obj/*.d