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