-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
62 lines (43 loc) · 1.54 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
CXX = clang++
SOURCE_DIR = src
BUILD_DIR = build
INCLUDE_DIR = include
DEBUG_DIR = $(BUILD_DIR)/debug
SANITIZED_DIR = $(BUILD_DIR)/sanitized
RELEASE_DIR = $(BUILD_DIR)/release
OBJS = $(patsubst $(SOURCE_DIR)/%.cpp, %.o, $(wildcard $(SOURCE_DIR)/*.cpp))
CXXFLAGS += -std=c++17 -Wall -Werror -g -I $(INCLUDE_DIR)
DEBUG_FLAGS = $(CXXFLAGS)
SANITIZED_FLAGS = $(DEBUG_FLAGS) -fsanitize=address,undefined,leak
RELEASE_FLAGS = $(DEBUG_FLAGS) -O3
all: debug sanitized release
debug: debug_dir $(DEBUG_DIR)/main
sanitized: sanitized_dir $(SANITIZED_DIR)/main
release: release_dir $(RELEASE_DIR)/main
#dirs
debug_dir:
mkdir -p $(DEBUG_DIR)/obj
sanitized_dir:
mkdir -p $(SANITIZED_DIR)/obj
release_dir:
mkdir -p $(RELEASE_DIR)/obj
# object files
$(DEBUG_DIR)/obj/%.o: $(SOURCE_DIR)/%.cpp
$(CXX) -c $(DEBUG_FLAGS) $< -o $@
$(SANITIZED_DIR)/obj/%.o: $(SOURCE_DIR)/%.cpp
$(CXX) -c $(SANITIZED_FLAGS) $< -o $@
$(RELEASE_DIR)/obj/%.o: $(SOURCE_DIR)/%.cpp
$(CXX) -c $(RELEASE_FLAGS) $< -o $@
# executable files
$(DEBUG_DIR)/main: $(patsubst %.o, $(DEBUG_DIR)/obj/%.o, $(OBJS))
$(CXX) $(DEBUG_FLAGS) -lpthread $^ -o $@
$(SANITIZED_DIR)/main: $(patsubst %.o, $(SANITIZED_DIR)/obj/%.o, $(OBJS))
$(CXX) $(SANITIZED_FLAGS) -lpthread $^ -o $@
$(RELEASE_DIR)/main: $(patsubst %.o, $(RELEASE_DIR)/obj/%.o, $(OBJS))
$(CXX) $(RELEASE_FLAGS) -lpthread $^ -o $@
# clang-tide
clang-tidy:
clang-tidy $(SOURCE_DIR)/*.cpp -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* -- $(SANITIZED_FLAGS)
clean:
rm -rf $(BUILD_DIR)
.PHONY: clean debug_dir sanitized_dir release_dir