forked from baidu/ins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
executable file
·157 lines (126 loc) · 5.13 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
# OPT ?= -O2 -DNDEBUG # (A) Production use (optimized mode)
OPT ?= -g2 -Wall -fPIC # (B) Debug mode, w/ full line-level debugging symbols
# OPT ?= -O2 -g2 -DNDEBUG # (C) Profiling mode: opt, but w/debugging symbols
# Thirdparty
SNAPPY_PATH=./thirdparty/snappy/
PROTOBUF_PATH=./thirdparty/protobuf/
PROTOC_PATH=./thirdparty/protobuf/bin/
PROTOC=protoc
PBRPC_PATH ?=./thirdparty/sofa-pbrpc/output/
BOOST_PATH ?=./thirdparty/boost/
GFLAGS_PATH=./thirdparty/gflags/
NEXUS_LDB_PATH=./thirdparty/leveldb/
GTEST_PATH=./gtest-1.7.0/
PREFIX=/usr/local/
DEPENDS=./depends/
INCLUDE_PATH = -I./ -I$(NEXUS_LDB_PATH)/include -I$(PREFIX)/include -I$(PROTOBUF_PATH)/include \
-I$(PBRPC_PATH)/include \
-I$(SNAPPY_PATH)/include \
-I$(GFLAGS_PATH)/include \
-I$(DEPENDS)/include \
-I$(BOOST_PATH)
LDFLAGS = -L$(DEPENDS)/lib -L$(PROTOBUF_PATH)/lib \
-L$(PBRPC_PATH)/lib -lsofa-pbrpc -lprotobuf \
-L$(SNAPPY_PATH)/lib -lsnappy \
-L$(GFLAGS_PATH)/lib -lgflags \
-L$(NEXUS_LDB_PATH) -lleveldb -L$(PREFIX)/lib \
-lrt -lz -lpthread
LDFLAGS_SO = -L$(DEPENDS)/lib -L$(PROTOBUF_PATH)/lib \
-L$(PBRPC_PATH)/lib -Wl,--whole-archive -lsofa-pbrpc -lprotobuf -Wl,--no-whole-archive \
-L$(SNAPPY_PATH)/lib -lsnappy \
-L$(GFLAGS_PATH)/lib -Wl,--whole-archive -lgflags -Wl,--no-whole-archive \
-L$(NEXUS_LDB_PATH) -lleveldb -L$(PREFIX)/lib \
-lz -lpthread
CXXFLAGS += $(OPT)
PROTO_FILE = $(wildcard proto/*.proto)
PROTO_SRC = $(patsubst %.proto,%.pb.cc,$(PROTO_FILE))
PROTO_HEADER = $(patsubst %.proto,%.pb.h,$(PROTO_FILE))
PROTO_OBJ = $(patsubst %.proto,%.pb.o,$(PROTO_FILE))
UTIL_SRC = $(filter-out $(wildcard */*test.cc) $(wildcard */*main.cc) server/flags.cc, \
$(wildcard server/*.cc) $(wildcard storage/*.cc))
UTIL_OBJ = $(patsubst %.cc, %.o, $(UTIL_SRC))
UTIL_HEADER = $(wildcard server/*.h) $(wildcard storage/*.h)
INS_SRC = $(filter-out $(UTIL_SRC) $(wildcard */*test.cc), $(wildcard server/ins_*.cc) \
$(wildcard storage/*.cc))
INS_OBJ = $(patsubst %.cc, %.o, $(INS_SRC))
INS_CLI_SRC = $(wildcard sdk/ins_*.cc)
INS_CLI_OBJ = $(patsubst %.cc, %.o, $(INS_CLI_SRC))
INS_CLI_HEADER = $(wildcard sdk/*.h)
SAMPLE_SRC = sdk/sample.cc
SAMPLE_OBJ = $(patsubst %.cc, %.o, $(SAMPLE_SRC))
SAMPLE_HEADER = $(wildcard sdk/*.h)
FLAGS_OBJ = $(patsubst %.cc, %.o, $(wildcard server/flags.cc))
COMMON_OBJ = $(patsubst %.cc, %.o, $(wildcard common/*.cc))
OBJS = $(FLAGS_OBJ) $(COMMON_OBJ) $(PROTO_OBJ) $(UTIL_OBJ)
SDK_OBJ = $(patsubst %.cc, %.o, sdk/ins_sdk.cc) $(PROTO_OBJ) $(COMMON_OBJ) $(FLAGS_OBJ)
TEST_SRC = $(wildcard server/*_test.cc) $(wildcard storage/*_test.cc)
TEST_OBJ = $(patsubst %.cc, %.o, $(TEST_SRC))
TESTS = test_binlog test_storage_manager test_user_manager test_performance_center
BIN = ins ins_cli sample
LIB = libins_sdk.a
PY_LIB = libins_py.so
all: $(BIN) cp $(LIB)
nexus_ldb:
cd ./thirdparty/leveldb && make
# Depends
$(INS_OBJ) $(INS_CLI_OBJ) $(TEST_OBJ) $(UTIL_OBJ): $(PROTO_HEADER)
$(UTIL_OBJ): $(UTIL_HEADER)
$(INS_CLI_OBJ): $(INS_CLI_HEADER)
$(SAMPLE_OBJ): $(SAMPLE_HEADER)
# Targets
ins: $(INS_OBJ) $(UTIL_OBJS) $(OBJS) nexus_ldb
$(CXX) $(INS_OBJ) $(UTIL_OBJS) $(OBJS) -o $@ $(LDFLAGS)
ins_cli: $(INS_CLI_OBJ) $(OBJS) nexus_ldb
$(CXX) $(INS_CLI_OBJ) $(OBJS) -o $@ $(LDFLAGS)
sample: $(SAMPLE_OBJ) $(SDK_OBJ) $(LIB) nexus_ldb
$(CXX) $(SAMPLE_OBJ) $(LIB) -o $@ $(LDFLAGS)
$(LIB): $(SDK_OBJ)
ar -rs $@ $(SDK_OBJ)
%.o: %.cc
$(CXX) $(CXXFLAGS) $(INCLUDE_PATH) -c $< -o $@
%.pb.h %.pb.cc: %.proto
$(PROTOC) --proto_path=./proto/ --proto_path=/usr/local/include --cpp_out=./proto/ $<
clean:
rm -rf $(BIN) $(LIB) $(TESTS) $(PY_LIB)
rm -rf $(INS_OBJ) $(INS_CLI_OBJ) $(SAMPLE_OBJ) $(SDK_OBJ) $(TEST_OBJ) $(UTIL_OBJ)
rm -rf $(PROTO_SRC) $(PROTO_HEADER)
rm -rf output/
cp: $(BIN) $(LIB)
mkdir -p output/bin
mkdir -p output/lib
mkdir -p output/include
cp ins output/bin
cp ins_cli output/bin
cp sample output/bin
cp sdk/ins_sdk.h output/include
cp libins_sdk.a output/lib
sdk: $(LIB)
mkdir -p output/include
mkdir -p output/lib
cp sdk/ins_sdk.h output/include
cp libins_sdk.a output/lib
python: $(SDK_OBJ) sdk/ins_wrapper.o
$(CXX) -shared -fPIC -Wl,-soname,$(PY_LIB) -o $(PY_LIB) $(LDFLAGS_SO) $^
mkdir -p output/python
cp $(PY_LIB) sdk/ins_sdk.py output/python
install: $(LIB)
cp sdk/ins_sdk.h $(PREFIX)/include
cp $(LIB) $(PREFIX)/lib
install_sdk: $(LIB)
cp sdk/ins_sdk.h $(PREFIX)/include
cp libins_sdk.a $(PREFIX)/lib
.PHONY: test test_binlog test_storage_manager test_user_manager test_performance_center
test: $(TESTS)
./test_binlog
./test_storage_manager
./test_user_manager
./test_performance_center
echo "Test done"
test_binlog: storage/binlog_test.o $(UTIL_OBJ) $(OBJS)
$(CXX) $^ -o $@ $(LDFLAGS) -L$(GTEST_PATH) -lgtest
test_storage_manager: storage/storage_manage_test.o $(UTIL_OBJ) $(OBJS)
$(CXX) $^ -o $@ $(LDFLAGS) -L$(GTEST_PATH) -lgtest
test_user_manager: server/user_manage_test.o $(UTIL_OBJ) $(OBJS)
$(CXX) $^ -o $@ $(LDFLAGS) -L$(GTEST_PATH) -lgtest
test_performance_center: server/performance_center_test.o $(UTIL_OBJ) $(OBJS)
$(CXX) $^ -o $@ $(LDFLAGS) -L$(GTEST_PATH) -lgtest