-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
147 lines (113 loc) · 5.02 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tchow-so <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/11/10 10:52:33 by tchow-so #+# #+# #
# Updated: 2024/11/10 11:45:13 by tchow-so ### ########.fr #
# #
# **************************************************************************** #
# ============================================================================ #
# NAMES & PATHS #
# ============================================================================ #
NAME = $(NAME_SERVER) $(NAME_CLIENT)
NAME_SERVER = server
NAME_CLIENT = client
BONUS = $(NAME_SERVER_BONUS) $(NAME_CLIENT_BONUS)
NAME_SERVER_BONUS = server_bonus
NAME_CLIENT_BONUS = client_bonus
SRC_SERVER = server.c
SRC_CLIENT = client.c
SRC_UTILS = utils.c
SRC_SERVER_BONUS = server_bonus.c
SRC_CLIENT_BONUS = client_bonus.c client_handler_bonus.c
BUILD_DIR = .build
OBJS_SERVER = $(addprefix $(BUILD_DIR)/, $(notdir $(SRC_SERVER:.c=.o)))
OBJS_CLIENT = $(addprefix $(BUILD_DIR)/, $(notdir $(SRC_CLIENT:.c=.o)))
OBJS_UTILS = $(addprefix $(BUILD_DIR)/, $(notdir $(SRC_UTILS:.c=.o)))
OBJS_SERVER_BONUS = $(addprefix $(BUILD_DIR)/, $(notdir $(SRC_SERVER_BONUS:.c=.o)))
OBJS_CLIENT_BONUS = $(addprefix $(BUILD_DIR)/, $(notdir $(SRC_CLIENT_BONUS:.c=.o)))
LIBFT_DIR = libft
LIBFT_ARC = $(LIBFT_DIR)/libft.a
# ============================================================================ #
# COMPILER, FLAGS & COMMANDS #
# ============================================================================ #
CC = cc
CFLAGS = -Wall -Wextra -Werror
#CFLAGS += -g -fsanitize=address
MAKE = make -C
RM = rm -rf
AR = ar rcs
MKDIR = mkdir -p
# ============================================================================ #
# RULES #
# ============================================================================ #
##@ COMPILATION RULES
all: $(NAME) ## Compile minitalk
$(NAME): $(LIBFT_ARC) $(BUILD_DIR) $(OBJS_SERVER) $(OBJS_CLIENT) $(OBJS_UTILS)
@printf "$(GRN)>> Generated object files$(RES)\n\n"
$(CC) $(CFLAGS) $(OBJS_SERVER) $(OBJS_UTILS) $(LIBFT_ARC) -o $(NAME_SERVER)
@printf "$(GRN)>> Compiled Server$(RES)\n\n"
$(CC) $(CFLAGS) $(OBJS_CLIENT) $(OBJS_UTILS) $(LIBFT_ARC) -o $(NAME_CLIENT)
@printf "$(GRN)>> Compiled Client$(RES)\n\n"
bonus: $(BONUS) ## Compile minitalk with bonus features (required by subject)
$(BONUS): $(LIBFT_ARC) $(BUILD_DIR) $(OBJS_SERVER_BONUS) $(OBJS_CLIENT_BONUS) $(OBJS_UTILS)
@printf "$(GRN)>> Generated object files (bonus version)$(RES)\n\n"
$(CC) $(CFLAGS) $(OBJS_SERVER_BONUS) $(OBJS_UTILS) $(LIBFT_ARC) -o $(NAME_SERVER_BONUS)
@printf "$(GRN)>> Compiled Server (bonus version)$(RES)\n\n"
$(CC) $(CFLAGS) $(OBJS_CLIENT_BONUS) $(OBJS_UTILS) $(LIBFT_ARC) -o $(NAME_CLIENT_BONUS)
@printf "$(GRN)>> Compiled Client (bonus version)$(RES)\n\n"
$(BUILD_DIR):
$(MKDIR) $(BUILD_DIR)
@printf "$(GRN)>> Created .build/ directory for object files$(RES)\n\n"
$(BUILD_DIR)/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(LIBFT_ARC):
$(MAKE) $(LIBFT_DIR)
@printf "$(GRN)>> Created Libft archive$(RES)\n\n"
##@ CLEAN-UP RULES
clean: ## Remove object files
$(RM) $(BUILD_DIR)
$(MAKE) $(LIBFT_DIR) clean
@printf "$(GRN)>> Removed object files$(RES)\n\n"
fclean: clean ## Remove executable files
$(RM) $(NAME) $(BONUS)
@printf "$(GRN)>> Removed executable files$(RES)\n\n"
$(MAKE) $(LIBFT_DIR) fclean
@printf "$(GRN)>> Removed Libft archive$(RES)\n\n"
re: fclean all ## Purge and recompile
##@ HELP
help: ## Display this help info
@awk 'BEGIN { \
FS = ":.*##"; \
printf "\n$(WHI_B)USAGE$(RES)\n\t$(YEL)make$(RES)$(CYA)\t \
<target>$(RES)\n"} \
/^[a-zA-Z_0-9-]+:.*?##/ { \
printf "\t$(CYA_B)%-15s$(RES) %s\n", $$1, $$2 } \
/^##@/ { printf "\n$(WHI_B)%s$(RES)\n", \
substr($$0, 5) } ' Makefile
@printf "\n"
.PHONY: all bonus clean fclean re help
# ============================================================================ #
# UTILS: SHELL FORMATTING #
# ============================================================================ #
# Reset to default
RES = \033[0m
# Regular text colors
RED = \033[0;31m
GRN = \033[0;32m
YEL = \033[0;33m
BLU = \033[0;34m
MAG = \033[0;35m
CYA = \033[0;36m
WHI = \033[0;37m
# Bold text colors
RED_B = \033[1;31m
GRN_B = \033[1;32m
YEL_B = \033[1;33m
BLU_B = \033[1;34m
MAG_B = \033[1;35m
CYA_B = \033[1;36m
WHI_B = \033[1;37m