-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
78 lines (61 loc) · 2.25 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
################################################################################
## Code color ##
################################################################################
COLOR_NORM = \033[0m
COLOR_RED = \033[31m
COLOR_BLUE = \033[36m
################################################################################
## SRCS ##
################################################################################
CACHE = .cache
SRCS_DIR = srcs
SRCS = main.cpp \
Krpsim.cpp \
Process.cpp \
Stock.cpp \
Parser.cpp
NAME = krpsim
OBJS_DIR = build
OBJS = $(addprefix $(OBJS_DIR)/,$(subst $(SRCS_DIR),,$(SRCS:.cpp=.o)))
CC = c++
CFLAGS = -Wall -Wextra -Werror -MMD -MP -Iincludes -g3 -fstandalone-debug # -O3 -fsanitize=address
RM = rm -rf
# Set the number of object files
NUM_OBJS = $(words $(OBJS))
################################################################################
## Compilation Environnement ##
################################################################################
# Define a function to print the progress bar
define print_progress
$(eval i = $(shell expr $(i) + 1))
$(eval PERCENT = $(shell expr $(i) '*' 100 '/' $(NUM_OBJS)))
@if [ $(i) -eq 1 ]; then \
printf "$(COLOR_BLUE)Starting compilation...\n$(COLOR_NORM)"; \
fi
@printf "\r\033[K\t$(COLOR_BLUE)[$(PERCENT)%%]\t--> $(COLOR_NORM)$<\$(COLOR_NORM)"
@printf "\r\033[K\t$(COLOR_BLUE)[$(PERCENT)%%]\t--> $(COLOR_NORM)$<\$(COLOR_NORM)"
endef
# Compilation rule for object files
$(OBJS_DIR)/%.o : $(SRCS_DIR)/%.cpp
@mkdir -p $(dir $@)
$(call print_progress)
@$(CC) $(CFLAGS) -c $< -o $@
# Include the dependency files
-include $(OBJ:.o=.d)
# Default target
all: $(NAME)
# Link the final executable
$(NAME): $(OBJS)
@printf "\n[✅]\tCompilation of $(COLOR_PURPLE)$(NAME)\$(COLOR_NORM)\n"
@$(CC) $(CFLAGS) -o $(NAME) $(OBJS)
# Clean up object files and dependency files
clean:
@$(RM) $(OBJS_DIR)
@$(RM) $(DEPS_DIR)
@$(RM) $(CACHE)
# Clean up object files, dependency files, and the executable
fclean: clean
@$(RM) $(NAME)
# Rebuild everything
re: fclean all
.PHONY: all clean fclean re