-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
173 lines (138 loc) · 3.77 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
##
## EPITECH PROJECT, 2023
## my_ls
## File description:
## Makefile for my_ls
##
# ↓ Basic variables
CC := gcc -std=gnu11
CFLAGS := -W -Wall -Wextra -Wunused -Wpedantic
CFLAGS += -Wundef -Wshadow -Wcast-align
CFLAGS += -Wstrict-prototypes -Wmissing-prototypes
CFLAGS += -Waggregate-return -Wcast-qual
CFLAGS += -Wunreachable-code
CFLAGS += -U_FORTIFY_SOURCE
CFLAGS += -iquote ./include
# ↓ Binaries
NAME := my_ls
TEST_NAME := unit_tests
ASAN_NAME := asan
PROF_NAME := prof
# Libmy
LIBMY := lib/libmy.a
LDFLAGS := -L./$(dir $(LIBMY)) -lmy
# Source files
VPATH := src
SRC := my_ls.c
SRC += get_files.c
SRC += sort_files.c
SRC += params.c
SRC += clear.c
SRC += print_format/long.c
SRC += print_format/normal.c
SRC += print_format/print.c
# Tests files
VPATH += tests
TEST_SRC := $(SRC)
TEST_SRC += test_sort_paths.c
TEST_SRC += test_params.c
TEST_SRC += test_clear.c
TEST_SRC += test_my_ls_normal.c
TEST_SRC += test_my_ls_long.c
SRC += main.c
# ↓ Objects
BUILD_DIR := .build
OBJ := $(SRC:%.c=$(BUILD_DIR)/source/%.o)
TEST_OBJ := $(TEST_SRC:%.c=$(BUILD_DIR)/tests/%.o)
ASAN_OBJ := $(SRC:%.c=$(BUILD_DIR)/asan/%.o)
PROF_OBJ := $(SRC:%.c=$(BUILD_DIR)/prof/%.o)
# ↓ Dependencies for headers
DEPS_FLAGS := -MMD -MP
DEPS := $(OBJ:.o=.d)
TEST_DEPS := $(TEST_OBJ:.o=.d)
ASAN_DEPS := $(ASAN_OBJ:.o=.d)
PROF_DEPS := $(PROF_OBJ:.o=.d)
DIE := exit 1
# ↓ Colors
ECHO := echo -e
C_RESET := \033[00m
C_BOLD := \e[1m
C_RED := \e[31m
C_GREEN := \e[32m
C_YELLOW := \e[33m
C_BLUE := \e[34m
C_PURPLE := \e[35m
C_CYAN := \e[36m
all: $(NAME)
.PHONY: all
# ↓ Compiling libmy
$(LIBMY):
@ $(MAKE) -s -C $(dir $(LIBMY))/my
libmy: $(LIBMY)
.PHONY: libmy
# ↓ Compiling
$(BUILD_DIR)/source/%.o: %.c $(LIBMY)
@ mkdir -p $(dir $@)
@ $(ECHO) "[${C_BOLD}${C_RED}CC${C_RESET}] $^"
@ $(CC) -o $@ -c $< $(CFLAGS) $(DEPS_FLAGS) || $(DIE)
$(NAME): $(LIBMY) $(OBJ)
@ $(ECHO) "[${C_BOLD}${C_YELLOW}CC${C_RESET}] ${C_GREEN}$@${C_RESET}"
@ $(CC) -o $@ $(OBJ) $(CFLAGS) $(LDFLAGS) || $(DIE)
.PHONY: $(NAME)
# ↓ Unit tests
$(BUILD_DIR)/tests/%.o: %.c $(LIBMY)
@ mkdir -p $(dir $@)
@ $(ECHO) "[${C_BOLD}${C_RED}CC${C_RESET}] $^"
@ $(CC) -o $@ -c $< $(CFLAGS) $(DEPS_FLAGS) || $(DIE)
ifneq ($(NO_COV), 1)
$(TEST_NAME): CFLAGS += -g3 --coverage
endif
$(TEST_NAME): CFLAGS += -lcriterion
$(TEST_NAME): $(LIBMY) $(TEST_OBJ)
@ $(ECHO) "[${C_BOLD}${C_YELLOW}CC${C_RESET}] ${C_GREEN}$@${C_RESET}"
@ $(CC) -o $@ $(TEST_OBJ) $(CFLAGS) $(LDFLAGS) || $(DIE)
tests_run: fclean $(TEST_NAME)
@-./$(TEST_NAME)
.PHONY: $(TEST_NAME) tests_run
# ↓ Asan
$(BUILD_DIR)/asan/%.o: %.c $(LIBMY)
@ mkdir -p $(dir $@)
@ $(ECHO) "[${C_BOLD}${C_RED}CC${C_RESET}] $^"
@ $(CC) -o $@ -c $< $(CFLAGS) $(DEPS_FLAGS) || $(DIE)
$(ASAN_NAME): CFLAGS += -fsanitize=address,leak,undefined -g3
$(ASAN_NAME): $(LIBMY) $(ASAN_OBJ)
@ $(ECHO) "[${C_BOLD}${C_YELLOW}CC${C_RESET}] ${C_GREEN}$@${C_RESET}"
@ $(CC) -o $@ $(ASAN_OBJ) $(CFLAGS) $(LDFLAGS) || $(DIE)
.PHONY: $(ASAN_NAME)
# ↓ Profiler
$(BUILD_DIR)/prof/%.o: %.c $(LIBMY)
@ mkdir -p $(dir $@)
@ $(ECHO) "[${C_BOLD}${C_RED}CC${C_RESET}] $^"
@ $(CC) -o $@ -c $< $(CFLAGS) $(DEPS_FLAGS) || $(DIE)
$(PROF_NAME): CFLAGS += -pg
$(PROF_NAME): $(LIBMY) $(PROF_OBJ)
@ $(ECHO) "[${C_BOLD}${C_YELLOW}CC${C_RESET}] ${C_GREEN}$@${C_RESET}"
@ $(CC) -o $@ $(PROF_OBJ) $(CFLAGS) $(LDFLAGS) || $(DIE)
.PHONY: $(PROF_NAME)
# ↓ Coverage
cov: GCOVR_FLAGS := --exclude bonus/
cov: GCOVR_FLAGS += --exclude tests/
cov:
@ gcovr $(GCOVR_FLAGS)
@ gcovr $(GCOVR_FLAGS) --branches
.PHONY: cov
# ↓ Cleaning
clean:
@ $(RM) $(OBJ) $(TEST_OBJ) $(ASAN_OBJ)
fclean: clean
@ $(RM) $(NAME) $(TEST_NAME) $(ASAN_NAME) $(PROF_NAME)
@ $(RM) -r $(BUILD_DIR)
@ $(MAKE) -s -C $(dir $(LIBMY))/my fclean
.PHONY: clean fclean
re: fclean
@ $(MAKE) -s -C .
.PHONY: re
-include $(DEPS)
-include $(TEST_DEPS)
-include $(ASAN_DEPS)
-include $(PROF_DEPS)