This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.in
198 lines (129 loc) · 6.02 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
# Flags
INCDIR = $(CURDIR)/include
BINDIR = $(CURDIR)/bin
CFLAGS += -fPIC -g -Wall -Wno-uninitialized -Wno-pointer-to-int-cast -pedantic -D_POSIX_C_SOURCE=200809L -I$(INCDIR) -I/opt/local/include @COMPILE_CONFIG_FLAGS@ -std=c99 #-Werror
LFLAGS = -L/opt/local/lib -L/usr/lib
LFLAGS_EXE = -L/opt/local/lib -L/usr/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
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)
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 storage file-ec file-no-ec # network-goes-here
# Get files for the core library
CORE_FILES = $(wildcard src/*.c)
CORE_OBJS = $(patsubst 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: src/%.c | build
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -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: 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: 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: dependencies/random/CBRand.c
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
# Network library target linking
#network : build/CBLibEventSockets.o | bin
# $(CC) $(LFLAGS) -o bin/libcbitcoin-network$(LIBRARY_EXTENSION) build/CBLibEventSockets.o -levent_core
# Network library compile
#build/CBLibEventSockets.o: dependencies/sockets/CBLibEventSockets.c dependencies/sockets/CBLibEventSockets.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: dependencies/storage/CBHamming72.c dependencies/storage/CBHamming72.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBFileEC.o: dependencies/storage/CBFileEC.c dependencies/storage/CBFileEC.h dependencies/storage/CBHamming72.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBFileNoEC.o: dependencies/storage/CBFileNoEC.c dependencies/storage/CBFileNoEC.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
# Storage library target linking
storage : build/CBBlockChainStorage.o build/CBAddressStorage.o build/CBDatabase.o | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin-storage$(LIBRARY_EXTENSION) build/CBBlockChainStorage.o build/CBAddressStorage.o build/CBDatabase.o
# Storage library compile
build/CBBlockChainStorage.o: dependencies/storage/CBBlockChainStorage.c dependencies/storage/CBBlockChainStorage.h dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBAddressStorage.o: dependencies/storage/CBAddressStorage.c dependencies/storage/CBAddressStorage.h dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
build/CBDatabase.o: dependencies/storage/CBDatabase.c dependencies/storage/CBDatabase.h
$(CC) -c $(CFLAGS) $(LIBCFLAGS) $< -o $@
# Clean
clean:
rm -f build/*.o build/*.d
# Tests
TEST_FILES = $(wildcard test/*.c)
TEST_BINARIES = $(patsubst test/%.c, bin/%, $(TEST_FILES))
TEST_OBJS = $(patsubst test/%.c, build/%.o, $(TEST_FILES))
test-build : all-build $(TEST_BINARIES)
# REMEMBER to add dependencies after the objects or libraries that depend on them.
$(TEST_BINARIES): bin/%: build/%.o
$(CC) $< -L$(BINDIR) -lpthread -lcbitcoin.$(LIBRARY_VERSION) -lcbitcoin-crypto.$(LIBRARY_VERSION) -lcbitcoin-storage.$(LIBRARY_VERSION) -lcbitcoin.$(LIBRARY_VERSION) -lcbitcoin-file-ec.$(LIBRARY_VERSION) -lcbitcoin-rand.$(LIBRARY_VERSION) -L/opt/local/lib -lcrypto -o $@
$@
#network disabled -levent_core -levent_pthreads
$(TEST_OBJS): build/%.o: test/%.c
$(CC) -c $(CFLAGS) -I$(CURDIR)/dependencies/sockets/ -I$(CURDIR)/dependencies/storage $< -o $@
# Examples
EXAMPLES_FILES = $(wildcard examples/*.c)
EXAMPLES_BINARIES = $(patsubst examples/%.c, bin/%, $(EXAMPLES_FILES))
EXAMPLES_OBJS = $(patsubst examples/%.c, build/%.o, $(EXAMPLES_FILES))
examples-build : all-build $(EXAMPLES_BINARIES)
# REMEMBER to add dependencies after the objects or libraries that depend on them.
$(EXAMPLES_BINARIES): bin/%: build/%.o
$(CC) $< -L$(BINDIR) $(LFLAGS_EXE) -lpthread -lcbitcoin.$(LIBRARY_VERSION) -lcbitcoin-crypto.$(LIBRARY_VERSION) -lcbitcoin-storage.$(LIBRARY_VERSION) -lcbitcoin.$(LIBRARY_VERSION) -lcbitcoin-file-ec.$(LIBRARY_VERSION) -lcbitcoin-rand.$(LIBRARY_VERSION) -lcrypto -lev -g -o $@
# $@
$(EXAMPLES_OBJS): build/%.o: examples/%.c
$(CC) -c $(CFLAGS) -I$(CURDIR)/dependencies/storage $< -o $@