Bump version to 0.3.4
[novacoin.git] / src / makefile.unix
1 # Copyright (c) 2009-2010 Satoshi Nakamoto
2 # Copyright (c) 2011-2012 The PPCoin developers
3 # Distributed under the MIT/X11 software license, see the accompanying
4 # file license.txt or http://www.opensource.org/licenses/mit-license.php.
5
6 USE_UPNP:=0
7 STATIC:=1
8
9 DEFS=-DBOOST_SPIRIT_THREADSAFE
10
11 DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
12 LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
13
14 TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
15
16 LMODE = dynamic
17 LMODE2 = dynamic
18 ifdef STATIC
19         LMODE = static
20         ifeq (${STATIC}, all)
21                 LMODE2 = static
22         endif
23 else
24         TESTDEFS += -DBOOST_TEST_DYN_LINK
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 ifndef USE_UPNP
39         override USE_UPNP = -
40 endif
41 ifneq (${USE_UPNP}, -)
42         LIBS += -l miniupnpc
43         DEFS += -DUSE_UPNP=$(USE_UPNP)
44 endif
45
46 LIBS+= \
47  -Wl,-B$(LMODE2) \
48    -l z \
49    -l dl \
50    -l pthread
51
52
53 # Hardening
54 # Make some classes of vulnerabilities unexploitable in case one is discovered.
55 #
56     # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
57     # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
58     # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
59     HARDENING=-fno-stack-protector
60
61     # Stack Canaries
62     # Put numbers at the beginning of each stack frame and check that they are the same.
63     # If a stack buffer if overflowed, it writes over the canary number and then on return
64     # when that number is checked, it won't be the same and the program will exit with
65     # a "Stack smashing detected" error instead of being exploited.
66     HARDENING+=-fstack-protector-all -Wstack-protector
67
68     # Make some important things such as the global offset table read only as soon as
69     # the dynamic linker is finished building it. This will prevent overwriting of addresses
70     # which would later be jumped to.
71     HARDENING+=-Wl,-z,relro -Wl,-z,now
72
73     # Build position independent code to take advantage of Address Space Layout Randomization
74     # offered by some kernels.
75     # see doc/build-unix.txt for more information.
76     ifdef PIE
77         HARDENING+=-fPIE -pie
78     endif
79
80     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
81     # the source such overflowing a statically defined buffer.
82     HARDENING+=-D_FORTIFY_SOURCE=2
83 #
84
85
86 DEBUGFLAGS=-g
87 CXXFLAGS=-O2 -msse2
88 xCXXFLAGS=-pthread -Wall -Wextra -Wno-sign-compare -Wno-invalid-offsetof -Wno-unused-parameter -Wformat -Wformat-security \
89     $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
90
91 OBJS= \
92     obj/version.o \
93     obj/checkpoints.o \
94     obj/netbase.o \
95     obj/addrman.o \
96     obj/crypter.o \
97     obj/key.o \
98     obj/db.o \
99     obj/init.o \
100     obj/irc.o \
101     obj/keystore.o \
102     obj/main.o \
103     obj/net.o \
104     obj/protocol.o \
105     obj/bitcoinrpc.o \
106     obj/rpcdump.o \
107     obj/script.o \
108     obj/util.o \
109     obj/wallet.o \
110     obj/walletdb.o \
111     obj/noui.o \
112     obj/kernel.o \
113     obj/pbkdf2.o \
114     obj/scrypt_mine.o \
115     obj/scrypt-x86.o \
116     obj/scrypt-x86_64.o
117
118 all: novacoind
119
120 # auto-generated dependencies:
121 -include obj/*.P
122 -include obj-test/*.P
123
124 obj/build.h: FORCE
125         /bin/sh ../share/genbuild.sh obj/build.h
126 version.cpp: obj/build.h
127 DEFS += -DHAVE_BUILD_INFO
128
129 obj/%.o: %.cpp
130         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
131         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
132           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
133               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
134           rm -f $(@:%.o=%.d)
135
136 obj/scrypt-x86.o: scrypt-x86.S
137         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
138
139 obj/scrypt-x86_64.o: scrypt-x86_64.S
140         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
141
142 novacoind: $(OBJS:obj/%=obj/%)
143         $(CXX) $(xCXXFLAGS) -rdynamic -o $@ $^ $(LDFLAGS) $(LIBS)
144
145 TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
146
147 obj-test/%.o: test/%.cpp
148         $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -o $@ $<
149         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
150           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
151               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
152           rm -f $(@:%.o=%.d)
153
154 test_novacoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
155         $(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(LDFLAGS) $(LIBS)
156
157 clean:
158         -rm -f novacoind test_novacoin
159         -rm -f obj/*.o
160         -rm -f obj-test/*.o
161         -rm -f obj/*.P
162         -rm -f obj-test/*.P
163         -rm -f src/build.h
164
165 FORCE: