update to 0.4 preview
[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
8 LINK:=$(CXX)
9
10 DEFS=-DBOOST_SPIRIT_THREADSAFE
11
12 DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
13 LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
14
15 TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
16
17 LMODE = dynamic
18 LMODE2 = dynamic
19 ifdef STATIC
20         LMODE = static
21         ifeq (${STATIC}, all)
22                 LMODE2 = static
23         endif
24 else
25         TESTDEFS += -DBOOST_TEST_DYN_LINK
26 endif
27
28 # for boost 1.37, add -mt to the boost libraries
29 LIBS += \
30  -Wl,-B$(LMODE) \
31    -l boost_system$(BOOST_LIB_SUFFIX) \
32    -l boost_filesystem$(BOOST_LIB_SUFFIX) \
33    -l boost_program_options$(BOOST_LIB_SUFFIX) \
34    -l boost_thread$(BOOST_LIB_SUFFIX) \
35    -l db_cxx$(BDB_LIB_SUFFIX) \
36    -l ssl \
37    -l crypto
38
39 ifndef USE_UPNP
40         override USE_UPNP = -
41 endif
42 ifneq (${USE_UPNP}, -)
43         LIBS += -l miniupnpc
44         DEFS += -DUSE_UPNP=$(USE_UPNP)
45 endif
46
47 ifneq (${USE_IPV6}, -)
48         DEFS += -DUSE_IPV6=$(USE_IPV6)
49 endif
50
51 LIBS+= \
52  -Wl,-B$(LMODE2) \
53    -l z \
54    -l dl \
55    -l pthread
56
57
58 # Hardening
59 # Make some classes of vulnerabilities unexploitable in case one is discovered.
60 #
61     # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
62     # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
63     # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
64     HARDENING=-fno-stack-protector
65
66     # Stack Canaries
67     # Put numbers at the beginning of each stack frame and check that they are the same.
68     # If a stack buffer if overflowed, it writes over the canary number and then on return
69     # when that number is checked, it won't be the same and the program will exit with
70     # a "Stack smashing detected" error instead of being exploited.
71     HARDENING+=-fstack-protector-all -Wstack-protector
72
73     # Make some important things such as the global offset table read only as soon as
74     # the dynamic linker is finished building it. This will prevent overwriting of addresses
75     # which would later be jumped to.
76     LDHARDENING+=-Wl,-z,relro -Wl,-z,now
77
78     # Build position independent code to take advantage of Address Space Layout Randomization
79     # offered by some kernels.
80     # see doc/build-unix.txt for more information.
81     ifdef PIE
82         HARDENING+=-fPIE
83         LDHARDENING+=-pie
84     endif
85
86     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
87     # the source such overflowing a statically defined buffer.
88     HARDENING+=-D_FORTIFY_SOURCE=2
89 #
90
91
92 DEBUGFLAGS=-g
93
94 # CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only
95 # adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work.
96 xCXXFLAGS=-O0 -msse2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \
97     $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
98
99 # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
100 # adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
101 xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
102
103 OBJS= \
104     obj/alert.o \
105     obj/version.o \
106     obj/checkpoints.o \
107     obj/netbase.o \
108     obj/addrman.o \
109     obj/crypter.o \
110     obj/key.o \
111     obj/db.o \
112     obj/init.o \
113     obj/irc.o \
114     obj/keystore.o \
115     obj/main.o \
116     obj/net.o \
117     obj/protocol.o \
118     obj/bitcoinrpc.o \
119     obj/rpcdump.o \
120     obj/rpcnet.o \
121     obj/rpcmining.o \
122     obj/rpcwallet.o \
123     obj/rpcblockchain.o \
124     obj/rpcrawtransaction.o \
125     obj/script.o \
126     obj/sync.o \
127     obj/util.o \
128     obj/wallet.o \
129     obj/walletdb.o \
130     obj/noui.o \
131     obj/kernel.o \
132     obj/pbkdf2.o \
133     obj/scrypt_mine.o \
134     obj/scrypt-x86.o \
135     obj/scrypt-x86_64.o
136
137
138 all: novacoind
139
140 test check: test_novacoin FORCE
141         ./test_novacoin
142
143 # auto-generated dependencies:
144 -include obj/*.P
145 -include obj-test/*.P
146
147 obj/build.h: FORCE
148         /bin/sh ../share/genbuild.sh obj/build.h
149 version.cpp: obj/build.h
150 DEFS += -DHAVE_BUILD_INFO
151
152 obj/scrypt-x86.o: scrypt-x86.S
153         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
154
155 obj/scrypt-x86_64.o: scrypt-x86_64.S
156         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
157
158 obj/%.o: %.cpp
159         $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
160         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
161           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
162               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
163           rm -f $(@:%.o=%.d)
164
165 novacoind: $(OBJS:obj/%=obj/%)
166         $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
167
168 TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
169
170 obj-test/%.o: test/%.cpp
171         $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
172         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
173           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
174               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
175           rm -f $(@:%.o=%.d)
176
177 test_novacoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
178         $(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(xLDFLAGS) $(LIBS)
179
180 clean:
181         -rm -f novacoind test_novacoin
182         -rm -f obj/*.o
183         -rm -f obj-test/*.o
184         -rm -f obj/*.P
185         -rm -f obj-test/*.P
186         -rm -f obj/build.h
187
188 FORCE: