
NAME		 =	webserv
CXX			 =	c++

CXXFLAGS	 =	-Wall -Wextra #-Werror
CXXFLAGS	+=	$(HEADERS_D:%=-I%)
CXXFLAGS	+=	-std=c++98
CXXFLAGS	+=	-g
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 \
				run_loop.cpp \
				ConfigParser.cpp \
				ConfigParserUtils.cpp \
				ConfigParserPost.cpp \
				utils.cpp \
				cgi_script.cpp \
				Client.cpp \

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

# --------------------
# ------ RULES -------
# --------------------

all: $(NAME)

$(OBJS_D)/%.o: %.cpp | $(OBJS_D)
	$(CXX) $(CXXFLAGS) -c $< -o $@

$(OBJS_D):
	mkdir $@

$(NAME): $(OBJS)
	$(CXX) $^ -o $(NAME)

clean:
	rm -rf $(OBJS_D)

fclean: clean
	rm -f $(NAME)

re: fclean all

.PHONY : all clean fclean re

-include $(DEPS) # header dependencie

