-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
108 lines (78 loc) · 2.33 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
102
103
104
105
106
107
108
##
## EPITECH PROJECT, 2021
## makefile
## File description:
## c makefile by Erudyx
##
MAKEFLAGS += --no-print-directory -j
END=\e[0m
GREEN=\e[92m
RED=\x1b[31;01m
YELLOW=\x1b[33;
define rich_echo
[ -t 1 ] && echo -e "\e[1m$(1)\e[0m\t$(2)" || echo -e "$(0)\t$(2)"
endef
SOURCE_DIR = src
BUILD_DIR = build
SOURCE = $(shell find $(SOURCE_DIR) -name "*.c")
TEST_SOURCE = $(shell find $(SOURCE_DIR) -name "*.c" -not -name "main.cpp")
OBJ = $(patsubst $(SOURCE_DIR)/%.c,$(BUILD_DIR)/%.o,$(SOURCE))
TEST_OBJ = $(patsubst $(SOURCE_DIR)/%.c,$(BUILD_DIR)/%.o,$(TEST_SOURCE))
NAME = myftp
CPPFLAGS += -I./include -g
CFLAGS += -O2 -W -Wall -Wextra
ifneq (,$(findstring debug,$(MAKECMDGOALS)))
CPPFLAGS += -g3
endif
ifneq (,$(findstring tests,$(MAKECMDGOALS)))
CPPFLAGS += -D__TESTS -lgtest -lgtest_main --coverage
endif
all:: $(NAME)
all:: message
message:
@echo -e "\e[38;5;33m"
@figlet $(NAME); exit 0
@echo -e "\e[0m"
@echo -e "\e[1m[INFO]\t$(GREEN)Compilation successful ✔$(END)"
$(NAME): $(OBJ)
@$(CC) -o $@ $^ $(CFLAGS)
.SECONDEXPANSION:
$(BUILD_DIR)/%.o: override CPPFLAGS += -MT $@ -MMD -MP -MF $(@:.o=.d)
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c | $$(@D)/.
@$(call rich_echo,"CC","$@")
@mkdir -p $(@D)
@$(CC) $(CPPFLAGS) -c $< -o $@
$(BUILD_DIR)/.:
@mkdir -p $@
$(BUILD_DIR)%/.:
@mkdir -p $@
.PRECIOUS: $(BUILD_DIR)/. $(BUILD_DIR)%/.
clean:
@rm -rfv $(shell find $(BUILD_DIR) -name "*.o")
@rm -rfv $(shell find $(BUILD_DIR) -name "*.d")
debug: $(OBJ)
@$(CC) -o $(NAME).debug $(CPPFLAGS) $^
@$(call rich_echo,"🔨","Debug biniary set")
fclean: clean
@rm -fv $(NAME) $(NAME).debug $(NAME).gtest
tests_run: $(OBJ)
@$(CC) -o $(NAME).gtest $(TEST_OBJ) $(CPPFLAGS) tests/*.cpp
@$(call rich_echo,"🔨","Unit tests building done")
./$(NAME).gtest
@gcovr --exclude tests
$(CLEAR)
re:: fclean
re:: all
.PHONY: all clean fclean re debug test DOLIB
-include $(OBJ:.o=.d)
# CC: compilateur C (gcc, clang)
# CPP: compilateur préprocesseur C/C++ (gcc, clang, g++, clang++)
# CXX: compilateur C++ (g++, clang++)
# LD: linker (ld, gcc, ...)
# CFLAGS: flag compilo C (-W, -Wall, --coverage, -g)
# CPPFLAGS flag compilo C/C++ PREPROCESSOR (-Include)
# CXXFLAGS flag compilo C++ (-W ..., -std=c++14)
# LDLIBS: lib pour le linker (-lmy, -lcriterion)
# LDFLAGS: flag pour le linker (-Llib)
#
#