-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Makefile
390 lines (335 loc) · 10.7 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#Shell
SHELL = /bin/bash
#Executeable name
NAME = WSServer
#Compiler
CC = gcc
#Version
ifeq ($(VER),)
VER = $(shell git describe --abbrev=0 --tags)
endif
#Debug or Release
PROFILE = -Og -g -DNDEBUG
DEBUG = -Og -g
RELEASE = -O3 -funroll-loops -DNDEBUG
SPACE = -Os -DNDEBUG
MODE = "release"
EXEC = $(RELEASE)
#Compiler options
CFLAGS = $(EXEC) \
-fno-exceptions \
-fPIC \
-fstack-protector \
-fvisibility=hidden \
-march=native \
-MMD \
-pedantic \
-pedantic-errors \
-pipe \
-W \
-Wall \
-Werror \
-Wno-unused-parameter \
-Wno-unused-function \
-Wno-strict-aliasing \
-Wno-overlength-strings \
-Wformat \
-Wformat-security \
-Wformat-nonliteral \
-Winit-self \
-Winline \
-Wl,-z,relro \
-Wl,-z,now \
-Wmultichar \
-Wpointer-arith \
-Wreturn-type \
-Wsign-compare \
-Wuninitialized \
-D_DEFAULT_SOURCE \
-DWSS_SERVER_VERSION=\"$(VER)\" \
-DUSE_RPMALLOC #\
-DUSE_POLL\
CVER = -std=c11
# Flags
FLAGS_EXTRA = -pthread -lm -ldl
FLAGS_TEST = -lgcov
FLAGS_COVERAGE =
# Folders
ROOT = $(shell pwd)
LOG_FOLDER = $(ROOT)/log
BUILD_FOLDER = $(ROOT)/build
BIN_FOLDER = $(ROOT)/bin
SRC_FOLDER = $(ROOT)/src
INCLUDE_FOLDER = $(ROOT)/include
TEST_FOLDER = $(ROOT)/test
CONF_FOLDER = $(ROOT)/conf
GEN_FOLDER = $(ROOT)/generated
RESOURCES_FOLDER = $(ROOT)/resources
EXTENSIONS_FOLDER = $(ROOT)/extensions
SUBPROTOCOLS_FOLDER = $(ROOT)/subprotocols
SCRIPTS_FOLDER = $(ROOT)/scripts
# Include folders
INCLUDES = -I$(INCLUDE_FOLDER) -I$(SRC_FOLDER) -I$(EXTENSIONS_FOLDER) -I$(SUBPROTOCOLS_FOLDER)
# Files
SRC = $(shell find $(SRC_FOLDER) -name '*.c' -type f;)
TESTS = $(shell find $(TEST_FOLDER) -name 'test_*.c' -type f;)
SRC_OBJ = $(subst $(SRC_FOLDER), $(BUILD_FOLDER), $(patsubst %.c, %.o, $(SRC)))
TEST_OBJ = ${subst ${TEST_FOLDER}, ${BUILD_FOLDER}, ${patsubst %.c, %.o, $(TESTS)}}
ALL_OBJ = ${SRC_OBJ} ${TEST_OBJ}
TEST_NAMES = ${patsubst ${TEST_FOLDER}/%.c, %, ${TESTS}}
DEPS = $(ALL_OBJ:%.o=%.d)
ifneq ($(SSL_LIBRARY_PATH),)
INCLUDES += -I$(SSL_LIBRARY_PATH)/include -L$(SSL_LIBRARY_PATH)/lib
export LD_LIBRARY_PATH=$(SSL_LIBRARY_PATH)/lib
endif
ifeq ($(BUMP),)
BUMP = default
endif
ifndef TRAVIS
# Which SSL implementation to use
ifeq ($(SSL),)
SSL = OPENSSL
endif
$(shell pkg-config --exists libssl libcrypto)
ifeq ($(.SHELLSTATUS),0)
ifeq ("$(SSL)","OPENSSL")
FLAGS_EXTRA += $(shell pkg-config --libs libssl libcrypto)
CFLAGS += $(shell pkg-config --cflags libssl libcrypto) -DUSE_OPENSSL
endif
endif
$(shell pkg-config --exists wolfssl)
ifeq ($(.SHELLSTATUS),0)
ifeq ("$(SSL)","WOLFSSL")
FLAGS_EXTRA += $(shell pkg-config --libs wolfssl)
CFLAGS += $(shell pkg-config --cflags wolfssl) -DUSE_WOLFSSL
endif
endif
$(shell pkg-config --exists criterion)
ifeq ($(.SHELLSTATUS),0)
FLAGS_TEST += $(shell pkg-config --libs criterion)
endif
else
FLAGS_EXTRA += -lssl -lcrypto
CFLAGS += -DUSE_OPENSSL
FLAGS_TEST += -lcriterion
endif
.PHONY: valgrind version bump cachegrind callgrind clean subprotocols extensions autobahn massconnect autobahn_debug autobahn_call autobahn_cache analysis count release debug profiling space test ${addprefix run_,${TEST_NAMES}}
#what we are trying to build
all: clean version bin build log subprotocols extensions $(NAME)
build:
if [[ ! -e $(BUILD_FOLDER) ]]; then mkdir -p $(BUILD_FOLDER); fi
bin:
if [[ ! -e $(BIN_FOLDER) ]]; then mkdir -p $(BIN_FOLDER); fi
log:
if [[ ! -e $(LOG_FOLDER) ]]; then mkdir -p $(LOG_FOLDER); fi
docs: $(SRC)
rm -rf $(GEN_FOLDER)/documentation
mkdir -p $(GEN_FOLDER)/documentation
doxygen $(CONF_FOLDER)/doxyfile.conf
release_mode:
$(eval EXEC = $(RELEASE))
$(eval MODE = "release")
debug_mode:
$(eval EXEC = $(DEBUG))
$(eval MODE = "debug")
profiling_mode:
$(eval EXEC = $(PROFILE))
$(eval MODE = "profiling")
space_mode:
$(eval EXEC = $(SPACE))
$(eval MODE = "space")
# Recompile when headers change
-include $(DEPS)
#linkage
$(NAME): $(SRC_OBJ)
@echo
@echo ================ [Linking] ================
@echo
$(CC) $(CFLAGS) ${FLAGS_COVERAGE} $(CVER) -o $(BIN_FOLDER)/$@ $(filter-out $(filter-out $(BUILD_FOLDER)/[email protected], $(addsuffix .o, $(addprefix $(BUILD_FOLDER)/, $(NAME)))), $^) $(FLAGS_EXTRA) $(INCLUDES)
@echo
@echo ================ [$(NAME) compiled succesfully] ================
@echo
# compile every source file
$(BUILD_FOLDER)/%.o: $(SRC_FOLDER)/%.c
@echo
@echo ================ [Building Object] ================
@echo
$(CC) $(CFLAGS) ${FLAGS_COVERAGE} $(CVER) $(INCLUDES) -c $< -o $@
@echo
@echo OK [$<] - [$@]
@echo
# compile every test file
$(BUILD_FOLDER)/%.o: $(TEST_FOLDER)/%.c
@echo
@echo ================ [Building Object] ================
@echo
$(CC) --coverage $(CFLAGS) ${FLAGS_COVERAGE} $(CVER) $(INCLUDES) -c $< -o $@
@echo
@echo OK [$<] - [$@]
@echo
# Link test objects
${TEST_NAMES}: clean debug_mode bin build log ${SRC_OBJ} ${TEST_OBJ}
@echo
@echo ================ [Linking Tests] ================
@echo
$(CC) ${CFLAGS} ${FLAGS_COVERAGE} ${CVER} -o ${BIN_FOLDER}/$@ ${BUILD_FOLDER}/[email protected]\
$(filter-out $(addsuffix .o, $(addprefix ${BUILD_FOLDER}/, main)), $(filter-out ${BUILD_FOLDER}/test_%.o, $(ALL_OBJ)))\
${FLAGS_EXTRA} ${FLAGS_TEST} $(INCLUDES)
@echo
@echo ================ [$@ compiled succesfully] ================
extensions:
cd $(EXTENSIONS_FOLDER)/permessage-deflate/ && make $(MODE)
subprotocols:
cd $(SUBPROTOCOLS_FOLDER)/echo/ && make $(MODE)
cd $(SUBPROTOCOLS_FOLDER)/broadcast/ && make $(MODE)
#make valgrind
valgrind: debug_mode all
@echo
@echo ================ [Executing $(NAME) using Valgrind] ================
@echo
valgrind -v --leak-check=full --log-file="$(LOG_FOLDER)/valgrind.log" --track-origins=yes \
--show-reachable=yes $(BIN_FOLDER)/$(NAME) -c $(CONF_FOLDER)/wss.json
#make cachegrind
cachegrind: profiling_mode all
@echo
@echo ================ [Executing $(NAME) using Cachegrind] ================
@echo
valgrind --tool=cachegrind --trace-children=yes --cachegrind-out-file=$(LOG_FOLDER)/$(NAME).callgrind.log $(BIN_FOLDER)/$(NAME) -c $(CONF_FOLDER)/wss.json
#make callgrind
callgrind: profiling_mode all
@echo
@echo ================ [Executing $(NAME) using Callgrind] ================
@echo
valgrind --tool=callgrind --simulate-cache=yes --branch-sim=yes --callgrind-out-file=$(LOG_FOLDER)/$(NAME).callgrind.log $(BIN_FOLDER)/$(NAME) -c $(CONF_FOLDER)/wss.json
#make clean
clean:
@echo
@echo ================ [Cleaning $(NAME)] ================
@echo
rm -rf $(BIN_FOLDER)
rm -rf $(BUILD_FOLDER)
rm -rf $(LOG_FOLDER)
#make count
count:
@echo
@echo ================ [Counting lines in $(NAME)] ================
@echo
sloccount --wide --follow -- $(SRC_FOLDER) $(INCLUDE_FOLDER) $(TEST_FOLDER)
#make autobahn
autobahn: release
rm -rf $(GEN_FOLDER)/autobahn
if [[ ! -e $(GEN_FOLDER) ]]; then mkdir -p $(GEN_FOLDER); fi
$(BIN_FOLDER)/$(NAME) -c $(CONF_FOLDER)/autobahn.json &
sleep 1
docker build -t wsserver/autobahn -f Dockerfile.test .
docker run -it --rm \
--network="host" \
-v ${CONF_FOLDER}:/config \
-v ${GEN_FOLDER}:/generated \
-p 9001:9001 \
--name fuzzingclient \
wsserver/autobahn
pkill $(NAME) || true
#make autobahn_debug
autobahn_debug: debug
rm -rf $(GEN_FOLDER)/autobahn
if [[ ! -e $(GEN_FOLDER) ]]; then mkdir -p $(GEN_FOLDER); fi
valgrind -v --leak-check=full --log-file="$(LOG_FOLDER)/valgrind.log" --track-origins=yes \
--show-reachable=yes $(BIN_FOLDER)/$(NAME) -c $(CONF_FOLDER)/autobahn.debug.json &
sleep 3
docker build -t wsserver/autobahn -f Dockerfile.test .
docker run -it --rm \
--network="host" \
-v ${CONF_FOLDER}:/config \
-v ${GEN_FOLDER}:/generated \
-p 9001:9001 \
--name fuzzingclient \
wsserver/autobahn
pkill -SIGINT memcheck
#make autobahn_call
autobahn_call: profiling
rm -rf $(GEN_FOLDER)/autobahn
if [[ ! -e $(GEN_FOLDER) ]]; then mkdir -p $(GEN_FOLDER); fi
valgrind --tool=callgrind --simulate-cache=yes --branch-sim=yes --callgrind-out-file=$(LOG_FOLDER)/$(NAME).callgrind.log $(BIN_FOLDER)/$(NAME) -c $(CONF_FOLDER)/autobahn.debug.json &
sleep 3
docker build -t wsserver/autobahn -f Dockerfile.test .
docker run -it --rm \
--network="host" \
-v ${CONF_FOLDER}:/config \
-v ${GEN_FOLDER}:/generated \
-p 9001:9001 \
--name fuzzingclient \
wsserver/autobahn
pkill -SIGINT memcheck
#make autobahn_cache
autobahn_cache: profiling
rm -rf $(GEN_FOLDER)/autobahn
if [[ ! -e $(GEN_FOLDER) ]]; then mkdir -p $(GEN_FOLDER); fi
valgrind --tool=cachegrind --trace-children=yes --cachegrind-out-file=$(LOG_FOLDER)/$(NAME).callgrind.log $(BIN_FOLDER)/$(NAME) -c $(CONF_FOLDER)/autobahn.debug.json &
sleep 3
docker build -t wsserver/autobahn -f Dockerfile.test .
docker run -it --rm \
--network="host" \
-v ${CONF_FOLDER}:/config \
-v ${GEN_FOLDER}:/generated \
-p 9001:9001 \
--name fuzzingclient \
wsserver/autobahn
pkill -SIGINT memcheck
#make massconnect
massconnect: release
if [[ ! -e $(GEN_FOLDER) ]]; then mkdir -p $(GEN_FOLDER); fi
$(BIN_FOLDER)/$(NAME) -c $(CONF_FOLDER)/autobahn.json &
sleep 1
docker build -t wsserver/autobahn -f Dockerfile.massconnect .
docker run -it --rm \
--network="host" \
-v ${CONF_FOLDER}:/config \
-v ${GEN_FOLDER}:/generated \
-p 9001:9001 \
--name massconnect \
wsserver/autobahn
pkill $(NAME) || true
#make autobahn_cache
massconnect_cache: profiling
if [[ ! -e $(GEN_FOLDER) ]]; then mkdir -p $(GEN_FOLDER); fi
valgrind --tool=cachegrind --trace-children=yes --cachegrind-out-file=$(LOG_FOLDER)/$(NAME).callgrind.log $(BIN_FOLDER)/$(NAME) -c $(CONF_FOLDER)/autobahn.json &
sleep 3
docker build -t wsserver/autobahn -f Dockerfile.massconnect .
docker run -it --rm \
--network="host" \
-v ${CONF_FOLDER}:/config \
-v ${GEN_FOLDER}:/generated \
-p 9001:9001 \
--name massconnect \
wsserver/autobahn
pkill -SIGINT memcheck
criterion:
$(eval FLAGS_COVERAGE = -fprofile-arcs -ftest-coverage)
#make test
test: criterion subprotocols extensions $(TEST_NAMES) ${addprefix run_,${TEST_NAMES}}
rm -rf $(GEN_FOLDER)/gcov
mkdir -p $(GEN_FOLDER)/gcov
gcovr --object-directory $(BUILD_FOLDER) -r . --html --html-details --html-title $(NAME) -o $(GEN_FOLDER)/gcov/index.html
#make run_test_*
${addprefix run_,${TEST_NAMES}}: ${TEST_NAMES}
@echo ================ [Running test ${patsubst run_%,%,$@}] ================
@echo
${BIN_FOLDER}/${patsubst run_%,%,$@} --verbose
analysis:
cppcheck --language=c -f -q --enable=warning,performance,portability --std=c11 --error-exitcode=1 -i$(TEST_FOLDER) $(INCLUDES) .
#make version
version:
@echo ================ [$(NAME) - version $(VER)] ================
#make release
release: release_mode all
#make debug
debug: debug_mode all
#make profiling
profiling: profiling_mode all
#make space
space: space_mode all
#make bump
bump:
$(eval VER = $(shell $(SCRIPTS_FOLDER)/bump.sh --$(BUMP)))
make release VER=$(VER)