-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
185 lines (156 loc) · 5.51 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
174
175
176
177
178
179
180
181
182
183
184
185
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: aperez-b <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/07/07 10:28:33 by aperez-b #+# #+# #
# Updated: 2023/04/05 13:44:45 by aperez-b ### ########.fr #
# #
# **************************************************************************** #
# Color Aliases
DEFAULT = \033[0;39m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
SHELL=/bin/bash
UNAME = $(shell uname -s)
PRINTF = echo
ifeq ($(UNAME), Linux)
PRINTF = echo -e
endif
# Make variables
PRINTF = printf
CC = gcc -MD
CFLAGS = -Wall -Wextra -Werror
AR = ar rcs
RM = rm -f
HEADER = libft.h
SRC_DIR = src
SRCB_DIR = srcb
SRCA_DIR = srca
OBJ_DIR = obj
OBJB_DIR = objb
OBJA_DIR = obja
BIN_DIR = bin
BIN = libft.a
NAME = $(BIN_DIR)/$(BIN)
SRC = ft_atoi.c ft_bzero.c \
ft_calloc.c ft_putendl_fd.c \
ft_itoa.c ft_putchar_fd.c \
ft_putstr_fd.c ft_memccpy.c \
ft_memchr.c ft_memcmp.c \
ft_memcpy.c ft_isalnum.c \
ft_isalpha.c ft_isascii.c \
ft_isdigit.c ft_isprint.c \
ft_memmove.c ft_memset.c \
ft_split.c ft_strchr.c \
ft_strdup.c ft_strjoin.c \
ft_strlcat.c ft_strlcpy.c \
ft_strlen.c ft_strmapi.c \
ft_strncmp.c ft_strnstr.c \
ft_strrchr.c ft_strtrim.c \
ft_substr.c ft_tolower.c \
ft_toupper.c ft_putnbr_fd.c
SRCB = ft_lstadd_back.c \
ft_lstadd_front.c \
ft_lstclear.c \
ft_lstdelone.c \
ft_lstiter.c \
ft_lstlast.c \
ft_lstsize.c \
ft_lstnew.c \
ft_lstmap.c \
ft_lstget_at.c
SRCA = ft_putnbr_base_fd.c ft_putstrn_fd.c \
ft_putnchar_fd.c ft_isspace.c ft_uitoa.c \
ft_nbrlen.c ft_strrncmp.c ft_countchar.c \
ft_strenlarge.c ft_recursive_power.c \
ft_chartostr.c ft_sqrt.c ft_newvector.c \
ft_euclideandistance.c ft_atoi2.c \
ft_free_matrix.c ft_dup_matrix.c \
ft_strchr_i.c ft_putmatrix_fd.c \
ft_matrixlen.c ft_strchars_i.c \
ft_between_chars.c ft_subsplit.c \
ft_extend_matrix.c ft_matrixtolst.c \
ft_lsttomatrix.c ft_matrix_replace_in.c
OBJ = $(addprefix $(OBJ_DIR)/, $(SRC:.c=.o))
OBJB = $(addprefix $(OBJB_DIR)/, $(SRCB:.c=.o))
OBJA = $(addprefix $(OBJA_DIR)/, $(SRCA:.c=.o))
# Progress vars
SRC_COUNT_TOT := $(shell expr $(shell echo -n $(SRC) | wc -w) - $(shell ls -l $(OBJ_DIR) 2>&1 | grep ".o" | wc -l) + 1)
ifeq ($(shell test $(SRC_COUNT_TOT) -lt 0; echo $$?),0)
SRC_COUNT_TOT := $(shell echo -n $(SRC) | wc -w)
endif
SRC_COUNT := 0
SRC_PCT = $(shell expr 100 \* $(SRC_COUNT) / $(SRC_COUNT_TOT))
SRCB_COUNT_TOT := $(shell expr $(shell echo -n $(SRCB) | wc -w) - $(shell ls -l $(OBJB_DIR) 2>&1 | grep ".o" | wc -l) + 1)
ifeq ($(shell test $(SRCB_COUNT_TOT) -lt 0; echo $$?),0)
SRCB_COUNT_TOT := $(shell echo -n $(SRCB) | wc -w)
endif
SRCB_COUNT := 0
SRCB_PCT = $(shell expr 100 \* $(SRCB_COUNT) / $(SRCB_COUNT_TOT))
SRCA_COUNT_TOT := $(shell expr $(shell echo -n $(SRCA) | wc -w) - $(shell ls -l $(OBJA_DIR) 2>&1 | grep ".o" | wc -l) + 1)
ifeq ($(shell test $(SRCA_COUNT_TOT) -lt 0; echo $$?),0)
SRCA_COUNT_TOT := $(shell echo -n $(SRCA) | wc -w)
endif
SRCA_COUNT := 0
SRCA_PCT = $(shell expr 100 \* $(SRCA_COUNT) / $(SRCA_COUNT_TOT))
all: $(NAME)
$(NAME): $(OBJ) $(OBJB) $(OBJA) | $(BIN_DIR)
@$(AR) $(NAME) $^
@$(PRINTF) "\r%100s\r$(GREEN)$(BIN) is up to date!$(DEFAULT)\n"
bonus: $(OBJB) | $(BIN_DIR)
@$(AR) $(NAME) $^
@$(PRINTF) "\r%100s\r$(MAGENTA)Bonus $(BIN) is up to date!$(DEFAULT)\n"
additional: $(OBJA) | $(BIN_DIR)
@$(AR) $(NAME) $^
@$(PRINTF) "\r%100s\r$(YELLOW)Additional $(BIN) is up to date!$(DEFAULT)\n"
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
@$(eval SRC_COUNT = $(shell expr $(SRC_COUNT) + 1))
@$(PRINTF) "\r%100s\r[ %d/%d (%d%%) ] Compiling $(BLUE)$<$(DEFAULT)..." "" $(SRC_COUNT) $(SRC_COUNT_TOT) $(SRC_PCT)
@$(CC) $(CFLAGS) -c $< -o $@
$(OBJB_DIR)/%.o: $(SRCB_DIR)/%.c | $(OBJB_DIR)
@$(eval SRCB_COUNT = $(shell expr $(SRCB_COUNT) + 1))
@$(PRINTF) "\r%100s\r[ %d/%d (%d%%) ] Compiling $(MAGENTA)$<$(DEFAULT)..." "" $(SRCB_COUNT) $(SRCB_COUNT_TOT) $(SRCB_PCT)
@$(CC) $(CFLAGS) -c $< -o $@
$(OBJA_DIR)/%.o: $(SRCA_DIR)/%.c | $(OBJA_DIR)
@$(eval SRCA_COUNT = $(shell expr $(SRCA_COUNT) + 1))
@$(PRINTF) "\r%100s\r[ %d/%d (%d%%) ] Compiling $(YELLOW)$<$(DEFAULT)..." "" $(SRCA_COUNT) $(SRCA_COUNT_TOT) $(SRCA_PCT)
@$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR):
@mkdir -p $(OBJ_DIR)
$(OBJB_DIR):
@mkdir -p $(OBJB_DIR)
$(OBJA_DIR):
@mkdir -p $(OBJA_DIR)
$(BIN_DIR):
@mkdir -p $(BIN_DIR)
clean:
@$(PRINTF) "$(CYAN)Cleaning up object files in libft...$(DEFAULT)\n"
@$(RM) -r $(OBJ_DIR)
@$(RM) -r $(OBJB_DIR)
@$(RM) -r $(OBJA_DIR)
fclean: clean
@$(RM) -r $(BIN_DIR)
@$(PRINTF) "$(CYAN)Removed $(NAME)$(DEFAULT)\n"
create_dirs:
norminette:
@$(PRINTF) "$(CYAN)\nChecking norm for libft...$(DEFAULT)\n"
@norminette -R CheckForbiddenSourceHeader $(SRC_DIR) $(SRCB_DIR) $(SRCA_DIR) inc/libft.h
re: fclean
@make all
git:
git add .
git commit
git push
-include $(OBJ_DIR)/*.d
-include $(OBJB_DIR)/*.d
-include $(OBJA_DIR)/*.d
.PHONY: all bonus additional clean fclean git norminette re