Build identification strings
[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,$(CURDIR) $(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 LIBS+= \
43  -Wl,-B$(LMODE2) \
44    -l z \
45    -l dl \
46    -l pthread
47
48
49 # Hardening
50 # Make some classes of vulnerabilities unexploitable in case one is discovered.
51 #
52     # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes
53     # -fstack-protector-all to be ignored unless -fno-stack-protector is used first.
54     # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722
55     HARDENING=-fno-stack-protector
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
84 xCXXFLAGS=-pthread -Wextra -Wno-sign-compare -Wno-char-subscripts -Wno-invalid-offsetof -Wformat -Wformat-security \
85     $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
86
87 OBJS= \
88     obj/version.o \
89     obj/checkpoints.o \
90     obj/netbase.o \
91     obj/addrman.o \
92     obj/crypter.o \
93     obj/key.o \
94     obj/db.o \
95     obj/init.o \
96     obj/irc.o \
97     obj/keystore.o \
98     obj/main.o \
99     obj/net.o \
100     obj/protocol.o \
101     obj/bitcoinrpc.o \
102     obj/rpcdump.o \
103     obj/script.o \
104     obj/util.o \
105     obj/wallet.o \
106     obj/noui.o
107
108
109 all: bitcoind
110
111 # auto-generated dependencies:
112 -include obj/*.P
113 -include obj-test/*.P
114
115 build.h: FORCE
116         @../share/genbuild.sh build.h
117 DEFS += -DHAVE_BUILD_INFO
118
119 obj/%.o: %.cpp
120         $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
121         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
122           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
123               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
124           rm -f $(@:%.o=%.d)
125
126 bitcoind: build.h $(OBJS:obj/%=obj/%)
127         $(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
128
129 TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
130
131 obj-test/%.o: test/%.cpp
132         $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -o $@ $<
133         @cp $(@:%.o=%.d) $(@:%.o=%.P); \
134           sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
135               -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
136           rm -f $(@:%.o=%.d)
137
138 test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%))
139         $(CXX) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-B$(LMODE) -lboost_unit_test_framework $(LDFLAGS) $(LIBS)
140
141 clean:
142         -rm -f bitcoind test_bitcoin
143         -rm -f obj/*.o
144         -rm -f obj-test/*.o
145         -rm -f obj/*.P
146         -rm -f obj-test/*.P
147         -rm -f src/build.h
148
149 FORCE: