# **************************************************************************** #
#                                                                              #
#                                                   :::  o_   ::::::    :::    #
#    Makefile                                      :+:  /    :+::+:    :+:     #
#                                                 +:+   >   +:++:+    +:+      #
#    By: whaffman <whaffman@student.codam.nl>    +#+  +:+  +#++#++:++#++       #
#                                               +#+ +#+#+ +#++#+    +#+ \o/    #
#    Created: 2024/10/15 11:48:46 by whaffman   #+#+# #+#+# #+#    #+#   |     #
#    Updated: 2024/11/07 15:28:08 by whaffman   ###   ###  ###    ###   / \    #
#                                                                              #
# **************************************************************************** #

NAME = philo

SRC_PATH = src
INC_PATH = inc

OBJ_PATH = obj

VPATH = src:src/utils
SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c"))

OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o))
DEPENDS = ${OBJECTS:.o=.d}

CC = cc
RM = rm -rf

INCLUDES = -I./$(INC_PATH)
CFLAGS = -Wall -Wextra -Werror -MMD

UNAME_S	:= $(shell uname -s)
ifeq ($(UNAME_S),Linux)
	LDLIBS	:= -pthread
endif

all: $(NAME)

$(NAME): $(OBJECTS)
	$(CC) $(CFLAGS) $(OBJECTS) $(LDLIBS) -o $(NAME)

-include ${DEPENDS}

$(OBJ_PATH):
	mkdir -p $@

$(OBJ_PATH)/%.o: %.c | $(OBJ_PATH)
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

clean:
	$(RM) $(OBJECTS) $(OBJ_PATH)

fclean: clean
	$(RM) $(NAME)

re: fclean all

.PHONY: all clean fclean re
