
NAME		 =	webserv
CXX			 =	c++

CXXFLAGS	 =	-Wall -Wextra #-Werror
CXXFLAGS	+=	$(HEADERS_D:%=-I%)
CXXFLAGS	+=	-std=c++98
CXXFLAGS	+=	-g
#CXXFLAGS	+=	-fno-limit-debug-info
CXXFLAGS	+=	-MMD -MP #header dependencie
#CXXFLAGS	+=	-O3

VPATH		 =	$(SRCS_D)

HEADERS_D	 =	srcs \
				srcs/webserv \
				srcs/config

SRCS_D		 =	srcs \
				srcs/webserv \
				srcs/config \

SRCS		 =	main.cpp \
				base.cpp init.cpp close.cpp epoll_update.cpp signal.cpp \
				accept.cpp request.cpp response.cpp \
				method_get.cpp method_post.cpp method_delete.cpp \
				run_loop.cpp timeout.cpp \
				parser.cpp \
				extraConfig.cpp \
				postProcessing.cpp \
				utils.cpp \
				cgi.cpp \
				Client.cpp Client_multipart_body.cpp \

OBJS_D		 =	builds
OBJS		 =	$(SRCS:%.cpp=$(OBJS_D)/%.o)
DEPS		 =	$(OBJS:.o=.d) #header dependencie

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#             .  target: prerequisites    .   $@ : target             #
#    RULES    .          recipe           .   $< : 1st prerequisite   #
#             .          @recipe (silent) .   $^ : all prerequisites  #
#             .  target: VAR = assignment .   |  : order-only prereq. #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

all: $(NAME)

$(OBJS_D)/%.o: %.cpp | $(OBJS_D)
	$(CXX) $(CXXFLAGS) -c $< -o $@
	printf "$(_CYAN)\r\33[2K\rCompling $@$(_END)"

$(OBJS_D):
	mkdir $@

$(NAME): $(OBJS)
	$(CXX) $^ -o $(NAME)
	echo "$(_GREEN)\r\33[2K\r$(NAME) created 😎$(_END)"

# CGI
cgi:
	make -C srcs/cgi-bin
cgiclean:
	make clean -C srcs/cgi-bin
cgifclean:
	make fclean -C srcs/cgi-bin
cgire:
	make re -C srcs/cgi-bin

clean:
	rm -rf $(OBJS_D)
	echo "$(_RED).o Files Deleted  😱$(_END)"

fclean: clean
	rm -f $(NAME)
	echo "$(_RED)$(NAME) Deleted  😱$(_END)"

re: fclean all

.PHONY : all clean fclean re

-include $(DEPS) # header dependencie

.SILENT:

# ------------------
# ----- COLORS -----
# ------------------

_GREY=$ \033[30m
_RED=$ \033[31m
_GREEN=$ \033[32m
_YELLOW=$ \033[33m
_BLUE=$ \033[34m
_PURPLE=$ \033[35m
_CYAN=$ \033[36m
_WHITE=$ \033[37m
_END=$ \033[0m






