-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
160 lines (126 loc) · 5.14 KB
/
Makefile
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
HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
SYSTEM ?= $(HOST_SYSTEM)
CC = gcc
CXX = g++
cov_comp = -fprofile-arcs -ftest-coverage -fno-inline
cov_lnk = -fprofile-arcs -ftest-coverage --coverage -fno-inline
NO_WARN = -w
TRIM_WARN = -Wno-unused-variable -Wno-unused-but-set-variable -Wno-format-security -Wformat=0
GDB_INFO = -g
SANA = -fsanitize=address
SANT = -fsanitize=thread
CFLAGS = -DPOSIX -fpermissive -std=c++1z -L/usr/local/lib $(GDB_INFO) #$(SANT)
ifeq ($(SYSTEM),Darwin)
LDFLAGS += `pkg-config --libs protobuf grpc++ grpc` -lgrpc++_reflection -ldl
else
LDFLAGS += `pkg-config --libs protobuf grpc++ grpc` -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -ldl
endif
CFLAGS_GRPC = -DGRPC_VERBOSITY=DEBUG -DGRPC_TRACE=all
LOG_LEVEL_NOTICE_MAJOR = -D_HIDE_HEARTBEAT_NOTICE -D_HIDE_GRPC_NOTICE -D_HIDE_NOEMPTY_REPEATED_APPENDENTRY_REQUEST
LOG_LEVEL_TEST = -D_HIDE_HEARTBEAT_NOTICE -D_HIDE_NOEMPTY_REPEATED_APPENDENTRY_REQUEST -D_HIDE_GRPC_NOTICE # -D_HIDE_RAFT_DEBUG
LOG_LEVEL_LIB = $(LOG_LEVEL_NOTICE_MAJOR) -D_HIDE_RAFT_DEBUG -D_HIDE_DEBUG -D_HIDE_TEST_DEBUG
ifeq ($(DEBUG), test)
# @echo "debug mode"
LOGLEVEL = $(LOG_LEVEL_TEST)
else
# @echo "no debug mode"
LOGLEVEL = $(LOG_LEVEL_LIB)
endif
$(warning LOGLEVEL=$(LOGLEVEL))
CFLAGS += $(TRIM_WARN)
CFLAGS += $(CFLAGS_GRPC)
OBJ_EXT=o
ROOT = .
# Important not to include ".", or gcov -r will fail with some files
SRC_ROOT = src
BIN_ROOT = bin
OBJ_ROOT = $(BIN_ROOT)/obj
DYOBJ_ROOT = $(BIN_ROOT)/dyobj
SRCS = $(wildcard $(SRC_ROOT)/*.cpp)
SRCS_H = $(wildcard $(SRC_ROOT)/*.h)
OBJS = $(patsubst $(SRC_ROOT)%, $(OBJ_ROOT)%, $(patsubst %cpp, %o, $(SRCS)))
DYOBJS = $(patsubst $(SRC_ROOT)%, $(DYOBJ_ROOT)%, $(patsubst %cpp, %o, $(SRCS)))
GRPCSRCS_H = $(patsubst %proto, %pb.h, $(wildcard $(SRC_ROOT)/grpc/*.proto))
GRPCSRCS_H += $(patsubst %proto, %grpc.pb.h, $(wildcard $(SRC_ROOT)/grpc/*.proto))
GRPCSRCS_CPP = $(patsubst %proto, %pb.cc, $(wildcard $(SRC_ROOT)/grpc/*.proto))
GRPCSRCS_CPP += $(patsubst %proto, %grpc.pb.cc, $(wildcard $(SRC_ROOT)/grpc/*.proto))
GRPCCODES = $(GRPCSRCS_H) $(GRPCSRCS_CPP)
GRPCOBJS = $(patsubst $(SRC_ROOT)%, $(OBJ_ROOT)%, $(patsubst %cc, %o, $(GRPCSRCS_CPP)))
DYGRPCOBJS = $(patsubst $(SRC_ROOT)%, $(DYOBJ_ROOT)%, $(patsubst %cc, %o, $(GRPCSRCS_CPP)))
all: test
install: $(BIN_ROOT)/libnuft.so $(BIN_ROOT)/libnuft.a
sudo cp $(BIN_ROOT)/libnuft.so /usr/local/lib/libnuft.so
sudo cp $(BIN_ROOT)/libnuft.a /usr/local/lib/libnuft.a
sudo mkdir -p /usr/local/include/Nuft/
sudo mkdir -p /usr/local/include/Nuft/grpc
sudo find $(SRC_ROOT) -name \*.h -exec cp {} /usr/local/include/Nuft \;
sudo find $(SRC_ROOT)/grpc -name \*.h -exec cp {} /usr/local/include/Nuft/grpc \;
sudo cp -r $(SRC_ROOT)/Nuke /usr/local/include/Nuke
uninstall:
rm -rf /usr/local/include/Nuft/
rm -rf /usr/local/include/Nuke/
rm -rf usr/local/lib/libnuft.so
rm -rf usr/local/lib/libnuft.a
test: $(GRPCOBJS) $(OBJS) $(SRC_ROOT)/test/test.cpp
make test_pure DEBUG=test
test_pure: $(GRPCOBJS) $(OBJS) $(SRC_ROOT)/test/test.cpp
$(CXX) $(CFLAGS) $(LOGLEVEL) $(SRC_ROOT)/test/test.cpp -o $(ROOT)/test -pthread $(GRPCOBJS) $(OBJS) /usr/local/lib/libgtest.a $(LDFLAGS)
atomic:
cd $(SRC_ROOT)/test/atomic/ && make atomic DEBUG=normal
$(OBJ_ROOT)/grpc/%.o: $(SRC_ROOT)/grpc/%.cc $(GRPCCODES) $(OBJ_ROOT)/grpc
$(CXX) $(CFLAGS) $(LOGLEVEL) -pthread -I/usr/local/include -c -o $@ $< $(LDFLAGS)
$(OBJ_ROOT)/%.o: $(SRC_ROOT)/%.cpp $(GRPCCODES) $(OBJ_ROOT)
$(CXX) $(CFLAGS) $(LOGLEVEL) -pthread -I/usr/local/include -c -o $@ $< $(LDFLAGS)
$(DYOBJ_ROOT)/grpc/%.o: $(SRC_ROOT)/grpc/%.cc $(GRPCCODES) $(DYOBJ_ROOT)/grpc
$(CXX) $(CFLAGS) $(LOGLEVEL) -fPIC -pthread -I/usr/local/include -c -o $@ $< $(LDFLAGS)
$(DYOBJ_ROOT)/%.o: $(SRC_ROOT)/%.cpp $(GRPCCODES) $(DYOBJ_ROOT)
$(CXX) $(CFLAGS) $(LOGLEVEL) -fPIC -pthread -I/usr/local/include -c -o $@ $< $(LDFLAGS)
dbg:
@echo $(OBJ_ROOT)/
@echo $(OBJS)
@echo $(GRPCCODES)
lib: $(BIN_ROOT)/libnuft.so $(BIN_ROOT)/libnuft.a
$(BIN_ROOT)/libnuft.so: $(DYOBJS) $(DYGRPCOBJS)
$(CXX) $(CFLAGS) $(LOGLEVEL) -o $(BIN_ROOT)/libnuft.so -shared $(DYOBJS) $(DYGRPCOBJS) $(LDFLAGS)
$(BIN_ROOT)/libnuft.a: $(OBJS) $(GRPCOBJS)
ar rvs $(BIN_ROOT)/libnuft.a $(OBJS) $(GRPCOBJS)
$(GRPCCODES):
protoc -I $(SRC_ROOT)/grpc --grpc_out=$(SRC_ROOT)/grpc --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` $(SRC_ROOT)/grpc/raft_messages.proto
protoc -I $(SRC_ROOT)/grpc --cpp_out=$(SRC_ROOT)/grpc $(SRC_ROOT)/grpc/raft_messages.proto
$(OBJ_ROOT)/grpc: $(OBJ_ROOT)
mkdir -p $(OBJ_ROOT)/grpc
$(OBJ_ROOT):
mkdir -p $(OBJ_ROOT)
$(DYOBJ_ROOT)/grpc: $(DYOBJ_ROOT)
mkdir -p $(DYOBJ_ROOT)/grpc
$(DYOBJ_ROOT):
mkdir -p $(DYOBJ_ROOT)
debug:
export GRPC_TRACE=all
export DEBUG=test
read_persist: $(GRPCOBJS)
$(CXX) $(GRPCOBJS) $(CFLAGS) $(LDFLAGS) -Isrc/grpc $(SRCS) $(SRC_ROOT)/test/read_persist.cpp -o $(ROOT)/read_persist -lpthread /usr/local/lib/libgtest.a
.PHONY: clean
clean: clc
rm -rf $(BIN_ROOT)
rm -f ./kv
rm -rf ./test
rm -rf ./read_persist
rm -rf *.so
rm -rf *.a
cd $(SRC_ROOT)/test/atomic && make clean
.PHONY: clc
clc:
rm -f *.err
rm -f *.out
rm -f *.persist
rm -f .persist
rm -f core
.PHONY: clean2
clean2: clean
rm -rf $(SRC_ROOT)/grpc/*.pb.*
list:
@echo $(SRCS)
@echo $(OBJS)
@echo $(GRPCSRCS)
@echo $(GRPCOBJS)