-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
79 lines (63 loc) · 2.68 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
COMPILER = clang++
CFLAGS = -O2 -Wall -g --target=x86_64-unknown-none-elf -g -ffreestanding -mno-red-zone -fno-exceptions -fno-rtti -std=c++20 -I $(SRCDIR)
HEADERS = $(filter-out %bits, $(filter-out %common, $(filter-out %spec, $(notdir $(wildcard $(SRCDIR)*)))))
INCLUDEDIR = ./include/
SRCDIR = ./src/
TEMPDIR = ./temp/
TESTDIR = ./test/
SPECDIR = spec/
COMMONDIR = common/
BITSDIR = bits/
BITS = $(notdir $(wildcard $(SRCDIR)$(BITSDIR)*.hpp))
SPECSRC = $(wildcard $(SRCDIR)$(SPECDIR)*.cpp)
COMMONSRC = $(wildcard $(SRCDIR)$(COMMONDIR)*.cpp)
TESTSRC = $(wildcard $(TESTDIR)*.cpp)
SPECOBJECTS = $(addprefix $(TEMPDIR)$(SPECDIR), $(notdir $(SPECSRC:.cpp=.o)))
COMMONOBJECTS = $(addprefix $(TEMPDIR)$(COMMONDIR), $(notdir $(COMMONSRC:.cpp=.o)))
TESTOBJECTS = $(addprefix $(TEMPDIR)test/, $(notdir $(TESTSRC:.cpp=.o)))
define add_compile_commands
@echo "{" >> compile_commands.json
@echo "\"directory\": \"$(shell pwd)\"," >> compile_commands.json
@echo "\"command\": \"$(COMPILER) $(CFLAGS) -o $(1:.cpp=.o) -c $(1)\"," >> compile_commands.json
@echo "\"file\": \"$(1)\"" >> compile_commands.json
@echo "}," >> compile_commands.json
endef
build:copyheaders copybits ./lib/libozstd.a ./lib/libcommonstd.a
./lib/libozstd.a: $(SPECOBJECTS)
ar rcs $@ $^
./lib/libcommonstd.a: $(COMMONOBJECTS)
ar rcs $@ $^
$(TEMPDIR)%.o: $(SRCDIR)%.cpp
mkdir -p $(dir $@)
$(COMPILER) $(CFLAGS) -o $@ -c $<
copyheaders: $(addprefix $(INCLUDEDIR), $(HEADERS))
copybits: $(addprefix $(INCLUDEDIR)$(BITSDIR), $(BITS))
$(INCLUDEDIR)%: $(SRCDIR)%
mkdir -p $(dir $@)
cp $< $@
$(TEMPDIR)test/%.o: $(TESTDIR)%.cpp
mkdir -p $(dir $@)
$(COMPILER) $(CFLAGS) -o $@ -c $<
test: $(TESTOBJECTS)
$(foreach file, $(TESTSRC), clang-tidy -p ./ -header-filter=.* -system-headers $(file);)
clean:
rm -rf $(TEMPDIR)*
rm -rf $(INCLUDEDIR)*
rm ./lib/*
setup: compile_commands.json
compile_commands.json:
@echo "[" > compile_commands.json
$(foreach file, $(SPECSRC), $(call add_compile_commands, $(file)))
$(foreach file, $(COMMONSRC), $(call add_compile_commands, $(file)))
$(foreach file, $(TESTSRC), $(call add_compile_commands, $(file)))
@echo "{" >> compile_commands.json
@echo "\"directory\": \"placeholder\"," >> compile_commands.json
@echo "\"command\": \"placeholder\"," >> compile_commands.json
@echo "\"file\": \"placeholder\"" >> compile_commands.json
@echo "}" >> compile_commands.json
@echo "]" >> compile_commands.json
lint:
$(foreach file, $(SPECSRC), clang-tidy -p ./ $(file);)
$(foreach file, $(COMMONSRC), clang-tidy -p ./ $(file);)
$(foreach file, $(TESTSRC), clang-tidy -p ./ $(file);)
.PHONY: setup copyheaders copybits clean build test lint