This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
159 lines (129 loc) · 4.42 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
################################################################################
## Compilation environnement ##
################################################################################
NAME = ircserv
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98 -g3 -ggdb -fsanitize=address
################################################################################
## SRCS ##
################################################################################
MK = Makefile
# Headers
DIR_HDS = includes
RELATIVE_HDS = includes.hpp \
runtime.hpp \
Server.hpp \
define.hpp \
commands.hpp \
channel/ChannelMode.hpp \
channel/Channel.hpp \
mode/utils.hpp \
user/UserMode.hpp \
user/User.hpp \
log/log.hpp \
bot/bot.hpp \
Parsing.hpp \
reply.hpp \
utils/string.hpp \
utils/compare.hpp
# Code
DIR_GLOBAL = srcs
SRC_GLOBAL = main.cpp \
Parsing.cpp \
Server.cpp
DIR_USER = $(DIR_GLOBAL)/user
SRC_USER = UserMode.cpp User.cpp
DIR_BOT = $(DIR_GLOBAL)/bot
SRC_BOT = bot.cpp
DIR_LOG = $(DIR_GLOBAL)/log
SRC_LOG = log.cpp
DIR_CHANNEL = $(DIR_GLOBAL)/channel
SRC_CHANNEL = ChannelMode.cpp Channel.cpp
DIR_MOD = $(DIR_GLOBAL)/mode
SRC_MOD = utils.cpp
DIR_UTILS = $(DIR_GLOBAL)/utils
SRC_UTILS = string.cpp compare.cpp
DIR_COMMANDS = $(DIR_GLOBAL)/commands
SRC_COMMANDS = initCmd.cpp \
PASS.cpp \
NICK.cpp \
INFO.cpp \
USER.cpp \
PRIVMSG.cpp \
HELP.cpp \
VERSION.cpp \
CAP.cpp \
KICK.cpp \
PART.cpp \
LUSERS.cpp \
TIME.cpp \
QUIT.cpp \
PING.cpp \
PONG.cpp \
TOPIC.cpp \
NAMES.cpp \
MODE.cpp \
NOTICE.cpp \
KILL.cpp \
OPER.cpp \
INVITE.cpp \
JOIN.cpp
################################################################################
## Binaries Architecture ##
################################################################################
# All dirs
DIRS_SRC = ${DIR_BOT} $(DIR_MOD) $(DIR_COMMANDS) $(DIR_UTILS) $(DIR_USER) \
$(DIR_LOG) $(DIR_CHANNEL) $(DIR_GLOBAL)
# Directory of all binaries (objects)
DIR_OBJ = obj
# All srcs
SRCS = $(addprefix $(DIR_GLOBAL)/, $(SRC_GLOBAL)) \
$(addprefix $(DIR_USER)/, $(SRC_USER)) \
$(addprefix $(DIR_BOT)/, $(SRC_BOT)) \
$(addprefix $(DIR_MOD)/, $(SRC_MOD)) \
$(addprefix $(DIR_UTILS)/, $(SRC_UTILS)) \
$(addprefix $(DIR_LOG)/, $(SRC_LOG)) \
$(addprefix $(DIR_COMMANDS)/, $(SRC_COMMANDS)) \
$(addprefix $(DIR_CHANNEL)/, $(SRC_CHANNEL))
# All hpp
HDS = $(addprefix $(DIR_HDS)/, $(RELATIVE_HDS))
# All objs location
OBJS = $(addprefix $(DIR_OBJ)/, $(SRCS:.cpp=.o))
# Global dependencies
DEPENDS = $(HDS) $(MK)
################################################################################
## Presentation ##
################################################################################
COLOR_NORM = \033[0m
COLOR_RED = \033[31m
COLOR_PURPLE = \033[35m
################################################################################
## Rules ##
################################################################################
# Default rule
all : $(NAME)
# Rule function to create .o with .cpp
# @param $(1) the directory of the source
# @param $(2) the dependence of the source
define src2obj
$(DIR_OBJ)/$(1)/%.o: $(1)/%.cpp $(2)
@mkdir -p $(DIR_OBJ)/$(1)
@printf "\r\033[K\tCompilation of $(COLOR_PURPLE)$$< ==> $$@\$(COLOR_NORM)"
@$(CC) $(CFLAGS) -c -o $$@ $$< $(INC_INC)
endef
# Construct all rules for each directory .cpp => .o
$(foreach dir,$(DIRS_SRC),$(eval $(call src2obj,$(dir), $(DEPENDS))))
# NAME rule to construct the executable
$(NAME) : $(DEPENDS) $(OBJS)
@printf "\n\tCompilation of $(COLOR_PURPLE)$(NAME)\$(COLOR_NORM)\n"
@$(CC) $(CFLAGS) -o $(NAME) $(OBJS)
# Remove all objects (.o)
clean:
@printf "\tDelete $(COLOR_RED)$(DIR_OBJ)/$(COLOR_NORM) of $(NAME)\n"
@rm -rf $(DIR_OBJ)
# Remove all objects (.o) and the executable
fclean: clean
@printf "\tDelete $(COLOR_RED)$(NAME)$(COLOR_NORM)\n"
@rm -rf $(NAME)
# Delete all binaries and recompile
re: fclean all