Added a workaround for an Ubuntu bug which causes -fstack-protector-all to be disrega...
[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 license.txt or http://www.opensource.org/licenses/mit-license.php.
4
5 CXX=g++
6
7 WXINCLUDEPATHS=$(shell wx-config --cxxflags)
8
9 WXLIBS=$(shell wx-config --libs)
10
11 USE_UPNP:=0
12
13 DEFS=-DNOPCH -DUSE_SSL
14
15 # for boost 1.37, add -mt to the boost libraries
16 LIBS= \
17  -Wl,-Bstatic \
18    -l boost_system \
19    -l boost_filesystem \
20    -l boost_program_options \
21    -l boost_thread \
22    -l db_cxx \
23    -l ssl \
24    -l crypto
25
26 ifdef USE_UPNP
27         LIBS += -l miniupnpc
28         DEFS += -DUSE_UPNP=$(USE_UPNP)
29 endif
30
31 LIBS+= \
32  -Wl,-Bdynamic \
33    -l z \
34    -l dl \
35    -l pthread
36
37
38 # Hardening
39 # Make some classes of vulnerabilities unexploitable in case one is discovered.
40 #
41     # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
42     # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
43     # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
44     HARDENING=-fno-stack-protector
45
46     # Stack Canaries
47     # Put numbers at the beginning of each stack frame and check that they are the same.
48     # If a stack buffer if overflowed, it writes over the canary number and then on return
49     # when that number is checked, it won't be the same and the program will exit with
50     # a "Stack smashing detected" error instead of being exploited.
51     HARDENING+=-fstack-protector-all -Wstack-protector
52
53     # Make some important things such as the global offset table read only as soon as
54     # the dynamic linker is finished building it. This will prevent overwriting of addresses
55     # which would later be jumped to.
56     HARDENING+=-Wl,-z,relro -Wl,-z,now
57
58     # Build position independent code to take advantage of Address Space Layout Randomization
59     # offered by some kernels.
60     # see doc/build-unix.txt for more information.
61     ifdef PIE
62         HARDENING+=-fPIE -pie
63     endif
64
65     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
66     # the source such overflowing a statically defined buffer.
67     HARDENING+=-D_FORTIFY_SOURCE=2
68 #
69
70
71 DEBUGFLAGS=-g -D__WXDEBUG__
72 CXXFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(HARDENING)
73 HEADERS = \
74     base58.h \
75     bignum.h \
76     crypter.h \
77     db.h \
78     headers.h \
79     init.h \
80     irc.h \
81     key.h \
82     keystore.h \
83     main.h \
84     net.h \
85     noui.h \
86     protocol.h \
87     rpc.h \
88     script.h \
89     serialize.h \
90     strlcpy.h \
91     ui.h \
92     uibase.h \
93     uint256.h \
94     util.h \
95     wallet.h
96
97 OBJS= \
98     obj/crypter.o \
99     obj/db.o \
100     obj/init.o \
101     obj/irc.o \
102     obj/keystore.o \
103     obj/main.o \
104     obj/net.o \
105     obj/protocol.o \
106     obj/rpc.o \
107     obj/script.o \
108     obj/util.o \
109     obj/wallet.o \
110     cryptopp/obj/sha.o \
111     cryptopp/obj/cpu.o
112
113
114 all: bitcoin
115
116
117 obj/%.o: %.cpp $(HEADERS)
118         $(CXX) -c $(CXXFLAGS) $(WXINCLUDEPATHS) -DGUI -o $@ $<
119
120 cryptopp/obj/%.o: cryptopp/%.cpp
121         $(CXX) -c $(CXXFLAGS) -O3 -o $@ $<
122
123 bitcoin: $(OBJS) obj/ui.o obj/uibase.o
124         $(CXX) $(CXXFLAGS) -o $@ $^ $(WXLIBS) $(LIBS)
125
126
127 obj/nogui/%.o: %.cpp $(HEADERS)
128         $(CXX) -c $(CXXFLAGS) -o $@ $<
129
130 bitcoind: $(OBJS:obj/%=obj/nogui/%)
131         $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
132
133 obj/test/test_bitcoin.o: $(wildcard test/*.cpp) $(HEADERS)
134         $(CXX) -c $(CFLAGS) -o $@ test/test_bitcoin.cpp
135
136 test_bitcoin: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
137         $(CXX) $(CXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-Bstatic -lboost_unit_test_framework $(LIBS)
138
139 clean:
140         -rm -f bitcoin bitcoind test_bitcoin
141         -rm -f obj/*.o
142         -rm -f obj/nogui/*.o
143         -rm -f obj/test/*.o
144         -rm -f cryptopp/obj/*.o
145         -rm -f headers.h.gch