forked from Gooddbird/rocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
118 lines (81 loc) · 4.09 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
##################################
# makefile
# ikerli
# 2022-05-23
##################################
PATH_BIN = bin
PATH_LIB = lib
PATH_OBJ = obj
PATH_ROCKET = rocket
PATH_COMM = $(PATH_ROCKET)/common
PATH_NET = $(PATH_ROCKET)/net
PATH_TCP = $(PATH_ROCKET)/net/tcp
PATH_CODER = $(PATH_ROCKET)/net/coder
PATH_RPC = $(PATH_ROCKET)/net/rpc
PATH_TESTCASES = testcases
# will install lib to /usr/lib/librocket.a
PATH_INSTALL_LIB_ROOT = /usr/lib
# will install all header file to /usr/include/rocket
PATH_INSTALL_INC_ROOT = /usr/include
PATH_INSTALL_INC_COMM = $(PATH_INSTALL_INC_ROOT)/$(PATH_COMM)
PATH_INSTALL_INC_NET = $(PATH_INSTALL_INC_ROOT)/$(PATH_NET)
PATH_INSTALL_INC_TCP = $(PATH_INSTALL_INC_ROOT)/$(PATH_TCP)
PATH_INSTALL_INC_CODER = $(PATH_INSTALL_INC_ROOT)/$(PATH_CODER)
PATH_INSTALL_INC_RPC = $(PATH_INSTALL_INC_ROOT)/$(PATH_RPC)
# PATH_PROTOBUF = /usr/include/google
# PATH_TINYXML = /usr/include/tinyxml
CXX := g++
CXXFLAGS += -g -O0 -std=c++11 -Wall -Wno-deprecated -Wno-unused-but-set-variable
CXXFLAGS += -I./ -I$(PATH_ROCKET) -I$(PATH_COMM) -I$(PATH_NET) -I$(PATH_TCP) -I$(PATH_CODER) -I$(PATH_RPC)
LIBS += /usr/lib/libprotobuf.a /usr/lib/libtinyxml.a
COMM_OBJ := $(patsubst $(PATH_COMM)/%.cc, $(PATH_OBJ)/%.o, $(wildcard $(PATH_COMM)/*.cc))
NET_OBJ := $(patsubst $(PATH_NET)/%.cc, $(PATH_OBJ)/%.o, $(wildcard $(PATH_NET)/*.cc))
TCP_OBJ := $(patsubst $(PATH_TCP)/%.cc, $(PATH_OBJ)/%.o, $(wildcard $(PATH_TCP)/*.cc))
CODER_OBJ := $(patsubst $(PATH_CODER)/%.cc, $(PATH_OBJ)/%.o, $(wildcard $(PATH_CODER)/*.cc))
RPC_OBJ := $(patsubst $(PATH_RPC)/%.cc, $(PATH_OBJ)/%.o, $(wildcard $(PATH_RPC)/*.cc))
ALL_TESTS : $(PATH_BIN)/test_log $(PATH_BIN)/test_eventloop $(PATH_BIN)/test_tcp $(PATH_BIN)/test_client $(PATH_BIN)/test_rpc_client $(PATH_BIN)/test_rpc_server
# ALL_TESTS : $(PATH_BIN)/test_log
TEST_CASE_OUT := $(PATH_BIN)/test_log $(PATH_BIN)/test_eventloop $(PATH_BIN)/test_tcp $(PATH_BIN)/test_client $(PATH_BIN)/test_rpc_client $(PATH_BIN)/test_rpc_server
LIB_OUT := $(PATH_LIB)/librocket.a
$(PATH_BIN)/test_log: $(LIB_OUT)
$(CXX) $(CXXFLAGS) $(PATH_TESTCASES)/test_log.cc -o $@ $(LIB_OUT) $(LIBS) -ldl -pthread
$(PATH_BIN)/test_eventloop: $(LIB_OUT)
$(CXX) $(CXXFLAGS) $(PATH_TESTCASES)/test_eventloop.cc -o $@ $(LIB_OUT) $(LIBS) -ldl -pthread
$(PATH_BIN)/test_tcp: $(LIB_OUT)
$(CXX) $(CXXFLAGS) $(PATH_TESTCASES)/test_tcp.cc -o $@ $(LIB_OUT) $(LIBS) -ldl -pthread
$(PATH_BIN)/test_client: $(LIB_OUT)
$(CXX) $(CXXFLAGS) $(PATH_TESTCASES)/test_client.cc -o $@ $(LIB_OUT) $(LIBS) -ldl -pthread
$(PATH_BIN)/test_rpc_client: $(LIB_OUT)
$(CXX) $(CXXFLAGS) $(PATH_TESTCASES)/test_rpc_client.cc $(PATH_TESTCASES)/order.pb.cc -o $@ $(LIB_OUT) $(LIBS) -ldl -pthread
$(PATH_BIN)/test_rpc_server: $(LIB_OUT)
$(CXX) $(CXXFLAGS) $(PATH_TESTCASES)/test_rpc_server.cc $(PATH_TESTCASES)/order.pb.cc -o $@ $(LIB_OUT) $(LIBS) -ldl -pthread
$(LIB_OUT): $(COMM_OBJ) $(NET_OBJ) $(TCP_OBJ) $(CODER_OBJ) $(RPC_OBJ)
cd $(PATH_OBJ) && ar rcv librocket.a *.o && cp librocket.a ../lib/
$(PATH_OBJ)/%.o : $(PATH_COMM)/%.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
$(PATH_OBJ)/%.o : $(PATH_NET)/%.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
$(PATH_OBJ)/%.o : $(PATH_TCP)/%.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
$(PATH_OBJ)/%.o : $(PATH_CODER)/%.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
$(PATH_OBJ)/%.o : $(PATH_RPC)/%.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
# print something test
# like this: make PRINT-PATH_BIN, and then will print variable PATH_BIN
PRINT-% : ; @echo $* = $($*)
# to clean
clean :
rm -f $(COMM_OBJ) $(NET_OBJ) $(TESTCASES) $(TEST_CASE_OUT) $(PATH_LIB)/librocket.a $(PATH_OBJ)/librocket.a $(PATH_OBJ)/*.o
# install
install:
mkdir -p $(PATH_INSTALL_INC_COMM) $(PATH_INSTALL_INC_NET) $(PATH_INSTALL_INC_TCP) $(PATH_INSTALL_INC_CODER) $(PATH_INSTALL_INC_RPC)\
&& cp $(PATH_COMM)/*.h $(PATH_INSTALL_INC_COMM) \
&& cp $(PATH_NET)/*.h $(PATH_INSTALL_INC_NET) \
&& cp $(PATH_TCP)/*.h $(PATH_INSTALL_INC_TCP) \
&& cp $(PATH_CODER)/*.h $(PATH_INSTALL_INC_CODER) \
&& cp $(PATH_RPC)/*.h $(PATH_INSTALL_INC_RPC) \
&& cp $(LIB_OUT) $(PATH_INSTALL_LIB_ROOT)/
# uninstall
uninstall:
rm -rf $(PATH_INSTALL_INC_ROOT)/rocket && rm -f $(PATH_INSTALL_LIB_ROOT)/librocket.a