b893853fd0878b0171d8b99ce645b5a541993268
[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 gthread-2.0 \
34    -l z \
35    -l dl \
36    -l pthread
37
38
39 # Hardening
40 # Make some classes of vulnerabilities unexploitable in case one is discovered.
41 #
42     # Stack Canaries
43     # Put numbers at the beginning of each stack frame and check that they are the same.
44     # If a stack buffer if overflowed, it writes over the canary number and then on return
45     # when that number is checked, it won't be the same and the program will exit with
46     # a "Stack smashing detected" error instead of being exploited.
47     HARDENING=-fstack-protector-all -Wstack-protector
48
49     # Make some important things such as the global offset table read only as soon as
50     # the dynamic linker is finished building it. This will prevent overwriting of addresses
51     # which would later be jumped to.
52     HARDENING+=-Wl,-z,relro -Wl,-z,now
53
54     # Build position independent code to take advantage of Address Space Layout Randomization
55     # offered by some kernels.
56     # see doc/build-unix.txt for more information.
57     ifdef PIE
58         HARDENING+=-fPIE -pie
59     endif
60
61     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
62     # the source such overflowing a statically defined buffer.
63     HARDENING+=-D_FORTIFY_SOURCE=2
64 #
65
66
67 DEBUGFLAGS=-g -D__WXDEBUG__
68 CXXFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(HARDENING)
69 HEADERS = \
70     base58.h \
71     bignum.h \
72     crypter.h \
73     db.h \
74     headers.h \
75     init.h \
76     irc.h \
77     key.h \
78     keystore.h \
79     main.h \
80     net.h \
81     noui.h \
82     protocol.h \
83     bitcoinrpc.h \
84     script.h \
85     serialize.h \
86     strlcpy.h \
87     ui.h \
88     uibase.h \
89     uint256.h \
90     util.h \
91     wallet.h
92
93 OBJS= \
94     obj/crypter.o \
95     obj/db.o \
96     obj/init.o \
97     obj/irc.o \
98     obj/keystore.o \
99     obj/main.o \
100     obj/net.o \
101     obj/protocol.o \
102     obj/bitcoinrpc.o \
103     obj/script.o \
104     obj/util.o \
105     obj/wallet.o \
106     cryptopp/obj/sha.o \
107     cryptopp/obj/cpu.o
108
109
110 all: bitcoin
111
112
113 obj/%.o: %.cpp $(HEADERS)
114         $(CXX) -c $(CXXFLAGS) $(WXINCLUDEPATHS) -DGUI -o $@ $<
115
116 cryptopp/obj/%.o: cryptopp/%.cpp
117         $(CXX) -c $(CXXFLAGS) -O3 -o $@ $<
118
119 bitcoin: $(OBJS) obj/ui.o obj/uibase.o
120         $(CXX) $(CXXFLAGS) -o $@ $^ $(WXLIBS) $(LIBS)
121
122
123 obj/nogui/%.o: %.cpp $(HEADERS)
124         $(CXX) -c $(CXXFLAGS) -o $@ $<
125
126 bitcoind: $(OBJS:obj/%=obj/nogui/%)
127         $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
128
129 obj/test/test_bitcoin.o: $(wildcard test/*.cpp) $(HEADERS)
130         $(CXX) -c $(CFLAGS) -o $@ test/test_bitcoin.cpp
131
132 test_bitcoin: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
133         $(CXX) $(CXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-Bstatic -lboost_unit_test_framework $(LIBS)
134
135 clean:
136         -rm -f bitcoin bitcoind test_bitcoin
137         -rm -f obj/*.o
138         -rm -f obj/nogui/*.o
139         -rm -f obj/test/*.o
140         -rm -f cryptopp/obj/*.o
141         -rm -f headers.h.gch