-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
137 lines (125 loc) · 5.48 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
.PHONY: index clean graph-% test tcp scan coverage all test-unit test-functional test-random test-mutation mutated clang-analyze
OPTLEVEL := g
PROJECT_DIR := $(firstword $(dir $(shell realpath --relative-to=. $(MAKEFILE_LIST))))
# Compiler configuration #######################################################
if_coverage = $(if $(findstring coverage,$(MAKECMDGOALS)),$(1),)
CPPFLAGS_clang := -D_FORTIFY_SOURCE=3
# Some gcc builds (depends on the distro) set _FORTIFY_SOURCE by default,
# so we need undefine it and then redefine it
CPPFLAGS_gcc := -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS
CPPFLAGS_cc = $(CPPFLAGS_gcc)
CPPFLAGS ?= $(CPPFLAGS_$(CC))
CPPFLAGS += -I$(PROJECT_DIR) -I$(PROJECT_DIR)multitasking
#CPPFLAGS += -DNDEBUG
# Disable all logs
#CPPFLAGS += -DNO_LOGS_ON_STDERR
CFLAGS_gcc := -fanalyzer -fanalyzer-checker=taint -fsanitize=bounds -fsanitize-undefined-trap-on-error -ffat-lto-objects
CFLAGS_gcc += -Wformat -Werror=format-security -grecord-gcc-switches
CFLAGS_gcc += -fstack-protector-all
CFLAGS_gcc += -fstack-clash-protection
CFLAGS_cc = $(CFLAGS_gcc)
CFLAGS ?= -std=gnu11 -O$(OPTLEVEL) -ggdb3 -Wall -Wextra -flto $(CFLAGS_$(CC))
CFLAGS += $(call if_coverage,--coverage)
#CFLAGS += -fstrict-flex-arrays
# TODO: Remove those warnings only for generated files
CFLAGS += -Wno-implicit-fallthrough -Wno-unused-const-variable -Wno-sign-compare -Wno-unused-variable -Wno-unused-parameter
TARGET_ARCH := -mtune=native -march=native
LDLIBS :=
LDFLAGS ?= -flto
LDFLAGS += $(call if_coverage,--coverage)
# Project configuration ########################################################
RL_C := wireprotocol.c frontend.c header.c body.c attrs.c frame.c
RL_O := $(RL_C:.c=.o)
CFILES := main.c log.c utils.c serialization.c autoresponder.c sighandler.c controller.c ucspi.c s6notify.c
OFILES := $(RL_O) $(CFILES:.c=.o)
UT_C := ut.c serialization.c log.c utils.c contextring.c
UT_O := $(UT_C:.c=.o) header.o body.o frame.o attrs.o
MUTATED_O := utils.o serialization.o
NORMAL_O := $(RL_O) ut.o log.o
ALL_C := $(CFILES) $(UT_C)
ALL_PLIST := $(ALL_C:.c=.plist)
LIBCOMULTI_C := coro.c contextring.c eventloop.c suspendables.c
LIBCOMULTI_O := $(LIBCOMULTI_C:.c=.o)
HOSTNAME := $(shell hostname -f)
BUILD_DIR ?= build
vpath %.rl $(PROJECT_DIR)fsm
vpath %.c $(PROJECT_DIR) $(addprefix $(PROJECT_DIR),multitasking multitasking/coro)
vpath %.t $(PROJECT_DIR)
vpath %.txt $(PROJECT_DIR)
# Public targets ###############################################################
all: frob ut
index: tags cscope.out
test: test-unit test-functional test-random
clean:
$(if $(strip $F),$(RM) -- $F)
coverage: test | $(CFILES) $(UT_C)
gcov -o . $|
clang-analyze: $(ALL_PLIST)
tcp-server: frob | d5.txt
s6-tcpserver -vd -b2 0.0.0.0 5002 s6-tcpserver-access -t200 -v3 -rp -B "Welcome!\r\n" $(realpath $<) 1000 $|
tcp-client: frob | d5.txt
s6-tcpclient -rv localhost 5002 rlwrap $(realpath $<) 1000 $| 2>&1 | s6-tai64n | s6-tai64nlocal
tls-server: frob server.cer server.key | d5.txt
env -i PATH=/bin CERTFILE=$(word 2,$^) KEYFILE=$(word 3,$^) s6-tlsserver 0.0.0.0 6666 $(realpath $<) -f $(word 1,$^)
tls-client: frob server.cer | d5.txt
env -i PATH=/bin CAFILE=$(word 2,$^) s6-tlsclient 0.0.0.0 6666 $(realpath $<) -f $(word 1,$^)
scan:
scan-build $(MAKE) clean frob
graph-%: frame.rl adjust-%.sed
ragel -p -V $< | sed -Ef $(word 2,$^) | dot -Tpng | feh -
protocol.png: protocol.rl protocol-adjust.sed
ragel -p -V $(word 1,$^) | sed -Ef $(word 2,$^) | dot -Tpng -Gdpi=200 -o $@
first_level.png: first_level.rl first_level-adjust.sed
ragel -p -V $(word 1,$^) | sed -Ef $(word 2,$^) | dot -Tpng -Gdpi=200 -o $@
dir-%: | $(BUILD_DIR)/
+$(MAKE) -C $| $(addprefix -f ,$(abspath $(MAKEFILE_LIST))) $*
# Internal targets #############################################################
tags:
ctags --kinds-C=+p -R . /usr/include/{sys,}/*.h
test-random: frob
pv -Ss100M /dev/urandom | ./$< 1 2>/dev/null 1>/dev/null
test-unit: ut
./$<
test-functional: frob.log frob.sum
# mull-runner leaves running mutant processes 🤦
test-mutation: mut
trap 'pkill mut' EXIT; mull-runner-15 --ld-search-path=/usr/lib ./$<
%.log %.sum: %
runtest --tool $<
cscope.out:
cscope -bR
ut: LDLIBS := -lcheck -lsubunit -lm
ut: $(UT_O) $(RL_O)
$(LINK.o) -o $@ $^ $(LDLIBS)
mut: LDLIBS := -lcheck -lsubunit -lm
mut: CC := clang
mut: $(NORMAL_O) mutated
$(LINK.o) -o $@ $(NORMAL_O) $(MUTATED_O) $(LDLIBS)
mutated: CFLAGS += -fexperimental-new-pass-manager -fpass-plugin=/usr/local/lib/mull-ir-frontend-15 -grecord-command-line
mutated: $(MUTATED_O)
frob: $(OFILES) libcomulti.a
$(LINK.o) -o $@ $^ $(LDLIBS)
objcopy --only-keep-debug $@ [email protected]
strip --strip-unneeded $@
objcopy [email protected] $@
libcomulti.a: libcomulti.a($(LIBCOMULTI_O))
%.c: %.rl
ragel -G2 -L -o $@ $<
%.s: %.c
$(CC) -S -o $@ -fverbose-asm -fno-asynchronous-unwind-tables $(CFLAGS) -fno-lto $<
%.c: %.t
checkmk $< >$@
%.plist: %.c
clang --analyze -o $@ $<
%.key:
openssl genpkey -algorithm RSA -out $@ -pkeyopt rsa_keygen_bits:4096
%.cer: %.key
openssl req -new -x509 -sha256 -key $< -out $@ -days 2 -subj '/L=$(word 2,$(subst /, ,$(TZ)))/CN=$(HOSTNAME)'
%/:
mkdir -p -- $@
clean: F += $(wildcard $(RL_C) $(RL_C:.c=.s) $(UT_O) ut.c ut.s ut.o $(OFILES) frob frob.s log.s tags cscope.out ut)
clean: F += $(wildcard *.gcda *.gcno *.gcov)
clean: F += $(wildcard frob.log frob.sum frob.debug mut)
clean: F += $(wildcard $(ALL_PLIST))
clean: F += $(wildcard evloop.o evloop.debug evloop.s evloop)
clean: F += $(wildcard *.key *.cer)