-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
99 lines (87 loc) · 3.71 KB
/
Copy pathMakefile
File metadata and controls
99 lines (87 loc) · 3.71 KB
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
CC = cc
CFLAGS = -std=c99 -Wall -Werror -Wextra -pedantic -Wno-unused-parameter -g -O0
DEFINES = -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE
TARGET = clf
SOURCES = main.c
ALL_SRCS = $(wildcard *.c)
COV_SRCS = color sixel preview draw nav os copy complete status command
HEADERS = $(wildcard *.h) $(wildcard include/*.h)
COV_TOOL = $(if $(findstring clang,$(CC)),llvm-cov gcov,gcov)
SAN_FLAGS = $(shell $(CC) -fsanitize=address -x c -E /dev/null 2>/dev/null >/dev/null && echo -n "-fsanitize=address ")$(shell $(CC) -fsanitize=undefined -x c -E /dev/null 2>/dev/null >/dev/null && echo -n "-fsanitize=undefined")
.PHONY: all clean install debug release test format run
all: $(TARGET)
$(TARGET): $(SOURCES) $(ALL_SRCS) $(HEADERS)
$(CC) $(CFLAGS) $(DEFINES) -o $(TARGET) $(SOURCES)
run: clean $(TARGET)
./$(TARGET)
clean:
@rm -f $(TARGET) test/$(TARGET)-test
@rm -rf test/coverage
install: $(TARGET)
cp $(TARGET) ~/.local/bin/
debug: CFLAGS += -DDEBUG -O0 -fsanitize=address,undefined
debug: $(TARGET)
release: CFLAGS = -std=c99 -Wall -Werror -Wextra -pedantic -Wno-unused-parameter -O3 -flto -DNDEBUG
release: $(TARGET)
test: test/test-all.c
@rm -rf test/coverage test/$(TARGET)-test *.gcno *.gcda *.gcov
$(CC) $(CFLAGS) -Wno-unused-variable -Wno-unused-function --coverage $(SAN_FLAGS) $(DEFINES) -o test/$(TARGET)-test test/test-all.c
ASAN_OPTIONS=detect_leaks=0 ./test/$(TARGET)-test
@mkdir -p test/coverage
@$(COV_TOOL) -o test/$(TARGET)-test-test-all.gcno color.c > /dev/null 2>&1; true
@mv *.gcov test/coverage/ 2>/dev/null || true
@mv test/*.gcda test/*.gcno test/coverage/ 2>/dev/null || true
@echo ""
@echo "Test coverage:"
@files=""; \
for f in $(addprefix test/coverage/,$(addsuffix .c.gcov,$(COV_SRCS))); do \
if [ -f "$$f" ]; then files="$$files $$f"; fi; \
done; \
if [ -n "$$files" ]; then \
awk -v srcs="$(COV_SRCS)" '\
BEGIN { n = split(srcs, covlist, " "); } \
/Source:/ { s = index($$0, "Source:"); cur = substr($$0, s + 7); \
sub(/^[ \t]+/, "", cur); \
execs[cur] = 0; unexs[cur] = 0; \
found[cur] = 1; } \
/^ *[0-9]+:/ { exec += 1; execs[cur] += 1; } \
/^ *#####:/ { unexec += 1; unexs[cur] += 1; } \
END { \
for (i = 1; i <= n; i++) { \
f = covlist[i] ".c"; \
fe = found[f] ? execs[f] : 0; \
fu = found[f] ? unexs[f] : 0; \
ft = fe + fu; \
fp = ft > 0 ? fe * 100.0 / ft : 0; \
printf "%-12s %3d / %-3d %5.1f%%\n", f, fe, ft, fp; \
total_exec += fe; total_unexec += fu; \
} \
total = total_exec + total_unexec; \
printf "%-12s %s\n", "", "-------"; \
if (total > 0) { \
tp = total_exec * 100.0 / total; \
printf "%-12s %3d / %-3d %5.1f%%\n", "", total_exec, total, tp; \
} else { \
print "No coverage data found."; \
} \
}' $$files; \
else \
for f in $(COV_SRCS); do \
printf "%-12s %3d / %-3d %5.1f%%\n", "$$f.c", 0, 0, 0.0; \
done; \
echo " -------"; \
echo "No coverage data found."; \
fi
format:
clang-format -i $(ALL_SRCS) $(HEADERS) $(wildcard test/*.c) $(wildcard test/*.h)
help:
@echo "Available targets:"
@echo " all - Build the file manager (default)"
@echo " clean - Remove built files"
@echo " install - Install to ~/.local/bin"
@echo " debug - Build with debug symbols and address sanitizer"
@echo " release - Build optimized release version"
@echo " run - Clean, build, and run"
@echo " test - Run all tests with coverage report (output in test/coverage/)"
@echo " format - Format all source files with clang-format"
@echo " help - Show this help message"