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