-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
66 lines (46 loc) · 1.5 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
.SILENT:
# Name of the executable file to be generated
NAME = push_swap
CHECKER = checker
# Compiler
CC = cc -g
FLAGS = -Wall -Wextra -Werror -fsanitize=address
RM = /bin/rm -rf
# Directory to store object files
OBJS_DIR = objs/
# Color codes for terminal output
RESET = \033[0m
GREEN = \033[1;32m
# Directories containing source files
SRC_DIRS := srcs
# Find all .c files recursively within SRC_DIRS
SRCS := $(shell find $(SRC_DIRS) -name '*.c')
# Generate object file paths from source file paths
OBJS := $(patsubst $(SRC_DIRS)/%.c,$(OBJS_DIR)%.o,$(SRCS))
# Compilation output
COMPILE_COUNT = 0
NUM_SRCS = $(words $(SRCS))
# Default target
all: $(NAME)
bonus: $(CHECKER)
$(NAME): EXEC_NAME = $(NAME)
$(CHECKER): EXEC_NAME = $(CHECKER)
$(CHECKER) $(NAME): $(OBJS)
@$(CC) $(FLAGS) $(OBJS) -o $(EXEC_NAME)
# Rule to compile each source file into an object file
# Also prints a progress bar
$(OBJS_DIR)%.o: $(SRC_DIRS)/%.c
@mkdir -p $(dir $@)
@$(CC) $(FLAGS) -c $< -o $@
@$(eval COMPILE_COUNT=$(shell echo $$(($(COMPILE_COUNT)+1))))
@printf "\r[$(GREEN)%3d%%$(RESET)] Compiling: $<" $$(($(COMPILE_COUNT) * 100 / $(NUM_SRCS)))
# Rule to clean object files
clean:
$(RM) $(OBJS_DIR)
# Rule to clean object files and the executables
fclean: clean
$(RM) $(NAME) $(CHECKER)
# Rule to clean object files, the executables, and recompile
re: fclean all
# Phony targets
.PHONY: all clean fclean re bonus