-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
222 lines (197 loc) · 14.2 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: aviholai <aviholai@student.hive.fi> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/01/18 15:29:53 by aviholai #+# #+# #
# Updated: 2025/01/21 by aviholai ### ########.fr #
# #
# **************************************************************************** #
# You may change the TITLE of the project to your liking. It will affect the
# header's (.h) filename and all references to it in SRC files upon
# running $(NAME).
TITLE = libft
NAME = $(TITLE).a
SRC = ft_memset.c\
ft_bzero.c\
ft_memcpy.c\
ft_memccpy.c\
ft_memmove.c\
ft_memchr.c\
ft_memcmp.c\
ft_strlen.c\
ft_strdup.c\
ft_strcpy.c\
ft_strncpy.c\
ft_strcat.c\
ft_strncat.c\
ft_strlcat.c\
ft_strchr.c\
ft_strrchr.c\
ft_strstr.c\
ft_strnstr.c\
ft_strcmp.c\
ft_strncmp.c\
ft_atoi.c\
ft_isalpha.c\
ft_isdigit.c\
ft_isalnum.c\
ft_isascii.c\
ft_isprint.c\
ft_toupper.c\
ft_tolower.c\
ft_memalloc.c\
ft_memdel.c\
ft_strnew.c\
ft_strdel.c\
ft_strclr.c\
ft_striter.c\
ft_striteri.c\
ft_strmap.c\
ft_strmapi.c\
ft_strequ.c\
ft_strnequ.c\
ft_strsub.c\
ft_strjoin.c\
ft_strtrim.c\
ft_strsplit.c\
ft_itoa.c\
ft_putchar.c\
ft_putstr.c\
ft_putendl.c\
ft_putnbr.c\
ft_putchar_fd.c\
ft_putstr_fd.c\
ft_putendl_fd.c\
ft_putnbr_fd.c
OBJ = $(SRC:.c=.o)
# Determine user OS for `sed` call during compile.
SED_CMD = $(shell uname | grep -q Darwin && echo "sed -i .bak" || echo "sed -i.bak")
LISTSRC = $(foreach part,$(SRC), $(PL) ${G}| $(part)$(if $(shell [ $$(echo -n $(part) | wc -c) -gt 13 ] && echo true), , )${PR})
# Running 'make' runs 'all' content: the 'art_header', '$(NAME)' and
# 'art_footer' rules, effectively building the whole archive.
all: $(NAME)
@#Runs `clean` and discards standard output (truly silent.)
@$(MAKE) clean > /dev/null 2>&1
# Run '$(NAME)' to run compile an archive with demanded check-ups and filters.
# Firstly, the rule will intialize a complete rewrite of the header's (.h)
# filename and all references to it in the 'SRC' files by utilizing the
# UNIX 'mv' and 'sed' commands.
# The compiled objects are created with the 'gcc' command's '-c' flag,
# with the source files from the afore listed address 'SRC'.
# Creates the library with the command 'ar', the flag '-r' forcing the
# compilation of the library, replacing existing archive member files if
# there happen to be any. When finished, prints the table of contents with
# the flag '-t'.
$(NAME):
@$(ARTHEAD)
@printf " ${PL} ${O}Confirming NAME. ${PR}"
@sleep 0.2
@printf " ${PL} ${G}| Renaming header file and fixing references ${PR}"
@printf " ${PL} ${G}| in sources. ${PR}"
@sleep 0.8
@-mv *.h $(TITLE).h
@# Determine correct SED command based on user OS. Rename library files.:
@$(SED_CMD) "s/#include \".*/#include \"$(TITLE).h\"/g" $(SRC)
@printf " ${PL} ${PR}"
@printf " ${PL} ${O}Compiling. ${PR}"
@sleep 0.2
@printf " ${PL} ${G}| Creating objects and archives with the ${PR}"
@printf " $(PL) ${G}| following source files: ${PR}"
@sleep 0.8
@printf "$(LISTSRC)"
@cc -Wall -Wextra -Werror -c $(SRC) $(TITLE).h
@sleep 0.2
@printf " ${PL} ${G}| Source files compiled to object files with 'cc'. ${PR}"
@sleep 0.2
@printf " ${PL} ${G}| " ; ar -r $(TITLE).a $(OBJ)
@sleep 0.2
@printf " ${PL} ${PR}"
@printf " ${PL} ${O}Finished archive. ${PR}"
@sleep 0.2
@printf " ${PL} ${G}| Archive $(TITLE).a compiled with 'ar'. ${PR}"
@sleep 0.8
@printf " ${PL} ${PR}"
@$(ARTFOOTER)
# The 'clean' command removes the compiled object files.
# 'rm', the remove command, with flags '-v' (verbose, lists the said files)
# and '-f' (forcefully remove without prompts.)
# The 'fclean' command also removes the compiled program and static libraries.
clean:
@echo "${O}\n Regular clean-up. | Removing objects, backups and temporary files.\n${G}"
@sleep 0.4
@rm -v -f $(OBJ)
@rm -v -f *.bak
@rm -v -f *~
@sleep 0.2
fclean: clean
@echo "${O}\n Full clean-up. | Removing compiles and archives.\n${G}"
@sleep 0.4
@rm -v -f $(TITLE).a
@rm -v -f $(TITLE).h.gch
@sleep 0.2
# The 're' command runs everything from scratch. That is 'fclean' and 'make'.
re: fclean
@echo "${O}\n Re-run. | After a full clean-up, running a recompile.\n${G}"
@sleep 0.4
@$(MAKE)
@sleep 0.2
# Colors and visual effects. Used for more clearer visual representation.
# 'NOC' stand for "no color", 'O' for orange, 'G' for gray,
# 'DG' for dark gray, 'R' for red and 'GN' for green. 'PL' stand for
# "pillar left" and 'PR' for "pillar right".
NOC = \033[0m
O = \033[0;33m
G = \033[0;37m
R = \033[1;31m
GN = \033[1;32m
PL = \033[1;31m▒▒▒▒░░
PR = \033[1;31m ▒▒▒▒\n
# The ASCII art used for enhancing the user experience. Header and footer
# are called upon rule '$(NAME)' start and end.
ARTHEAD = echo "${R}\n" \
"▒▒░░ ░░▒▒\n"\
" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒\n"\
" ▒▒██████████████████████████████████████████████████████████████████████████████████████▓▓██░░\n"\
" ░░▒ aviholai ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ /|,_ _ _ | |\ | _ |-|-| _ _ ▒▒░░\n"\
" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ /-|||_\(/_| | \|(/_|_|_|(/__\ ▒▒░░\n"\
" ░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▒▒▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░\n"\
" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▒▒░░▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒\n"\
" ░░░░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░\n"\
" ▒▒▒▒▒▒ ▓▓▒▒██▓▓░░ ▓▓▒▒▒▒\n"\
" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▒▒▒▒▒▒▒▒▒▒░░░░\n"\
" ▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒▒▒\n"\
" ▒▒▒▒▒▓▓▒▒▓▓▓▓▒▒▒▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▓▓▒▒▒▒▓▓▒▒▒▒▒▒▒\n"\
" ░░ ▒▒▒▒░░ ░░▒▒▒▒ ░░\n"\
" ▒▒▒▒░░ ▒▒▒▒"
ARTFOOTER = echo "${R} ▒▒▒▒░░ ██ ██ ▒▒▒▒\n"\
"${R} ▒▒▒▒░░ ██████████████████████████ ▒▒▒▒\n"\
"${R} ▒▒▒▒░░ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▒▒▒▒\n"\
"${R} ▒▒▒▒░░ ▓▓ ██ ▓▓ ▒▒▒▒\n"\
"${R} ▒▒▒▒░░ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▒▒▒▒\n"\
"${R} ▒▒▒▒░░ ▓▓ ▓▓ ▒▒▒▒\n"\
"${R} ▒▒▒▒░░ ▓▓ ▓▓ ▒▒▒▒\n"\
"${R} ▒▒▒▒░░ ▓▓ ▓▓ ▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▒▒ ${R}▓▓ ▓▓ $(GN)▒▒ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▒▒ ▒▒ ${R}▓▓ ▓▓ $(GN)▒▒▒▒ ▒▒ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▒▒ ▒▒▒▒ ${R}▓▓ ▓▓ $(GN)▒▒▒▒▒▒ ▒▒ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▒▒▒▒ ▒▒▒▒▒▒ ${R}▓▓ ▓▓ $(GN)▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▒▒▓▓▒▒▒▒▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒░░▒▒░░░░░░░░▒▒░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▒▒▓▓▒▒░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▒▒░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒░░░░░░▒▒░░░░░░░░░░▒▒░░░░░░░░▒▒▒▒▒▒ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░▒▒ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒░░░░░░░░░░▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░▒▒ ${R}▒▒▒▒\n"\
"${R} $(GN)░░ ${R}▒▒▒▒░░ $(GN)░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░▒▒░░░░░░░░░░▒▒▒▒▒▒▒▒ ${R}▒▒▒▒\n"\
"${R} $(GN)▒▒▒▒ ${R}▒▒▒▒░░ $(GN)░░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒░░░░░░░░░░░░░░▒▒░░░░░░░░░░░░░░░░░░▒▒▒▒░░▒▒▒▒▒ ${R}▒▒▒▒ $(GN)░░\n"\
"${R} $(GN)▒▒▒▒ ${R}▒▒▒▒░░ $(GN)░▒▒▒▒░░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒ ${R}▒▒▒▒ $(GN)▒▒\n"\
"${R} $(GN)▓▓░░ ${R}▒▒▒▒░░ $(GN)▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒ ${R}▒▒▒▒ $(GN)▓▓\n"\
"${R} $(GN)▓▓ ${R}▒▒▒▒░░ $(GN)▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▓▓▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▒▒▓▓▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒▓▓▓▓ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▒▒▓▓▓▓▓▓▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒▓▓▓▓▓▓▓▓ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ $(GN)▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ${R}▒▒▒▒\n"\
"${R} ▒▒▒▒░░ ▒▒▒▒"
# The '.PHONY' target exists to avoid conflict with files of the same name.
.PHONY: all clean fclean re