-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
91 lines (69 loc) · 2.46 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
SHELL = /bin/sh
CC = clang-11
INCLUDES = -I src/utils -I src/hashing -I src/list_data_structures -I src/data_structures -I src/sorting
FLAGS = -std=c11 -fsanitize=cfi -fvisibility=hidden -D_DEFAULT_SOURCE
CFLAGS = -pedantic-errors -Wall -Wextra -Werror -Wthread-safety
DEBUGFLAGS = -O0 -Wno-unused -Wno-unused-parameter -fno-omit-frame-pointer -fno-sanitize-recover=all -g -D _DEBUG
RELEASEFLAGS = -O3 -fsanitize=safe-stack -D NDEBUG
LINKFLAGS = -lcunit -flto -lm
WRAPFLAGS = -Wl,--wrap=malloc -Wl,--wrap=calloc -Wl,--wrap=realloc
SHAREDFLAGS = -std=c11 -O3 -D NDEBUG -fPIC -shared -D_DEFAULT_SOURCE
TARGET = src/test_runner
SHARED_TARGET = algo.so
SOURCES = $(wildcard src/*.c src/*/*.c src/*/include/*.c)
OBJECTS = $(SOURCES:.c=.o)
DEPS = $(OBJECTS:.o=.d)
all: $(TARGET)
all: CFLAGS += -fsanitize=safe-stack,undefined
$(TARGET): $(OBJECTS)
$(CC) $(FLAGS) $(INCLUDES) $(CFLAGS) $(DEBUGFLAGS) $(OBJECTS) $(LINKFLAGS) $(WRAPFLAGS) -o $(TARGET)
ASAN_OPTIONS=detect_leaks=1 ./$(TARGET)
build-only: $(SOURCES)
$(CC) $(FLAGS) $(INCLUDES) $(CFLAGS) $(RELEASEFLAGS) -o $(TARGET) $(SOURCES) $(LINKFLAGS)
release: $(SOURCES)
$(CC) $(FLAGS) $(INCLUDES) $(CFLAGS) $(RELEASEFLAGS) -o $(TARGET) $(SOURCES) $(LINKFLAGS)
./$(TARGET)
-include $(DEPS)
%.o: %.c
$(CC) $(FLAGS) $(INCLUDES) $(CFLAGS) $(DEBUGFLAGS) -c -o $@ $< -flto
%.d: %.c
@$(CC) $(FLAGS) $(INCLUDES) $(CFLAGS) $(DEBUGFLAGS) $< -MM -MT $(@:.d=.o) >$@ -flto
profile: CFLAGS += -pg
profile: $(TARGET)
test-cases: FLAGS += -DTEST_CASES -DINSTRUMENT_SORT
test-cases: release
code-coverage: CFLAGS += -fprofile-arcs -ftest-coverage
code-coverage: $(TARGET)
memory-san: CFLAGS += -fsanitize=memory,undefined -fsanitize-memory-track-origins
memory-san: $(TARGET)
thread-san: CFLAGS += -fsanitize=thread,undefined
thread-san: $(TARGET)
address-san: CFLAGS += -fsanitize=address,undefined
address-san: $(TARGET)
shared: $(SOURCES)
$(CC) $(INCLUDES) $(CFLAGS) $(SHAREDFLAGS) -o $(SHARED_TARGET) $(SOURCES) $(LINKFLAGS) $(WRAPFLAGS)
ctags:
ctags -R .
comp-db:
bear -- make -B build-only
lint:
cpplint src/*.[ch] src/*/*.[ch]
format:
clang-format-11 -i src/*.[ch] src/*/*.[ch]
tidy:
clang-tidy-11 src/*.[ch] src/*/*.[ch]
clean:
-rm -f $(OBJECTS)
-rm -f $(DEPS)
-rm -f $(TARGET)
-rm -f $(SHARED_TARGET)
-rm -f gmon.out
-rm -rf code_coverage
-rm -f src/*.gcda
-rm -f src/*/*.gcda
-rm -f src/*.gcov
-rm -f src/*/*.gcov
-rm -f src/*.gcno
-rm -f src/*/*.gcno
-rm -f src/*.info
-rm -f src/run_result.txt