Revert "Update gitian descriptors to point at stable git repo"
[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=-DBOOST_SPIRIT_THREADSAFE
8
9 DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
10 LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
11
12 TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data)
13
14 LMODE = dynamic
15 LMODE2 = dynamic
16 ifdef STATIC
17         LMODE = static
18         ifeq (${STATIC}, all)
19                 LMODE2 = static
20         endif
21 else
22         TESTDEFS += -DBOOST_TEST_DYN_LINK
23 endif
24
25 # for boost 1.37, add -mt to the boost libraries
26 LIBS += \
27  -Wl,-B$(LMODE) \
28    -l boost_system$(BOOST_LIB_SUFFIX) \
29    -l boost_filesystem$(BOOST_LIB_SUFFIX) \
30    -l boost_program_options$(BOOST_LIB_SUFFIX) \
31    -l boost_thread$(BOOST_LIB_SUFFIX) \
32    -l db_cxx$(BDB_LIB_SUFFIX) \
33    -l ssl \
34    -l crypto
35
36 ifndef USE_UPNP
37         override USE_UPNP = -
38 endif
39 ifneq (${USE_UPNP}, -)
40         LIBS += -l miniupnpc
41         DEFS += -DUSE_UPNP=$(USE_UPNP)
42 endif
43
44 LIBS+= \
45  -Wl,-B$(LMODE2) \
46    -l z \
47    -l dl \
48    -l pthread
49
50
51 # Hardening
52 # Make some classes of vulnerabilities unexploitable in case one is discovered.
53 #
54     # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
55     # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
56     # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
57     HARDENING=-fno-stack-protector
58
59     # Stack Canaries
60     # Put numbers at the beginning of each stack frame and check that they are the same.
61     # If a stack buffer if overflowed, it writes over the canary number and then on return
62     # when that number is checked, it won't be the same and the program will exit with
63     # a "Stack smashing detected" error instead of being exploited.
64     HARDENING+=-fstack-protector-all -Wstack-protector
65
66     # Make some important things such as the global offset table read only as soon as
67     # the dynamic linker is finished building it. This will prevent overwriting of addresses
68     # which would later be jumped to.
69     HARDENING+=-Wl,-z,relro -Wl,-z,now
70
71     # Build position independent code to take advantage of Address Space Layout Randomization
72     # offered by some kernels.
73     # see doc/build-unix.txt for more information.
74     ifdef PIE
75         HARDENING+=-fPIE -pie
76     endif
77
78     # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in
79     # the source such overflowing a statically defined buffer.
80     HARDENING+=-D_FORTIFY_SOURCE=2
81 #
82
83
84 DEBUGFLAGS=-g
85 CXXFLAGS=-O2
86 xCXXFLAGS=-pthread -Wall -Wextra -Wno-sign-compare -Wno-invalid-offsetof -Wno-unused-parameter -Wformat -Wformat-security \
87     $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
88
89 OBJS= \
90     obj/version.o \
91     obj/checkpoints.o \
92     obj/netbase.o \
93     obj/addrman.o \
94     obj/crypter.o \
95     obj/key.o \
96     obj/db.o \
97     obj/init.o \
98     obj/irc.o \
99     obj/keystore.o \
100     obj/main.o \
101     obj/net.o \
102     obj/protocol.o \
103     obj/bitcoinrpc.o \
104     obj/rpcdump.o \
105     obj/script.o \
106     obj/util.o \
107     obj/wallet.o \
108     obj/walletdb.o \
109     obj/noui.o
110
111
112 all: bitcoind
113
114 # auto-generated dependencies:
115 -include obj/*.P
116 -include obj-test/*.P
117
118 obj/build.h: FORCE
119         /bin/sh ../share/genbuild.sh obj/build.h
120 version.cpp: obj/build.h
121 DEFS += -DHAVE_BUILD_INFO
122
123 obj/%.o: %.cpp
124         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
125         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
126           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
127               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
128           rm -f $(@:%.o=%.d)
129
130 bitcoind: $(OBJS:obj/%=obj/%)
131         $(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
132
133 TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
134
135 obj-test/%.o: test/%.cpp
136         $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -o $@ $<
137         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
138           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
139               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
140           rm -f $(@:%.o=%.d)
141
142 test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
143         $(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(LDFLAGS) $(LIBS)
144
145 clean:
146         -rm -f bitcoind test_bitcoin
147         -rm -f obj/*.o
148         -rm -f obj-test/*.o
149         -rm -f obj/*.P
150         -rm -f obj-test/*.P
151         -rm -f src/build.h
152
153 FORCE: