-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
135 lines (116 loc) · 3.37 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
NAME = push_swap
CC = cc
CFLAGS = -Wall -Wextra -Werror -g3
OBJ_DIR := ./obj
DEP_DIR := $(OBJ_DIR)/.deps
INC_DIRS := ./includes
SRC_DIRS := ./srcs
vpath %.c $(SRC_DIRS)
vpath %.h $(INC_DIRS)
vpath %.d $(DEP_DIR)
LIBFT_DIR = $(INC_DIRS)/libft
LIBFT = libft.a
LIBFT_LIB = $(LIBFT_DIR)/$(LIBFT)
LIBFTFLAGS = -L$(LIBFT_DIR) -lft
LIBFT_REPO = https://github.com/blueyaGIT/libft.git
RED = \033[31m
GREEN = \033[32m
YELLOW = \033[33m
BLUE = \033[34m
MAGENTA = \033[35m
CYAN = \033[36m
NC = \033[0m
CLEAR_LINE = \033[2K\r
# Source files
SRCS = algorithm.c \
algorithm_utils.c \
calc_rot_ab.c \
calc_rot_ba.c \
dup_check.c \
find_rotation.c \
main.c \
push.c \
sort.c \
sort_three.c \
spot.c \
stack_control.c \
stack_control2.c \
stack_control3.c \
stack_control_utils.c \
utils.c \
utils2.c
# Object files
OBJS := $(addprefix $(OBJ_DIR)/, $(SRCS:%.c=%.o))
TOTAL_SRCS = $(words $(SRCS))
CURRENT = 0
# Default rule to compile all
all: $(NAME)
-include $(OBJS:.o=.d)
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(@D)
@$(eval CURRENT := $(shell echo $$(($(CURRENT) + 1))))
@$(eval PERCENT := $(shell echo $$(($(CURRENT) * 100 / $(TOTAL_SRCS)))))
@printf "$(CLEAR_LINE)$(YELLOW)🚧 Compiling $(PERCENT)%% [$(CURRENT)/$(TOTAL_SRCS)] $(CYAN)$<$(NC) 🚧"
@$(CC) $(CFLAGS) -c $< -o $@
# Initialize submodules
init-submodules: init-libft
# Initialize libft
init-libft:
@sleep 0.15
@if [ ! -d "$(LIBFT_DIR)" ]; then \
echo "$(YELLOW)🚧 Adding LIBFT submodule 🚧$(NC)"; \
git submodule add $(LIBFT_REPO) $(LIBFT_DIR) > /dev/null 2>&1 || (echo "$(RED)Failed to add libft submodule$(NC)" && exit 1); \
elif [ -z "$$(ls -A $(LIBFT_DIR) 2>/dev/null)" ]; then \
echo "$(CYAN)🔄 Updating LIBFT submodule 🔄$(NC)"; \
git submodule update --init --recursive $(LIBFT_DIR) > /dev/null 2>&1 || (echo "$(RED)Failed to update libft submodule$(NC)" && exit 1); \
else \
echo "$(GREEN)✅ LIBFT submodule is already initialized ✅$(NC)"; \
fi
# Remove submodules
remove-submodules: remove-libft
# Remove libft
remove-libft:
@if [ -d "$(LIBFT_DIR)" ]; then \
git submodule deinit -q -f $(LIBFT_DIR) > /dev/null 2>&1; \
git rm -q -f $(LIBFT_DIR) > /dev/null 2>&1; \
rm -rf .git/modules/$(LIBFT_DIR) > /dev/null 2>&1; \
fi
# Rule to compile libft
$(LIBFT_LIB): init-libft
@if [ ! -f "$(LIBFT_LIB)" ]; then \
echo "$(CLEAR_LINE)$(YELLOW)🚧 Building LIBFT 🚧$(NC)"; \
$(MAKE) -C $(LIBFT_DIR); \
fi
# Rule to compile program
$(NAME): init-submodules $(LIBFT_LIB) $(OBJS)
@echo "$(CLEAR_LINE)$(YELLOW)🚧 Building PUSH_SWAP 🚧$(NC)"
@$(CC) -o $(NAME) $(OBJS) $(LIBFTFLAGS)
@echo "$(CLEAR_LINE)$(GREEN)✅ Done Compiling ✅$(NC)"
# Clean object files and libraries
clean: remove-submodules
@rm -rf $(OBJ_DIR)
@rm -rf $(LIBFT_DIR)
# Clean all generated files
fclean: clean
@echo "$(YELLOW)🚧 Cleaning 🚧$(NC)"
@sleep 0.15
@printf "$(RED)🧹 Cleaning in Progress 🧹$(NC)\n"
@sleep 0.15
@printf "$(YELLOW)🛁 Scrubbing Code 🛁$(NC)\n"
@sleep 0.15
@printf "$(CYAN)🧽 Polishing Project 🧽$(NC)\n"
@sleep 0.15
@printf "$(MAGENTA)🧴 Tidying Up 🧴$(NC)\n"
@sleep 0.15
@printf "$(GREEN)✅ Done Cleaning ✅$(NC)\n"
@rm -rf $(NAME)
# Rebuild everything
re: fclean all
# Rebuild everything faster
fastre: remove-submodules
@rm -rf $(OBJ_DIR)
@rm -rf $(LIBFT_DIR)
@rm -rf $(NAME)
@make
# Phony targets
.PHONY: all clean fclean re libft init-submodules remove-submodules fastre