From 0c1de75aecb72e3b9355dd6e1fb24da15f5baa8a Mon Sep 17 00:00:00 2001 From: Willem Haffmans Date: Mon, 23 Dec 2024 10:10:43 +0100 Subject: [PATCH] Setup up project --- Makefile | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ inc/philo.h | 34 +++++++++++++++++++++++++++++++ src/main.c | 7 +++++++ 3 files changed, 99 insertions(+) create mode 100644 Makefile create mode 100644 inc/philo.h create mode 100644 src/main.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ed7e1db --- /dev/null +++ b/Makefile @@ -0,0 +1,58 @@ +# **************************************************************************** # +# # +# ::: o_ :::::: ::: # +# Makefile :+: / :+::+: :+: # +# +:+ > +:++:+ +:+ # +# By: whaffman +#+ +:+ +#++#++:++#++ # +# +#+ +#+#+ +#++#+ +#+ \o/ # +# Created: 2024/10/15 11:48:46 by whaffman #+#+# #+#+# #+# #+# | # +# Updated: 2024/11/07 15:28:08 by whaffman ### ### ### ### / \ # +# # +# **************************************************************************** # + +NAME = fdf + +SRC_PATH = src +INC_PATH = inc + +OBJ_PATH = obj + +VPATH = src +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 diff --git a/inc/philo.h b/inc/philo.h new file mode 100644 index 0000000..3d722c7 --- /dev/null +++ b/inc/philo.h @@ -0,0 +1,34 @@ +#ifndef PHILO_H +# define PHILO_H +# include +# include +# include +# include + +typedef struct s_rules +{ + int time_to_die; + int time_to_eat; + int time_to_sleep; + int nb_must_eat; + pthread_mutex_t *print; + pthread_mutex_t *death; + +} t_rules; + +typedef struct s_philo +{ + pthread_t *pid; + pthread_mutex_t *l_fork; + pthread_mutex_t *r_fork; + int last_meal; + t_rules rules; +} t_philo; +// memset, printf, malloc, free, write, +// usleep, gettimeofday, pthread_create, +// pthread_detach, pthread_join, pthread_mutex_init, +// pthread_mutex_destroy, pthread_mutex_lock, +// pthread_mutex_unlock + + +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..f03b93a --- /dev/null +++ b/src/main.c @@ -0,0 +1,7 @@ +#include "philo.h" + +int main(int argc, char *argv[]) +{ + + return(EXIT_SUCCESS); +}