-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
84 lines (59 loc) · 1.57 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
NAME := kilo
SRC_DIR := src
BIN_DIR := bin
TEST_DIR := test
MAIN := $(BIN_DIR)/$(NAME)
MAIN_TEST := $(BIN_DIR)/test
CXX := clang++
LANG := -x c++
STD := -std=c++20
WARNINGS := -Wall -Wextra -Wpedantic -Weffc++ -Wconversion -Wshadow \
-Wnon-virtual-dtor -Wcast-align -Woverloaded-virtual \
-Wnull-dereference -Wno-unused-parameter -Wno-unused-function \
-Wno-unused-variable
OPTM := -O0
CXXFLAGS := $(LANG) $(STD) $(WARNINGS) $(OPTM)
LD := clang++
LIB :=
SAN := -fsanitize=address,undefined
LDFLAGS := $(SAN) $(LIB)
TEST_ARGUMENTS := --gtest_filter=*
src := $(shell find $(SRC_DIR) -type f -name "*.cpp")
obj := $(src:.cpp=.o)
test_header := $(shell grep -roh '\.\./src/.*\.hpp' test | sort | uniq | sed 's;\.\./;;')
test_src := $(shell find $(TEST_DIR) -type f -name "*.cpp") \
$(test_header:.hpp=.cpp)
test_obj := $(test_src:.cpp=.o)
.PHONY: all run init debug build test clean clean_test fclean leak generate_cc
all: build
run: build
./$(MAIN)
runf: build
./$(MAIN) testfile
runc: build
./$(MAIN) testfile.cpp
runm: build
./$(MAIN) makefile
debug: CXXFLAGS += -g
debug: fclean build
test: LDFLAGS += -lgtest
test: CXXFLAGS += -g
test: $(MAIN_TEST)
./$(MAIN_TEST) $(TEST_ARGUMENTS)
build: $(MAIN)
$(MAIN): $(obj)
@test -d bin || mkdir bin
$(LD) $(obj) $(LDFLAGS) -o $(MAIN)
$(MAIN_TEST): $(test_obj)
$(LD) $(test_obj) $(LDFLAGS) -o $(MAIN_TEST)
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $^ -o $@
clean:
$(RM) $(obj)
fclean: clean
$(RM) $(BIN_DIR)/*
find . -type f -name "*.o" -delete
leak: $(MAIN)
valgrind --leak-check=full $(MAIN)
generate_cc:
bear -- make