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