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