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