NAME = so_long

SRC_DIR = src
SRC = $(addprefix $(SRC_DIR)/, *.c)
SRC_DIR2 = src/BFS_ALGORITHM
SRC2 = $(addprefix $(SRC_DIR2)/, *.c)

OBJ_DIR = obj
OBJ = $(addprefix $(OBJ_DIR)/, *.o)

CC = cc
FLAGS = -Wall -Werror -Wextra -g3
INCLUDE = -I/usr/include -Imlx_linux -O3 -c $<
LINK = -Lminilibx-linux -lmlx_Linux -L/usr/lib -Imlx_linux -lXext -lX11 -lm -lz

LIBFT_DIR = libft
LIBFT_LIB = libft.a
LIBFT = $(addprefix $(LIBFT_DIR)/, $(LIBFT_LIB))

GNL_DIR = get_next_line
GNL_LIB = get_next_line.a
GNL = $(addprefix $(GNL_DIR)/, $(GNL_LIB))

FT_PRINTF_DIR = ft_printf
FT_PRINTF_LIB = libftprintf.a 
FT_PRINTF = $(addprefix $(FT_PRINTF_DIR)/, $(FT_PRINTF_LIB))

MLX_DIR = minilibx-linux
MLX_LIB = libmlx_Linux.a
MLX = $(addprefix $(MLX_DIR)/, $(MLX_LIB))


$(NAME) : $(OBJ) $(MLX) $(LIBFT) $(GNL) $(PRINTF) 
	@make -C $(LIBFT_DIR)
	@make -C $(GNL_DIR)
	@make -C $(FT_PRINTF_DIR)
	@make -C $(MLX_DIR)
	$(CC) $(OBJ) $(LINK) $(LIBFT) $(GNL) $(FT_PRINTF) $(MLX) -o $@

$(OBJ): $(SRC) $(SRC2) $(OBJ_DIR) 
	$(CC) $(FLAGS) $(INCLUDE) $(SRC) $(SRC2)
	@mv *.o $(OBJ_DIR)

$(OBJ_DIR):
	@mkdir -p $(OBJ_DIR)

all : $(NAME)

clean :
	@rm obj/*

fclean : clean
	@rm $(NAME)

re : fclean all 

run : 
	./so_long carte/carte_de_test.ber

git :
	git add .
	git commit -m "AUTO_GIT_MAKE"
	git push

lldb  :
	@lldb so_long carte/carte_de_test.ber
valg :
	@valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./so_long carte/carte_de_test.ber

.PHONY: all fclean clean re run git lldb valg
