0e903ef18e98394c9ee7e895ce5fb79ef9bdbee4
[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 USE_UPNP:=0
8
9 DEFS=-DNOPCH
10
11 DEFS += $(addprefix -I,$(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
12 LIBS += $(addprefix -l,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
13
14 LMODE = dynamic
15 LMODE2 = dynamic
16 ifdef STATIC
17         LMODE = static
18         ifeq (${STATIC}, all)
19                 LMODE2 = static
20         endif
21 endif
22
23 # for boost 1.37, add -mt to the boost libraries
24 LIBS= \
25  -Wl,-B$(LMODE) \
26    -l boost_system$(BOOST_LIB_SUFFIX) \
27    -l boost_filesystem$(BOOST_LIB_SUFFIX) \
28    -l boost_program_options$(BOOST_LIB_SUFFIX) \
29    -l boost_thread$(BOOST_LIB_SUFFIX) \
30    -l db_cxx$(BDB_LIB_SUFFIX) \
31    -l ssl \
32    -l crypto
33
34 ifndef USE_UPNP
35         override USE_UPNP = -
36 endif
37 ifneq (${USE_UPNP}, -)
38         LIBS += -l miniupnpc
39         DEFS += -DUSE_UPNP=$(USE_UPNP)
40 endif
41
42 ifneq (${USE_SSL}, 0)
43         DEFS += -DUSE_SSL
44 endif
45
46 LIBS+= \
47  -Wl,-B$(LMODE2) \
48    -l gthread-2.0 \
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     # Stack Canaries
58     # Put numbers at the beginning of each stack frame and check that they are the same.
59     # If a stack buffer if overflowed, it writes over the canary number and then on return
60     # when that number is checked, it won't be the same and the program will exit with
61     # a "Stack smashing detected" error instead of being exploited.
62     HARDENING=-fstack-protector-all -Wstack-protector
63
64     # Make some important things such as the global offset table read only as soon as
65     # the dynamic linker is finished building it. This will prevent overwriting of addresses
66     # which would later be jumped to.
67     HARDENING+=-Wl,-z,relro -Wl,-z,now
68
69     # Build position independent code to take advantage of Address Space Layout Randomization
70     # offered by some kernels.
71     # see doc/build-unix.txt for more information.
72     ifdef PIE
73         HARDENING+=-fPIE -pie
74     endif
75
76     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
77     # the source such overflowing a statically defined buffer.
78     HARDENING+=-D_FORTIFY_SOURCE=2
79 #
80
81
82 DEBUGFLAGS=-g
83 CXXFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(HARDENING)
84 HEADERS = \
85     base58.h \
86     bignum.h \
87     crypter.h \
88     db.h \
89     headers.h \
90     init.h \
91     irc.h \
92     key.h \
93     keystore.h \
94     main.h \
95     net.h \
96     noui.h \
97     protocol.h \
98     bitcoinrpc.h \
99     script.h \
100     serialize.h \
101     strlcpy.h \
102     uint256.h \
103     util.h \
104     wallet.h
105
106 OBJS= \
107     obj/crypter.o \
108     obj/db.o \
109     obj/init.o \
110     obj/irc.o \
111     obj/keystore.o \
112     obj/main.o \
113     obj/net.o \
114     obj/protocol.o \
115     obj/bitcoinrpc.o \
116     obj/script.o \
117     obj/util.o \
118     obj/wallet.o
119
120
121 all: bitcoind
122
123 # auto-generated dependencies:
124 -include obj/nogui/*.P
125 -include obj/test/*.P
126
127 obj/nogui/%.o: %.cpp
128         $(CXX) -c $(CXXFLAGS) -MMD -o $@ $<
129         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
130           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
131               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
132           rm -f $(@:%.o=%.d)
133
134 bitcoind: $(OBJS:obj/%=obj/nogui/%)
135         $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
136
137 obj/test/%.o: test/%.cpp
138         $(CXX) -c $(CXXFLAGS) -MMD -o $@ $<
139         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
140           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
141               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
142           rm -f $(@:%.o=%.d)
143
144 test_bitcoin: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
145         $(CXX) $(CXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-Bstatic -lboost_unit_test_framework $(LIBS)
146
147 clean:
148         -rm -f bitcoind test_bitcoin
149         -rm -f obj/*.o
150         -rm -f obj/nogui/*.o
151         -rm -f obj/test/*.o
152         -rm -f obj/*.P
153         -rm -f obj/nogui/*.P
154         -rm -f obj/test/*.P