-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
101 lines (81 loc) · 2.48 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
##
## EPITECH PROJECT, 2022
## Makefile
## File description:
## Makefile
##
PROJECT_NAME = 42sh
NAME = 42sh
SRC := $(shell find src/ -name '*.c' -type f \
| xargs grep -L "int main")
MAIN = src/main.c
BUILD_DIR = build
OBJ = $(SRC:%.c=$(BUILD_DIR)/%.o) \
$(MAIN:%.c=$(BUILD_DIR)/%.o)
LIB_FOLDER = mars_lib
CFLAGS := -I include/ \
-I $(LIB_FOLDER)/include/ \
-I $(LIB_FOLDER)/my_printf/include/ \
-I $(LIB_FOLDER)/my_stdlib/include/
WFLAGS := -Wall -Wextra
LDLIBS := -L $(LIB_FOLDER) -lmars
CRITERION = -lcriterion --coverage
TEST_SRC = tests/basics.c
TEST_NAME = unit_tests
BUILD_TESTS_DIR = $(BUILD_DIR)/tests
TESTS_OBJ = $(TEST_SRC:%.c=$(BUILD_DIR)/%.o)
all: $(NAME)
$(NAME): $(OBJ)
@mkdir -p $(BUILD_DIR)
@make -s -C $(LIB_FOLDER)
@gcc -o $(NAME) $(OBJ) $(CFLAGS) $(WFLAGS) $(LDLIBS)\
&& echo -e "\033[1;32m[OK]\033[0m" $(NAME)\
|| echo -e "\033[1;31m[KO]\033[0m" $(NAME)
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(dir $@)
@gcc -c -o $@ $< $(CFLAGS) $(WFLAGS)\
&& echo -e "\033[1;32m[OK]\033[0m" $<\
|| echo -e "\033[1;31m[KO]\033[0m" $<
debug: CFLAGS += -g3
debug: re
clean:
@make -s -C $(LIB_FOLDER) clean
@echo -e "\033[1;31m[LIB CLEAN]\033[0m" $(LIB_FOLDER)
@for file in $(BUILD_DIR)/*; do\
if [ -d $$file ]; then\
rm -rf $$file;\
echo -e "\033[1;31m[DELETED]\033[0m" $$file;\
fi;\
done
@echo -e "\033[1;31m[CLEAN]\033[0m" $(PROJECT_NAME)
@rm -f $(shell find -name '*.gc*' -type f)
fclean: clean
@make -s -C $(LIB_FOLDER) fclean
@echo -e "\033[1;31m[LIB FCLEAN]\033[0m" $(LIB_FOLDER)
@rm -f $(TEST_NAME)
@echo -e "\033[1;31m[DELETED]\033[0m" $(TEST_NAME)
@rm -rf $(BUILD_DIR)
@echo -e "\033[1;31m[DELETED]\033[0m" $(BUILD_DIR)
@rm -f $(NAME)
@echo -e "\033[1;31m[DELETED]\033[0m" $(NAME)
re: fclean all
tests_run: CFLAGS += -lcriterion --coverage
tests_run: re
@if [ ! -d "tests" ]; then\
echo -e "\033[1;31m[ERROR]\033[0m" "No tests directory";\
exit 1;\
fi
@make -s tests_run -C $(LIB_FOLDER)
@mkdir -p $(BUILD_DIR)
@mkdir -p $(BUILD_TESTS_DIR)
@gcc -o $(TEST_NAME) $(TEST_SRC) $(SRC) $(CFLAGS) $(WFLAGS) $(CRITERION) \
$(LDLIBS)\
&& echo -e "\033[1;32m[OK]\033[0m" $(TEST_NAME)\
|| echo -e "\033[1;31m[KO]\033[0m" $(TEST_NAME)
@./$(TEST_NAME) --verbose --always-succeed
mv *.gc* $(BUILD_TESTS_DIR)
gcovr --exclude tests/
.PHONY: all clean fclean re debug tests_run
.SILENT: all clean fclean re debug tests_run
%:
@echo -e "\033[1;31m[ERROR]\033[0m" "No rule to make target '$@'"