forked from MatthewLM/cbitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.in
282 lines (188 loc) · 10.6 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# 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.
# REMEMBER to add dependencies after the objects or libraries that depend on them.
# Setup
INCDIR = $(CURDIR)/library/include
BINDIR = $(CURDIR)/bin
INCCLIENT = -I/$(CURDIR)/client-server/include
LFLAGS += -L/opt/local/lib -L/usr/local/ssl/lib @CONFIGLFLAGS@
CFLAGS += -I$(INCDIR) -I$(CURDIR)/library/dependencies/threads @CONFIGFLAGS@
CC = @CC@
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
# Set vpath search paths
vpath %.h include
vpath %.c src
vpath %.o build
vpath %.d build
# Main targets
all: all-build
test: test-build
examples: example-build
# Build all
all-build: library client
library: core crypto random threads logging network storage file-ec file-no-ec
# 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) $(if $(subst darwin,,$(OSTYPE)),,-install_name @executable_path/libcbitcoin$(LIBRARY_EXTENSION)) -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 CBLibEventSockets.o: library/include/CBDependencies.h
# Crypto library target linking
crypto : build/CBOpenSSLCrypto.o | bin
$(CC) $(LFLAGS) $(if $(subst darwin,,$(OSTYPE)),,-install_name @executable_path/libcbitcoin-crypto$(LIBRARY_EXTENSION)) $(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) $< -o $@
# Random library target linking
random : build/CBRand.o | bin
$(CC) $(LFLAGS) $(if $(subst darwin,,$(OSTYPE)),,-install_name @executable_path/libcbitcoin-rand$(LIBRARY_EXTENSION)) -o bin/libcbitcoin-rand$(LIBRARY_EXTENSION) build/CBRand.o
# Random library compile
build/CBRand.o: library/dependencies/random/CBRand.c
$(CC) -c $(CFLAGS) $< -o $@
# Network library target linking
network : build/CBLibEventSockets.o build/CBCallbackQueue.o | bin
$(CC) $(LFLAGS) $(if $(subst darwin,,$(OSTYPE)),,-install_name @executable_path/libcbitcoin-network$(LIBRARY_EXTENSION)) -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) $< -o $@
build/CBLibEventSockets.o: library/dependencies/sockets/CBLibEventSockets.c library/dependencies/sockets/CBLibEventSockets.h
$(CC) -c $(CFLAGS) $< -o $@
# Threads library target linking
threads : build/CBThreads.o | bin
$(CC) $(LFLAGS) $(if $(subst darwin,,$(OSTYPE)),,-install_name @executable_path/libcbitcoin-threads$(LIBRARY_EXTENSION)) -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) $< -o $@
# Logging library target linking
logging : build/CBLog.o | bin
$(CC) $(LFLAGS) $(if $(subst darwin,,$(OSTYPE)),,-install_name @executable_path/libcbitcoin-logging$(LIBRARY_EXTENSION)) -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) $< -o $@
# File IO library target linking
file-ec : build/CBFileEC.o build/CBHamming72.o | bin
$(CC) $(LFLAGS) $(if $(subst darwin,,$(OSTYPE)),,-install_name @executable_path/libcbitcoin-file-ec$(LIBRARY_EXTENSION)) -o bin/libcbitcoin-file-ec$(LIBRARY_EXTENSION) build/CBFileEC.o build/CBHamming72.o
file-no-ec : build/CBFileNoEC.o | bin
$(CC) $(LFLAGS) $(if $(subst darwin,,$(OSTYPE)),,-install_name @executable_path/libcbitcoin-file-no-ec$(LIBRARY_EXTENSION)) -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) $< -o $@
build/CBFileEC.o: library/dependencies/storage/CBFileEC.c library/dependencies/storage/CBFileEC.h library/dependencies/storage/CBHamming72.h
$(CC) -c $(CFLAGS) $< -o $@
build/CBFileNoEC.o: library/dependencies/storage/CBFileNoEC.c library/dependencies/storage/CBFileNoEC.h
$(CC) -c $(CFLAGS) $< -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) $(if $(subst darwin,,$(OSTYPE)),,-install_name @executable_path/libcbitcoin-storage$(LIBRARY_EXTENSION)) -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) $< -o $@
build/CBAddressStorage.o: library/dependencies/storage/CBAddressStorage.c library/dependencies/storage/CBAddressStorage.h library/dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $< -o $@
build/CBBlockChainStorage.o: library/dependencies/storage/CBBlockChainStorage.c library/dependencies/storage/CBBlockChainStorage.h library/dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $< -o $@
build/CBNodeStorage.o: library/dependencies/storage/CBNodeStorage.c library/dependencies/storage/CBNodeStorage.h library/dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $< -o $@
build/CBDatabase.o: library/dependencies/storage/CBDatabase.c library/dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $< -o $@
# Clean
clean:
rm -f -r build bin
# Library linking flags
LINK_CORE = -lcbitcoin.$(LIBRARY_VERSION)
LINK_NETWORK = -lcbitcoin-network.$(LIBRARY_VERSION)
LINK_STORAGE = -lcbitcoin-storage.$(LIBRARY_VERSION)
LINK_THREADS = -lcbitcoin-threads.$(LIBRARY_VERSION) -lpthread
LINK_LOGGING = -lcbitcoin-logging.$(LIBRARY_VERSION)
LINK_CRYPTO = -lcbitcoin-crypto.$(LIBRARY_VERSION) -lcrypto
LINK_FILE = -lcbitcoin-file-@NOEC@ec.$(LIBRARY_VERSION)
LINK_RAND = -lcbitcoin-rand.$(LIBRARY_VERSION)
# 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 : clean-tests $(TEST_BINARIES)
rm -f -r cbitcoin 0 1 2 test.dat testDb test.log
$(info ALL TESTS SUCCESSFUL)
# REMEMBER to add dependencies after the objects or libraries that depend on them.
$(TEST_BINARIES): bin/%: build/%.o
$(CC) $< -L$(BINDIR) -Wl,-rpath=$(BINDIR) $(LINK_CORE) $(LINK_NETWORK) $(LINK_STORAGE) $(LINK_THREADS) $(LINK_LOGGING) $(LINK_CRYPTO) $(LINK_CORE) -lcbitcoin-file-$(if $(subst bin/testCBFile,,$(subst bin/testCBHamming72,,$@)),@NOEC@,)ec.$(LIBRARY_VERSION) $(LINK_RAND) -L/opt/local/lib -levent_core -levent_pthreads -o $@
$@
$(TEST_OBJS): build/%.o: library/test/%.c library
$(CC) -c $(CFLAGS) -I$(CURDIR)/library/dependencies/sockets/ -I$(CURDIR)/library/dependencies/storage $< -o $@
clean-tests:
rm -f $(TEST_BINARIES)
# 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) $(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) -Wl,-rpath=$(BINDIR) $(LINK_CORE) $(LINK_NETWORK) $(LINK_STORAGE) $(LINK_THREADS) $(LINK_LOGGING) $(LINK_CRYPTO) $(LINK_CORE) $(LINK_FILE) $(LINK_RAND) -L/opt/local/lib -levent_core -levent_pthreads -o bin/cbitcoin
# Examples
EXAMPLE_FILES = $(wildcard examples/*.c)
EXAMPLE_BINARIES = $(patsubst examples/%.c, bin/%, $(EXAMPLE_FILES))
EXAMPLE_OBJS = $(patsubst examples/%.c, build/%.o, $(EXAMPLE_FILES))
example-build : $(EXAMPLE_BINARIES)
# For examples using the crypto dependencies only.
EXAMPLE_CRYPTO_LINK = $(CC) $< -L$(BINDIR) -Wl,-rpath=$(BINDIR) $(LINK_CORE) $(LINK_CRYPTO) -L/opt/local/lib -o $@
bin/base58ChecksumEncode bin/base58Converter bin/WIFConverter: bin/%: build/%.o
$(EXAMPLE_CRYPTO_LINK)
# For examples using the crypto and random dependencies
EXAMPLE_CRYPTO_RAND_LINK = $(CC) $< -L$(BINDIR) -Wl,-rpath=$(BINDIR) $(LINK_CORE) $(LINK_CRYPTO) $(LINK_RAND) -L/opt/local/lib -o $@
bin/addressGenerator: bin/%: build/%.o
$(EXAMPLE_CRYPTO_RAND_LINK)
# For examples using the crypto, random and threading dependencies
EXAMPLE_CRYPTO_RAND_THREAD_LINK = $(CC) $< -L$(BINDIR) -Wl,-rpath=$(BINDIR) $(LINK_CORE) $(LINK_CRYPTO) $(LINK_RAND) $(LINK_THREADS) -L/opt/local/lib -o $@
bin/noLowerAddressGenerator: bin/%: build/%.o
$(EXAMPLE_CRYPTO_RAND_THREAD_LINK)
# Compilation of example sources
$(EXAMPLE_OBJS): build/%.o: examples/%.c library
$(CC) -c $(CFLAGS) -I$(CURDIR)/library/dependencies/sockets/ -I$(CURDIR)/library/dependencies/storage $< -o $@