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