# **************************************************************************** #
#                                                                              #
#                                                         :::      ::::::::    #
#    Makefile                                           :+:      :+:    :+:    #
#                                                     +:+ +:+         +:+      #
#    By: gtertysh <marvin@42.fr>                    +#+  +:+       +#+         #
#                                                 +#+#+#+#+#+   +#+            #
#    Created: 2016/12/14 16:54:48 by gtertysh          #+#    #+#              #
#    Updated: 2016/12/23 19:59:53 by gtertysh         ###   ########.fr        #
#                                                                              #
# **************************************************************************** #

# clor constants

SWITCH =			\033[

NORMAL =			$(SWITCH)0m
GREEN =				$(SWITCH)32m
BLUE =				$(SWITCH)34m
CYAN =				$(SWITCH)36m

# final binary name

NAME = 				fdf

# static libraries

LIBFT =				libft.a
MLX =				libmlx.a

# directories

SRC_DIR =			./src/
OBJ_DIR =			./obj/
LIBFT_DIR =			./libft/
MLX_DIR =			./minilibx/

# src and obj files

SRC_FILES =			$(shell ls $(SRC_DIR))
OBJ_FILES =			$(SRC_FILES:.c=.o)

SRC =				$(addprefix $(SRC_DIR), $(SRC_FILES))
OBJ =				$(addprefix $(OBJ_DIR), $(OBJ_FILES))

# header files

INC =				-I $(LIBFT_DIR)includes/ \
					-I $(MLX_DIR) \
					-I ./inc 

# compiler flags

LIBFT_FLAGS =		-lft -L $(LIBFT_DIR)
MLX_FLAGS =			-lmlx -lXext -lX11 -L $(MLX_DIR)
OTHER_FLAGS =		-lm
CC_FLAGS =			-Werror -Wextra -Wall -O3
FLAGS :=			$(CC_FLAGS) $(LIBFT_FLAGS) $(MLX_FLAGS) $(OTHER_FLAGS)

# compiler

CC =				gcc

# rules

all: $(NAME)

$(NAME): $(OBJ) $(LIBFT_DIR)$(LIBFT) $(MLX_DIR)$(MLX)
	@echo "$(CYAN)Linking fdf binary...$(NORMAL)"
	@$(CC) $(OBJ) $(FLAGS) -o $(NAME)
	@echo "$(GREEN)Done!$(NORMAL)"

$(OBJ_DIR)%.o : $(SRC_DIR)%.c 
	@echo "$(CYAN)Compiling object files: $(BLUE)$@$(NORMAL)"
	@$(CC) $(CC_FLAGS) $(INC) -c $< -o $@  

$(LIBFT_DIR)$(LIBFT):
	@echo "$(CYAN)Compiling libft library...$(NORMAL)"
	@make -s -C $(LIBFT_DIR)

$(MLX_DIR)$(MLX):
	@echo "$(CYAN)Compiling libmlx library...$(NORMAL)"
	@make -s -C $(MLX_DIR)
	
clean:
	@rm -rf $(OBJ)

fclean: clean
	@rm -rf $(NAME)

libclean:
	@make clean -s -C $(LIBFT_DIR)
	@make clean -s -C $(MLX_DIR)

libfclean:
	@make fclean -s -C $(LIBFT_DIR)

re: fclean libfclean all

pu: fclean libfclean libclean
	@echo "$(CYAN)Cleaning for push...$(NORMAL)"

