-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
100 lines (75 loc) · 2.97 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
CHECK ?= none
COMPILER ?= clang++
DEBUGGER ?= lldb
OPTIMIZATION ?= -O0 -ggdb3
STANDARD ?= c++20
WARNINGS ?= -Wall -Wextra
CFLAGS := -std=$(STANDARD) $(OPTIMIZATION) $(WARNINGS) -Iinclude
OUTPUT ?= ll2w
LDFLAGS ?= -pthread
LTOPT ?=
LEXFLAGS := -Wno-sign-compare -Wno-register
LLVMLEXCPP := src/parser/yylex.cpp
LLVMPARSECPP := src/parser/yyparse.cpp
LLVMPARSEHDR := include/yyparse.h
LLVMFLEXSRC := src/parser/lexer.l
LLVMBISONSRC := src/parser/parser.y
WASMLEXCPP := src/parser/wasmlex.cpp
WASMPARSECPP := src/parser/wasmparse.cpp
WASMPARSEHDR := include/wasmparse.h
WASMFLEXSRC := src/parser/wasm.l
WASMBISONSRC := src/parser/wasm.y
CLOC_OPTIONS := --exclude-dir=.vscode,ll --not-match-f='^(yy|wasm)(lex|parse)|\.svg$$'
BISON_OPTIONS := --color=always
SOURCES := $(shell find src/**/*.cpp src/*.cpp)
OBJECTS := $(SOURCES:.cpp=.o) $(LLVMLEXCPP:.cpp=.o) $(LLVMPARSECPP:.cpp=.o) $(WASMLEXCPP:.cpp=.o) $(WASMPARSECPP:.cpp=.o)
ifeq ($(CHECK), asan)
COMPILER := $(COMPILER) -fsanitize=address -fno-common
else ifeq ($(CHECK), msan)
COMPILER := $(COMPILER) -fsanitize=memory -fno-common
endif
.PHONY: all clean count countbf declutter
all: $(OUTPUT)
test: $(OUTPUT)
./$(OUTPUT) ll/serial.ll
$(OUTPUT): $(OBJECTS)
$(COMPILER) $(LTOPT) -o $@ $^ $(LDFLAGS)
$(LLVMLEXCPP): $(LLVMFLEXSRC) $(LLVMPARSEHDR)
flex --prefix=llvm --outfile=$(LLVMLEXCPP) $(LLVMFLEXSRC)
$(LLVMPARSECPP) $(LLVMPARSEHDR): $(LLVMBISONSRC)
bison $(BISON_OPTIONS) --defines=$(LLVMPARSEHDR) --output=$(LLVMPARSECPP) $(LLVMBISONSRC)
$(LLVMLEXCPP:.cpp=.o): $(LLVMLEXCPP)
$(COMPILER) $(CFLAGS) $(LEXFLAGS) -c $< -o $@
$(LLVMPARSECPP:.cpp=.o): $(LLVMPARSECPP) $(LLVMPARSEHDR)
$(COMPILER) $(CFLAGS) $(LEXFLAGS) -c $< -o $@
$(WASMLEXCPP): $(WASMFLEXSRC) $(WASMPARSEHDR)
flex --prefix=wasm --outfile=$(WASMLEXCPP) $(WASMFLEXSRC)
$(WASMPARSECPP) $(WASMPARSEHDR): $(WASMBISONSRC)
bison $(BISON_OPTIONS) --defines=$(WASMPARSEHDR) --output=$(WASMPARSECPP) $(WASMBISONSRC)
$(WASMLEXCPP:.cpp=.o): $(WASMLEXCPP)
$(COMPILER) $(CFLAGS) $(LEXFLAGS) -c $< -o $@
$(WASMPARSECPP:.cpp=.o): $(WASMPARSECPP) $(WASMPARSEHDR)
$(COMPILER) $(CFLAGS) $(LEXFLAGS) -c $< -o $@
%.o: %.cpp include/yyparse.h include/wasmparse.h
$(COMPILER) $(CFLAGS) $(LTOPT) -c $< -o $@
clean:
rm -f $(OUTPUT) src/*.o src/**/*.o graph_*.png \
$(LLVMPARSEHDR) $(LLVMPARSECPP) $(LLVMLEXCPP) $(LLVMPARSECPP:.c=.output) $(LLVMLEXCPP) $(LLVMPARSECPP) \
$(WASMPARSEHDR) $(WASMPARSECPP) $(WASMLEXCPP) $(WASMPARSECPP:.c=.output) $(WASMLEXCPP) $(WASMPARSECPP) \
PVS-Studio.log report.tasks strace_out
declutter:
rm -f graph_*.png
grind: $(OUTPUT)
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --show-reachable=no ./$<
count:
cloc . parser $(CLOC_OPTIONS)
countbf:
cloc --by-file . parser $(CLOC_OPTIONS)
DEPFILE = .dep
DEPTOKEN = "\# MAKEDEPENDS"
DEPFLAGS = -f $(DEPFILE) -s $(DEPTOKEN)
depend:
@ echo $(DEPTOKEN) > $(DEPFILE)
makedepend $(DEPFLAGS) -- $(COMPILER) $(CFLAGS) -- $(SOURCES) 2>/dev/null
@ rm $(DEPFILE).bak
sinclude $(DEPFILE)