-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
102 lines (78 loc) · 2.59 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
92
93
94
95
96
97
98
99
100
101
EXEC := chessmaster
CC := g++
CFLAGS := -Wall -Werror -Wextra -std=c++20
SPATH := srcs
OPATH := objs
HPATH := includes
IPATHS := -I./$(HPATH)
SRCS := $(shell find $(SPATH) -name *.cpp)
INC := $(shell find $(HPATH) -name *.hpp)
OBJ := $(SRCS:$(SPATH)/%.cpp=$(OPATH)/%.o)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
IPATHS += -I/usr/local/opt/ncurses/include
LIBS += -L/usr/local/opt/ncurses/lib -lncurses
DEBUGGER := lldb
endif
ifeq ($(UNAME_S), Linux)
LIBS += -lncursesw
DEBUGGER := gdb
endif
EXEC_TEST := test.out
SPATH_TEST := tests
IPATHS_TEST := $(IPATHS) -I./libs/catch/includes
SRCS_TEST := $(wildcard $(SPATH_TEST)/*.cpp)
OBJ_TEST := $(filter-out $(OPATH)/main.o, $(OBJ)) $(SRCS_TEST:$(SPATH_TEST)/%.cpp=$(OPATH)/%.o)
WHITE := \033[0m
DARK := \033[1;35m
RED := \033[1;31m
GREENB := \033[1;32m
GREEN := \033[0;32m
YELLOW := \033[33m
CYAN := \033[36m
.PHONY: clean fclean all debug test
all: $(EXEC)
$(EXEC): $(OBJ)
@$(CC) -o $@ $^ $(CFLAGS) $(IPATHS) $(LIBS) \
&& printf "$(YELLOW)%-40s$(DARK)-->>\t$(GREEN)$@$(WHITE)\n" "Compilation"\
|| (printf "$(YELLOW)%-40s$(DARK)-->>\t$(RED)$@$(WHITE)\n" "Compilation" \
&& exit 1)
$(OPATH)/%.o: $(SPATH)/%.cpp
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) $(IPATHS) -o $@ -c $< \
&& printf "%-40s$(DARK)-->>\t$(GREEN)$@$(WHITE)\n" "$<" \
|| (printf "%-40s$(DARK)-->>\t$(RED)$@$(WHITE)\n" "$<" \
&& exit 1)
debug: CFLAGS += -g
debug: $(OPATH) $(EXEC) $(INC)
$(DEBUGGER) $(EXEC)
leaks: CFLAGS += -ggdb3
leaks: $(OPATH) $(EXEC) $(INC)
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes \
./$(EXEC)
test: $(EXEC_TEST) $(INC)
$(EXEC_TEST): $(OBJ_TEST)
@$(CC) -o $@ $^ $(CFLAGS) $(IPATHS_TEST) $(LIBS) \
&& printf "$(YELLOW)%-40s$(DARK)-->>\t$(GREEN)$@$(WHITE)\n" "Compilation"\
|| (printf "$(YELLOW)%-40s$(DARK)-->>\t$(RED)$@$(WHITE)\n" "Compilation" \
&& exit 1)
$(OPATH)/%.o: $(SPATH_TEST)/%.cpp
@$(CC) $(CFLAGS) $(IPATHS_TEST) -o $@ -c $< \
&& printf "%-40s$(DARK)-->>\t$(GREEN)$@$(WHITE)\n" "$<" \
|| (printf "%-40s$(DARK)-->>\t$(RED)$@$(WHITE)\n" "$<" \
&& exit 1)
clean:
@printf "%-40s" "Deleting $(OPATH)"
@rm -r $(OPATH) 2> /dev/null \
&& printf "$(GREENB)<<--$(WHITE)\n" \
|| printf "$(YELLOW)<<--$(WHITE)\t$(YELLOW)Doesn't exist$(WHITE)\n"
fclean: clean
@printf "%-40s" "Deleting $(EXEC)"
@rm $(EXEC) 2> /dev/null \
&& printf "$(GREENB)<<--$(WHITE)\n" \
|| printf "$(YELLOW)<<--$(WHITE)\t$(YELLOW)Doesn't exist$(WHITE)\n"
@printf "%-40s" "Deleting $(EXEC_TEST)"
@rm $(EXEC_TEST) 2> /dev/null \
&& printf "$(GREENB)<<--$(WHITE)\n" \
|| printf "$(YELLOW)<<--$(WHITE)\t$(YELLOW)Doesn't exist$(WHITE)\n"
re: fclean all