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

NAME      = burn

#TYPE      = c
TYPE      = cpp

ifeq "$(TYPE)" "c"
  CC      = c
  EXT     = c
else ifeq "$(TYPE)" "cpp"
  CC      = c++
  EXT     = cpp
endif

CFLAGS    = -Wall -Wextra -Werror $(INCLUDES)
ifeq "$(TYPE)" "cpp"
  CFLAGS += -std=c++98
endif

VPATH     = $(D_SRCS)

LIBS      =

INCLUDES  = -I$(D_HEADERS)

D_SRCS    = .
SRCS      = main.cpp \
			Animal.cpp \
			Dog.cpp \
			Cat.cpp \
			Brain.cpp

D_HEADERS = .
HEADERS   = Animal.hpp \
			Dog.hpp \
			Cat.hpp \
			Brain.hpp

D_OBJS    = builds
OBJS      = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)

ifeq "$(D_OBJS)" "."
  RM_OBJS = rm -f $(OBJS)
else
  RM_OBJS = rm -rf $(D_OBJS)
endif


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

all: $(NAME)

$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS)
	$(CC) $(CFLAGS) -c $< -o $@

$(D_OBJS):
	mkdir $@

$(OBJS): $(HEADERS:%=$(D_HEADERS)/%)

$(NAME): $(OBJS)
	$(CC) $(OBJS) -o $@ $(LIBS)

clean:
	$(RM_OBJS)

fclean: clean
	rm -f $(NAME)

re: fclean all

.PHONY : all clean fclean re

