-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
128 lines (93 loc) · 3.88 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
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
# adds protobuf default installation path for pkg-config
LIBCXXFLAGS=`export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig; pkg-config --cflags protobuf`
LIBLDFLAGS=`export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig; pkg-config --libs protobuf`
CXXFLAGS=-std=c++14 -Ilibs/include -Ilibs/openssl_internals -Llibs -pthread $(LIBCXXFLAGS) $(OPTIONAL)
LDFLAGS=$(LIBLDFLAGS) -lcrypto -ldl
# generate dependency files for all *.cpp files
SOURCES_ALL=$(wildcard server/*.cpp) $(wildcard client/*.cpp) $(wildcard utils/*.cpp)
DEPS=$(SOURCES_ALL:.cpp=.d)
# UTIL
SOURCES_UTIL_TEST=utils/test-util.cpp server/test-main.cpp utils/util.cpp utils/key.cpp
OBJECTS_UTIL_TEST=$(SOURCES_UTIL_TEST:.cpp=.o)
# SERVER
SOURCES_SERVER=utils/mess.pb.cpp server/message.pb.cpp server/server.cpp utils/functions.cpp utils/userAcc.pb.cpp utils/util.cpp utils/key.cpp
SOURCES_SERVER_TEST=server/test-server.cpp server/test-main.cpp $(SOURCES_SERVER)
SOURCES_SERVER_MAIN=server/main.cpp $(SOURCES_SERVER)
OBJECTS_SERVER_TEST=$(SOURCES_SERVER_TEST:.cpp=.o)
OBJECTS_SERVER_MAIN=$(SOURCES_SERVER_MAIN:.cpp=.o)
# CLIENT
SOURCES_CLIENT=client/client.cpp utils/functions.cpp utils/userAcc.pb.cpp utils/mess.pb.cpp utils/key.cpp utils/util.cpp
SOURCES_CLIENT_TEST=client/test-client.cpp server/test-main.cpp $(SOURCES_CLIENT)
SOURCES_CLIENT_MAIN=client/main.cpp $(SOURCES_CLIENT)
OBJECTS_CLIENT=$(SOURCES_MAIN:.cpp=.o)
OBJECTS_CLIENT_TEST=$(SOURCES_CLIENT_TEST:.cpp=.o)
OBJECTS_CLIENT_MAIN=$(SOURCES_CLIENT_MAIN:.cpp=.o)
# FUNCTIONS
SOURCES_FUNCTIONS_TEST=utils/test-functions.cpp server/test-main.cpp utils/functions.cpp
OBJECTS_FUNCTIONS_TEST=$(SOURCES_FUNCTIONS_TEST:.cpp=.o)
# PROTO FILES
PROTO_FILES=$(wildcard utils/*.proto)
PROTO_FILES_CPP=$(PROTO_FILES:.proto=.pb.cpp)
############
# RECIPIES #
############
all: server-build client-build
test-base: all test-server test-util test-functions test-client
test: test-base
./test-server
./test-util
./test-functions
./test-client
test-valgrind: test-base
valgrind --leak-check=full --show-reachable=yes ./test-server
valgrind --leak-check=full --show-reachable=yes ./test-util
valgrind --leak-check=full --show-reachable=yes ./test-functions
valgrind --leak-check=full --show-reachable=yes ./test-client
# builds a target with debugging flags
# example: make debug-test ... builds target test with debugging flags -DDEBUG -Og -ggdb
debug-%: clean
$(MAKE) $* $(MAKEFILE) OPTIONAL="-DDEBUG -Og -ggdb"
# builds a target with coverage flags
# WARNING: for generating html files, 'lcov' is required
coverage-%: clean
$(MAKE) $* $(MAKEFILE) CXX="g++" OPTIONAL="--coverage"
./utils/generate_lcov.sh
# builds a target with profiling flags
# generates file 'gmon.out', which can be processed with 'gprof'
profile-%: clean
$(MAKE) $* $(MAKEFILE) OPTIONAL="-pg"
server-build: serverApp
client-build: clientApp
valgrind: server-build
valgrind --leak-check=full --show-reachable=yes ./serverApp
flags:
@echo $(CXXFLAGS)
@echo $(LDFLAGS)
@echo $(SOURCES_ALL)
test-util: $(OBJECTS_UTIL_TEST)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
test-server: $(OBJECTS_SERVER_TEST)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
test-client: $(OBJECTS_CLIENT_TEST)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
test-functions: $(OBJECTS_FUNCTIONS_TEST)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
serverApp: $(OBJECTS_SERVER_MAIN)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
clientApp: $(OBJECTS_CLIENT_MAIN)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
%.o: %.cpp $(PROTO_FILES_CPP)
$(CXX) $(CXXFLAGS) -MMD -MP -c -o $@ $< $(LDFLAGS)
%.pb.cpp: %.proto
./utils/generate_protobuf.sh $<
# CLEANUP
.PHONY: clean clean-coverage
clean: clean-coverage
rm -rf $(OBJECTS_SERVER_TEST) $(OBJECTS_CLIENT) $(OBJECTS_CLIENT_MAIN) $(OBJECTS_UTIL_TEST) $(DEPS)
clean-coverage:
rm -rf `find './' -name "*.gcov"`
rm -rf `find './' -name "*.gcda"`
rm -rf `find './' -name "*.gcno"`
-include $(DEPS)