# **************************************************************************** #
#                                                                              #
#                                                         :::      ::::::::    #
#    Makefile                                           :+:      :+:    :+:    #
#                                                     +:+ +:+         +:+      #
#    By: gbrochar <gbrochar@student.42.fr>          +#+  +:+       +#+         #
#                                                 +#+#+#+#+#+   +#+            #
#    Created: 2020/12/17 19:47:03 by gbrochar          #+#    #+#              #
#    Updated: 2024/04/25 16:18:14 by gbrochar         ###   ########.fr        #
#                                                                              #
# **************************************************************************** #

NAME =		scop

SRC_FILE =	main.c \
			parse_file.c \
			parse_line.c \
			parse_token.c \
			center_vertices.c \
			env.c \
			run.c \
			mat4_transpose.c \
			mat4_multiply.c \
			mat4_perspective.c \
			mat4_lookat.c \
			mat4_identity.c \
			mat4_inverse.c \
			mat4_rotate.c \
			mat4_translate.c \
			mat4_scale.c \

OBJ_FILE =	$(SRC_FILE:.c=.o)

INC_FILE =	scop.h \

SRC_DIR =	src/
OBJ_DIR =	obj/
INC_DIR =	inc/

SRC =		$(addprefix $(SRC_DIR), $(SRC_FILE))
OBJ =		$(addprefix $(OBJ_DIR), $(OBJ_FILE))
INC =		$(addprefix $(INC_DIR), $(INC_FILE))

LIB =		-lm -lGL -lglfw glew-2.2.0/lib/libGLEW.a

CC =		gcc

CFLAGS =	-Wall -Werror -Wextra

RED = \033[31m
GREEN = \033[32m
YELLOW = \033[33m
BLUE = \033[34m
CYAN = \033[36m
WHITE = \033[0m

all: $(NAME)

$(NAME): $(OBJ) $(INC)
	@make -C glew-2.2.0
	@$(CC) $(CFLAGS) -c $(SRC) -I $(INC_DIR) -I glew-2.2.0/include/
	@mv $(OBJ_FILE) $(OBJ_DIR)
	@$(CC) $(CFLAGS) $(OBJ) -o $(NAME) $(LIB)
	@echo -e "$(GREEN)[OK]$(WHITE) $(NAME)"

$(OBJ_DIR)%.o: $(SRC_DIR)%.c inc/
	@if [ ! -d ./obj ]; then \
		mkdir -p ./obj; \
	fi;
	@$(CC) $(CFLAGS) -I $(INC_DIR) -I glew-2.2.0/include/ -o $@ -c $<
	@echo -e "$(CYAN)[CC]$(WHITE) $<"

clean:
	@rm -rf $(OBJ_DIR)
	@echo -e "$(RED)[REMOVED]$(WHITE) obj files"

fclean: clean
	make -C glew-2.2.0 clean
	@rm -f $(NAME)
	@echo -e "$(RED)[REMOVED]$(WHITE) $(NAME)"

re: fclean all

.PHONY: all clean fclean re
