Tiny NTP client.
[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_LEVELDB:=0
7 USE_IPV6:=1
8
9 LINK:=$(CXX)
10 ARCH:=$(system lscpu | head -n 1 | awk '{print $2}')
11
12 DEFS=-DBOOST_SPIRIT_THREADSAFE -D__STDC_FORMAT_MACROS
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 LMODE = dynamic
18 LMODE2 = dynamic
19 ifdef STATIC
20         LMODE = static
21         ifeq (${STATIC}, all)
22                 LMODE2 = static
23         endif
24 endif
25
26 # for boost 1.37, add -mt to the boost libraries
27 LIBS += \
28  -Wl,-B$(LMODE) \
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) \
34    -l ssl \
35    -l crypto
36
37 ifndef USE_UPNP
38         override USE_UPNP = -
39 endif
40 ifneq (${USE_UPNP}, -)
41         LIBS += -l miniupnpc
42         DEFS += -DUSE_UPNP=$(USE_UPNP)
43 endif
44
45 ifneq (${USE_IPV6}, -)
46         DEFS += -DUSE_IPV6=$(USE_IPV6)
47 endif
48
49 LIBS+= \
50  -Wl,-B$(LMODE2) \
51    -l z \
52    -l dl \
53    -l pthread
54
55
56 # Hardening
57 # Make some classes of vulnerabilities unexploitable in case one is discovered.
58 #
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
63
64     # Stack Canaries
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
70
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
75
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.
79     ifdef PIE
80         HARDENING+=-fPIE
81         LDHARDENING+=-pie
82     endif
83
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
87 #
88
89
90 DEBUGFLAGS=-g
91
92
93 ifeq (${ARCH}, i686)
94     EXT_OPTIONS=-msse2
95 endif
96
97
98 # CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only
99 # adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work.
100 xCXXFLAGS=-O2 $(EXT_OPTIONS) -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter \
101     $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
102
103 # LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
104 # adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
105 xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
106
107 OBJS= \
108     obj/alert.o \
109     obj/version.o \
110     obj/checkpoints.o \
111     obj/netbase.o \
112     obj/addrman.o \
113     obj/crypter.o \
114     obj/key.o \
115     obj/db.o \
116     obj/init.o \
117     obj/irc.o \
118     obj/keystore.o \
119     obj/miner.o \
120     obj/main.o \
121     obj/net.o \
122     obj/ntp.o \
123     obj/stun.o \
124     obj/protocol.o \
125     obj/bitcoinrpc.o \
126     obj/rpcdump.o \
127     obj/rpcnet.o \
128     obj/rpcmining.o \
129     obj/rpcwallet.o \
130     obj/rpcblockchain.o \
131     obj/rpcrawtransaction.o \
132     obj/script.o \
133     obj/sync.o \
134     obj/util.o \
135     obj/wallet.o \
136     obj/walletdb.o \
137     obj/noui.o \
138     obj/kernel.o
139
140 all: novacoind
141
142 #
143 # LevelDB support
144 #
145 ifeq (${USE_LEVELDB}, 1)
146 LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a
147 DEFS += $(addprefix -I,$(CURDIR)/leveldb/include) -DUSE_LEVELDB
148 DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers)
149 OBJS += obj/txdb-leveldb.o
150 leveldb/libleveldb.a:
151         @echo "Building LevelDB ..."; cd leveldb; make libleveldb.a libmemenv.a; cd ..;
152 obj/txdb-leveldb.o: leveldb/libleveldb.a
153 endif
154 ifneq (${USE_LEVELDB}, 1)
155 OBJS += obj/txdb-bdb.o
156 endif
157
158 ifeq (${USE_ASM}, 1)
159 # Assembler implementation
160 OBJS += scrypt-asm/obj/scrypt-arm.o scrypt-asm/obj/scrypt-x86.o scrypt-asm/obj/scrypt-x86_64.o scrypt-asm/obj/asm-wrapper.o
161
162 scrypt-asm/obj/scrypt-x86.o: scrypt-asm/scrypt-x86.S
163         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
164
165 scrypt-asm/obj/scrypt-x86_64.o: scrypt-asm/scrypt-x86_64.S
166         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
167
168 scrypt-asm/obj/scrypt-arm.o: scrypt-asm/scrypt-arm.S
169         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
170
171 scrypt-asm/obj/asm-wrapper.o: scrypt-asm/asm-wrapper.cpp
172         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
173 else
174 ifeq  (${USE_SSE2}, 1)
175 # Intrinsic implementation
176 DEFS += -DUSE_SSE2
177 OBJS += scrypt-intrin/obj/scrypt-sse2.o
178
179 scrypt-intrin/obj/scrypt-sse2.o: scrypt-intrin/scrypt-sse2.cpp
180         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
181 else
182 # Generic implementation
183 OBJS += obj/scrypt-generic.o
184
185 obj/scrypt-generic.o: scrypt-generic.cpp
186         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
187 endif
188 endif
189
190
191 # auto-generated dependencies:
192 -include obj/*.P
193
194 obj/build.h: FORCE
195         /bin/sh ../share/genbuild.sh obj/build.h
196 version.cpp: obj/build.h
197 DEFS += -DHAVE_BUILD_INFO
198
199
200 obj/%.o: %.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); \
205           rm -f $(@:%.o=%.d)
206
207 novacoind: $(OBJS:obj/%=obj/%)
208         $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS)
209
210 clean:
211         -rm -f novacoind
212         -rm -f obj/*.o
213         -rm -f obj/*.P
214         -rm -f obj/*.d
215         -rm -f scrypt-asm/obj/*.o
216         -rm -f scrypt-asm/obj/*.P
217         -rm -f scrypt-asm/obj/*.d
218         -rm -f scrypt-intrin/obj/*.o
219         -rm -f scrypt-intrin/obj/*.P
220         -rm -f scrypt-intrin/obj/*.d
221         -rm -f obj/build.h
222
223 FORCE: