-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
148 lines (128 loc) · 4.71 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
###############################
# COLORS #
###############################
GREEN = \033[1;32m
YELLOW = \033[1;33m
RED = \033[1;31m
BLUE = \033[34m
MAGENTA = \033[35m
ORANGE = \033[1;38;5;208m
STOP_COLOR = \033[0m
###############################
# COMPILATION #
###############################
CC = cc
GCC = cc
CFLAGS = -Wall -Wextra -Werror -g
###############################
# COMMANDS #
###############################
RM = rm -rf
###############################
# SRCS/OBJS #
###############################
LIBFTDIR = libft/
LIBFTLIB = libft/libft.a
SRC = ft_general_utils.c ft_val_utils.c mov_push.c \
mov_revrotate.c mov_rotate.c \
mov_swap.c srt_sorting_calculation.c \
srt_sorting_operations.c st_list_utils.c \
st_stack_definition.c st_stack_utils.c \
SRC_DIR = ./source/
OBJ = $(addprefix $(OBJDIR), $(SRC:.c=.o))
OBJDIR = objs/
NAME = push_swap
INPUT = 1 3 5 -10 -50 87 6
###############################
# BONUS => SRCS/OBJS #
###############################
BONUS_OBJDIR = bonus/bonus_objs/
BONUS_NAME = checker
BONUS_SRC = bonus/checker_bonus.c bonus/ft_utils_bonus.c \
bonus/ft_val_utils_bonus.c bonus/get_next_line_bonus.c \
bonus/get_next_line_utils_bonus.c bonus/mov_bonus.c
BONUS_OBJ = $(addprefix $(BONUS_OBJDIR), $(BONUS_SRC:bonus/%.c=%.o))
#######################################################################
# PUSH_SWAP - RULES #
#######################################################################
#main rule
all : $(NAME)
#create a directory for the objects
$(OBJDIR) :
@echo "$(YELLOW)[!] $(STOP_COLOR)CREATING DIRECTORY FOR OBJECTS"
mkdir $@
@echo "$(GREEN)[✔]$(STOP_COLOR) CREATED $@ DIRECTORY"
#compile the project
$(NAME) : $(OBJ) $(LIBFTLIB)
@echo "$(YELLOW)[!] $(STOP_COLOR)COMPILING PROJECT "
$(CC) $(CFLAGS) $(OBJ) $(SRC_DIR)push_swap.c $(LIBFTLIB) -o $(NAME)
@echo "$(GREEN)[✔]$(STOP_COLOR) $(BLUE)OK$(STOP_COLOR)"
#compile the objects and display a message for the first time created
#or in case of modification
$(OBJDIR)%.o: $(SRC_DIR)%.c | $(OBJDIR)
@$(CC) $(CFLAGS) -c $< -o $@
@if [ -n "$(shell find $< -newer $(OBJDIR)$*.o -print -quit)" ]; then \
echo "$(GREEN)[✔]$(STOP_COLOR) $(ORANGE)UPDATE OF $< DONE$(STOP_COLOR)"; \
else \
echo "$(YELLOW)[!]$(STOP_COLOR) $(ORANGE)Creating $<$(STOP_COLOR)"; \
$(CC) $(CFLAGS) -c $< -o $@; \
fi
#Create lib for libft
$(LIBFTLIB) : $(LIBFTDIR)
echo "$(YELLOW)[!] $(STOP_COLOR)COMPILING LIBFT"
make -C $(LIBFTDIR) bonus
make -C ./libft/ft_printf
#clean the .o objects
clean :
echo "$(YELLOW)[!] $(STOP_COLOR)CLEANING"
rm -rf $(OBJDIR)
make clean -C $(LIBFTDIR)
echo "$(GREEN)[✔]$(STOP_COLOR) $(BLUE)CLEAN DONE.$(STOP_COLOR)"
#clean the .o objects, the objs folder and the project file.
fclean :
echo "$(YELLOW)[!] $(STOP_COLOR)FULL CLEANING"
$(RM) $(NAME) $(OBJDIR)
make fclean -C $(LIBFTDIR)
echo "$(GREEN)[✔]$(STOP_COLOR) $(BLUE)FULL CLEANING DONE. $(STOP_COLOR)"
#refresh the project
re : fclean all
echo "$(GREEN)[✔]$(STOP_COLOR) $(MAGENTA)REFRESH DONE.$(STOP_COLOR)"
#######################################################################
# BONUS - RULES #
#######################################################################
#compile the bonus
bonus : $(BONUS_NAME)
#Create directory for the bonus objects
$(BONUS_OBJDIR) :
@echo "$(YELLOW)[!] $(STOP_COLOR)CREATING DIRECTORY FOR BONUS OBJECTS"
@mkdir $@
@echo "$(GREEN)[✔]$(STOP_COLOR) CREATED $@ DIRECTORY"
# Rule to compile bonus objects
$(BONUS_OBJDIR)%.o : bonus/%.c | $(BONUS_OBJDIR)
@echo "$(YELLOW)[!] $(STOP_COLOR)COMPILING $< "
$(CC) $(CFLAGS) -c $< -o $@
@echo "$(GREEN)[✔]$(STOP_COLOR) COMPILED $<"
$(BONUS_NAME) : $(BONUS_OBJDIR) $(BONUS_OBJ) $(OBJ) $(LIBFTLIB)
@echo "$(YELLOW)[!] $(STOP_COLOR)COMPILING BONUS "
$(CC) $(CFLAGS) $(BONUS_OBJ) $(OBJ) $(LIBFTLIB) -o bonus/$(BONUS_NAME)
@echo "$(GREEN)[✔]$(STOP_COLOR) $(BLUE)OK$(STOP_COLOR)"
bonus_clean :
echo "$(YELLOW)[!] $(STOP_COLOR)CLEANING BONUS"
$(RM) $(BONUS_OBJDIR)
make clean -C $(LIBFTDIR)
echo "$(GREEN)[✔]$(STOP_COLOR) $(BLUE)BONUS CLEAN.$(STOP_COLOR)"
bonus_fclean :
echo "$(YELLOW)[!] $(STOP_COLOR)BONUS FULL CLEANING"
$(RM) bonus/$(BONUS_NAME) $(BONUS_OBJDIR)
make fclean -C $(LIBFTDIR)
echo "$(GREEN)[✔]$(STOP_COLOR) $(BLUE)BONUS FULL CLEANING DONE. $(STOP_COLOR)"
#######################################################################
# EXTRA RULES #
#######################################################################
#rule to valgrind
valgrind : $(NAME)
$(GCC) $(CFLAGS) $(OBJ) $(LIBFTLIB) -o $(NAME)
valgrind -s --leak-check=full ./$(NAME) $(INPUT)
make clean
./push_swap $(INPUT)
.SILENT :