forked from MatthewLM/cbitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.in
240 lines (161 loc) · 8.52 KB
/
Makefile.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# Copyright (c) 2012 Matthew Mitchell
#
# This file is part of cbitcoin. It is subject to the license terms
# in the LICENSE file found in the top-level directory of this
# distribution and at http://www.cbitcoin.com/license.html. No part of
# cbitcoin, including this file, may be copied, modified, propagated,
# or distributed except according to the terms contained in the
# LICENSE file.
# Flags
INCDIR = $(CURDIR)/library/include
BINDIR = $(CURDIR)/bin
INCCLIENT = -I/$(CURDIR)/client-server/include
CFLAGS += -Wall -Wno-uninitialized -Wno-pointer-to-int-cast -pedantic -std=gnu99 -I$(INCDIR) -I/opt/local/ssl/include -I/opt/local/include -I$(CURDIR)/library/dependencies/threads -Werror
LFLAGS = -L/opt/local/lib -L/usr/local/ssl/lib
ifndef OSTYPE
OSTYPE = $(shell uname -s|awk '{print tolower($$0)}')
#export OSTYPE
endif
LIBRARY_VERSION = 2.0
ifeq ($(OSTYPE), darwin)
LFLAGS += -flat_namespace -dynamiclib -undefined dynamic_lookup
LIBRARY_EXTENSION=.$(LIBRARY_VERSION).dylib
CFLAGS += -DCB_MACOSX
else # Assuming Linux for now
LFLAGS += -shared
LIBRARY_EXTENSION=.$(LIBRARY_VERSION).so
ADDITIONAL_OPENSSL_FLAGS = -ldl -L/lib/x86_64-linux-gnu/
export LD_LIBRARY_PATH = $(BINDIR):/usr/local/lib
CFLAGS += -DCB_LINUX
endif
LIBCFLAGS = @LIB_COMPILE_CONFIG_FLAGS@
# Directory names
# Set vpath search paths
vpath %.h include
vpath %.c src
vpath %.o build
vpath %.d build
# Non-debugging
all: CFLAGS += -O3
all: all-build
test: CFLAGS += -O3
test: test-build
# Debugging
debug-all: CFLAGS += -g
debug-all: all-build
debug-test: CFLAGS += -g
debug-test: test-build
# Build all
all-build: core crypto random threads logging network storage file-ec file-no-ec client
# Get files for the core library
CORE_FILES = $(wildcard library/src/*.c)
CORE_OBJS = $(patsubst library/src/%.c, build/%.o, $(CORE_FILES))
# Core library target linking
core : $(CORE_OBJS) | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin$(LIBRARY_EXTENSION) $(CORE_OBJS)
# Include header prerequisites
-include build/*.d
# Create build directory
build:
mkdir build
# Create bin directory
bin:
mkdir bin
# Core Compilation
$(CORE_OBJS): build/%.o: library/src/%.c | build
$(CC) -c $(CFLAGS) $< -o $@
$(CC) -I$(INCDIR) -MM $< > build/$*.d
@cp build/$*.d build/$*.P
@sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < build/$*.P >> build/$*.d;
@rm build/$*.P
# Dependencies require include/CBDependencies.h as a prerequisite
build/CBOpenSSLCrypto.o build/CBRand.o CBBlockChainStorage.o BLibEventSockets.o: library/include/CBDependencies.h
# Crypto library target linking
crypto : build/CBOpenSSLCrypto.o | bin
$(CC) $(LFLAGS) $(ADDITIONAL_OPENSSL_FLAGS) -o bin/libcbitcoin-crypto$(LIBRARY_EXTENSION) build/CBOpenSSLCrypto.o -lcrypto -lssl
# Crypto library compile
build/CBOpenSSLCrypto.o: library/dependencies/crypto/CBOpenSSLCrypto.c
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
# Random library target linking
random : build/CBRand.o | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin-rand$(LIBRARY_EXTENSION) build/CBRand.o
# Random library compile
build/CBRand.o: library/dependencies/random/CBRand.c
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
# Network library target linking
network : build/CBLibEventSockets.o build/CBCallbackQueue.o | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin-network$(LIBRARY_EXTENSION) build/CBLibEventSockets.o build/CBCallbackQueue.o -levent_core
# Network library compile
build/CBCallbackQueue.o: library/dependencies/sockets/CBCallbackQueue.c library/dependencies/sockets/CBCallbackQueue.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBLibEventSockets.o: library/dependencies/sockets/CBLibEventSockets.c library/dependencies/sockets/CBLibEventSockets.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
# Threads library target linking
threads : build/CBThreads.o | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin-threads$(LIBRARY_EXTENSION) build/CBThreads.o
# Threads library compile
build/CBThreads.o: library/dependencies/threads/CBThreads.c library/dependencies/threads/CBThreads.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
# Logging library target linking
logging : build/CBLog.o | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin-logging$(LIBRARY_EXTENSION) build/CBLog.o
# Logging library compile
build/CBLog.o: library/dependencies/logging/CBLog.c library/dependencies/logging/CBLog.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
# File IO library target linking
file-ec : build/CBFileEC.o build/CBHamming72.o | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin-file-ec$(LIBRARY_EXTENSION) build/CBFileEC.o build/CBHamming72.o
file-no-ec : build/CBFileNoEC.o | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin-file-no-ec$(LIBRARY_EXTENSION) build/CBFileNoEC.o
# File IO library compile
build/CBHamming72.o: library/dependencies/storage/CBHamming72.c library/dependencies/storage/CBHamming72.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBFileEC.o: library/dependencies/storage/CBFileEC.c library/dependencies/storage/CBFileEC.h library/dependencies/storage/CBHamming72.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBFileNoEC.o: library/dependencies/storage/CBFileNoEC.c library/dependencies/storage/CBFileNoEC.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
# Storage library files
STORAGE_FILES = $(wildcard library/dependencies/storage/*.c)
STORAGE_OBJS = $(patsubst library/dependencies/storage/%.c, build/%.o, $(STORAGE_FILES))
# Storage library target linking
storage : build/CBBlockChainStorage.o build/CBAddressStorage.o build/CBDatabase.o build/CBAccounterStorage.o build/CBNodeStorage.o | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin-storage$(LIBRARY_EXTENSION) build/CBBlockChainStorage.o build/CBAddressStorage.o build/CBDatabase.o build/CBAccounterStorage.o build/CBNodeStorage.o
# Storage library compile
build/CBAccounterStorage.o: library/dependencies/storage/CBAccounterStorage.c library/dependencies/storage/CBAccounterStorage.h library/dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBAddressStorage.o: library/dependencies/storage/CBAddressStorage.c library/dependencies/storage/CBAddressStorage.h library/dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBBlockChainStorage.o: library/dependencies/storage/CBBlockChainStorage.c library/dependencies/storage/CBBlockChainStorage.h library/dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBNodeStorage.o: library/dependencies/storage/CBNodeStorage.c library/dependencies/storage/CBNodeStorage.h library/dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBDatabase.o: library/dependencies/storage/CBDatabase.c library/dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
# Clean
clean:
rm -f -r build bin
# Tests
TEST_FILES = $(wildcard library/test/*.c)
TEST_BINARIES = $(patsubst library/test/%.c, bin/%, $(TEST_FILES))
TEST_OBJS = $(patsubst library/test/%.c, build/%.o, $(TEST_FILES))
test-build : all-build $(TEST_BINARIES)
rm -f -r cbitcoin 0 1 2 test.dat testDb
# REMEMBER to add dependencies after the objects or libraries that depend on them.
$(TEST_BINARIES): bin/%: build/%.o
$(CC) $< -L$(BINDIR) -lcbitcoin.$(LIBRARY_VERSION) -lcbitcoin-network.$(LIBRARY_VERSION) -lcbitcoin-storage.$(LIBRARY_VERSION) -lcbitcoin-threads.$(LIBRARY_VERSION) -lcbitcoin-logging.$(LIBRARY_VERSION) -lcbitcoin-crypto.$(LIBRARY_VERSION) -lcbitcoin.$(LIBRARY_VERSION) -lcbitcoin-file-ec.$(LIBRARY_VERSION) -lcbitcoin-rand.$(LIBRARY_VERSION) -L/opt/local/lib -lpthread -levent_core -levent_pthreads -lcrypto -o $@
$@
$(TEST_OBJS): build/%.o: library/test/%.c
$(CC) -c $(CFLAGS) -I$(CURDIR)/library/dependencies/sockets/ -I$(CURDIR)/library/dependencies/storage $< -o $@
# Client Server
CLIENT_FILES = $(wildcard client-server/src/*.c)
CLIENT_OBJS = $(patsubst client-server/src/%.c, build/%.o, $(CLIENT_FILES))
$(CLIENT_OBJS): build/%.o: client-server/src/%.c | build
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $(INCCLIENT) $< -o $@
$(CC) -I$(INCDIR) $(INCCLIENT) -MM $< > build/$*.d
@cp build/$*.d build/$*.P
@sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < build/$*.P >> build/$*.d;
@rm build/$*.P
client : $(CLIENT_OBJS) | bin
$(CC) $(CLIENT_OBJS) -L$(BINDIR) -lcbitcoin.$(LIBRARY_VERSION) -lcbitcoin-network.$(LIBRARY_VERSION) -lcbitcoin-storage.$(LIBRARY_VERSION) -lcbitcoin-threads.$(LIBRARY_VERSION) -lcbitcoin-logging.$(LIBRARY_VERSION) -lcbitcoin-crypto.$(LIBRARY_VERSION) -lcbitcoin.$(LIBRARY_VERSION) -lcbitcoin-file-ec.$(LIBRARY_VERSION) -lcbitcoin-rand.$(LIBRARY_VERSION) -L/opt/local/lib -lpthread -levent_core -levent_pthreads -lcrypto -o bin/cbitcoin