-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
92 lines (76 loc) · 2.85 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
SHELL := /bin/bash
PROJECT_ROOT_DIR := $(shell pwd)
CA_CERT := ${PROJECT_ROOT_DIR}/certs/ca_cert.pem
SERVER_CERT := ${PROJECT_ROOT_DIR}/certs/server_cert.pem
SERVER_KEY := ${PROJECT_ROOT_DIR}/certs/server_key.pem
IS_LOCAL_SERVER := 0
IS_LOCAL_CLIENT := 1
REMOTE_HOST := ${REMOTE_IP}
REMOTE_NGTCP2_CFLAGS := -I/root/ngtcp2/include
REMOTE_NGTCP2_LDFLAGS=-L/root/ngtcp2/lib -lngtcp2 -lngtcp2_crypto_quictls
LOCAL_HOST := 127.0.0.1
LOCAL_NGTCP2_CFLAGS := -I/usr/local/include
LOCAL_NGTCP2_LDFLAGS := -L/usr/local/lib -lngtcp2 -lngtcp2_crypto_quictls
ifeq (${IS_LOCAL_SERVER}, 0)
HOST := ${REMOTE_HOST}
SERVER_NGTCP2_CFLAGS := ${REMOTE_NGTCP2_CFLAGS}
SERVER_NGTCP2_LDFLAGS := ${REMOTE_NGTCP2_LDFLAGS}
else
HOST := ${LOCAL_HOST}
SERVER_NGTCP2_CFLAGS := ${LOCAL_NGTCP2_CFLAGS}
SERVER_NGTCP2_LDFLAGS := ${LOCAL_NGTCP2_LDFLAGS}
endif
ifeq (${IS_LOCAL_CLIENT}, 0)
CLIENT_NGTCP2_CFLAGS := ${REMOTE_NGTCP2_CFLAGS}
CLIENT_NGTCP2_LDFLAGS := ${REMOTE_NGTCP2_LDFLAGS}
else
CLIENT_NGTCP2_CFLAGS := ${LOCAL_NGTCP2_CFLAGS}
CLIENT_NGTCP2_LDFLAGS := ${LOCAL_NGTCP2_LDFLAGS}
endif
PORT := 8443
SRC = $(wildcard *.c)
CLIENT_SRC = $(filter-out server.c, ${SRC})
SERVER_SRC = $(filter-out client.c, ${SRC})
EXE=client server
# -Wl,--trace-symbol,SYMBOL
# CREF=-Wl,--cref
TRACE := -Wl,--trace # 打印GCC搜寻共享库目录
RPATH := -Wl,-rpath=/usr/local/lib64
PEDANTIC := -pedantic
CFLAGS := -g -Wall -Wextra \
${PEDANTIC} \
${RPATH} \
# -DDEBUG \
# ${CREF} \
# ${TRACE} \
# quictls(openssl)
QUICTLS_LDFLAGS := -L/usr/local/lib64 -lssl -lcrypto
LDFLAGS := ${QUICTLS_LDFLAGS}
.PHONY: build_dir certs all run run_server run_client debug_client debug_server client server clean
all: build_dir client server
build_dir:
@mkdir -p build
certs: ${PROJECT_ROOT_DIR}/certs/gen.sh
@cd certs && ./gen.sh
client: build_dir ${CLIENT_SRC}
@gcc ${CFLAGS} ${CLIENT_NGTCP2_CFLAGS} -o build/$@ ${CLIENT_SRC} ${CLIENT_NGTCP2_LDFLAGS} ${LDFLAGS}
run_client: client
@SSLKEYLOGFILE="${PROJECT_ROOT_DIR}/keylog.txt" ./build/client ${HOST} ${PORT} ${CA_CERT}
debug_client: client
@SSLKEYLOGFILE="${PROJECT_ROOT_DIR}/keylog.txt" gdb --args ./build/client ${HOST} ${PORT} ${CA_CERT}
server: build_dir ${SERVER_SRC}
@gcc ${CFLAGS} ${SERVER_NGTCP2_CFLAGS} -o build/$@ ${SERVER_SRC} ${SERVER_NGTCP2_LDFLAGS} ${LDFLAGS}
run_server: server
@./build/server ${HOST} ${PORT} ${SERVER_CERT} ${SERVER_KEY}
debug_server: server
@gdb --args ./build/server ${HOST} ${PORT} ${SERVER_CERT} ${SERVER_KEY}
run: all
@if tmux has-session -t quic &> /dev/null; then tmux kill-session -t quic; fi; \
tmux new-session -s quic -c ${PROJECT_ROOT_DIR} -d; \
tmux split-window -t quic -v -l 10; \
tmux send-keys -t quic:0.0 "make run_server" C-m; \
sleep 0.5; \
tmux send-keys -t quic:0.1 "make run_client" C-m; \
if [[ -z "$$TMUX" ]]; then tmux attach-session -t quic; else tmux switch-client -t quic; fi;
clean:
rm -rfv build certs/*.pem