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

GRAY     = "\e[0;30m"
RED      = "\e[0;31m"
GREEN    = "\e[0;32m"
YELLOW   = "\e[0;33m"
BLUE     = "\e[0;34m"
PURPLE   = "\e[0;35m"
CYAN     = "\e[0;36m"
WHITE    = "\e[0;37m"

B_GRAY   = "\e[1;30m"
B_RED    = "\e[1;31m"
B_GREEN  = "\e[1;32m"
B_YELLOW = "\e[1;33m"
B_BLUE   = "\e[1;34m"
B_PURPLE = "\e[1;35m"
B_CYAN   = "\e[1;36m"
B_WHITE  = "\e[1;37m"

RESET    = "\e[0m"

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#               . name = value \          . += append to a variable   #
#   VARIABLES   .        value            . != set result of command  #
#               . name is case sensitive  . ?= set if not already set #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

NAME		 =	$(SRCS_X:.cpp=.out)

CXX			 =	c++
CXXFLAGS	 =	-Wall -Wextra #-Werror
CXXFLAGS	+=	$(HEADERS_D:%=-I%)
CXXFLAGS	+=	-std=c++98
CXXFLAGS	+=	-g

VPATH		 =	$(SRCS_D)
HEADERS_D	 =	.
SRCS_D		 =	.

SRCS		 =	cgi_utils.cpp
SRCS_X		 =	\
				cgi_cpp.cpp \
				cgi_cpp_bad_headers.cpp \
				cgi_cpp_empty.cpp \
				cgi_cpp_empty_lines.cpp \
				cgi_cpp_len.cpp \
				cgi_cpp_len_big.cpp \
				cgi_cpp_len_small.cpp \
				cgi_cpp_no_body.cpp \
				cgi_cpp_no_headers.cpp \
				cgi_cpp_only_crlf.cpp \
				cgi_cpp_sleep.cpp \
				cgi_cpp_status.cpp \
				cgi_cpp_download.cpp \

OBJS_D		 =	builds
OBJS		 =	$(SRCS:%.cpp=$(OBJS_D)/%.o)
OBJS_X		 =	$(SRCS_X:%.cpp=$(OBJS_D)/%.o)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#             .   target: prerequisites   .   $@ : target             #
#    RULES    .           recipe          .   $< : 1st prerequisite   #
#             .           recipe          .   $^ : all prerequisites  #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

all: $(NAME)

$(OBJS_D)/%.o: %.cpp | $(OBJS_D)
	@echo $(B_GREEN)"compilation :" $@ $(RESET)
	$(CXX) $(CXXFLAGS) -c $< -o $@

$(OBJS_D):
	mkdir $@

$(NAME): $(OBJS) $(OBJS_X)
$(NAME):
	@echo $(B_YELLOW)"linkage :" $@ $(RESET)
	$(CXX) $(OBJS) $(@:%.out=$(OBJS_D)/%.o) -o $@

clean:
	rm -rf $(OBJS_D)

fclean: clean
	rm -f $(NAME)

re: fclean all

.PHONY : all clean fclean re

