
# - - - - - - - - - - - - - - # name =	value \			 | .c in srcs/
#       variables names       # 		value			 | .h in includes/
# - - - - - - - - - - - - - - # ! name is case sensitive | ! use VPATH only for .c

NAME	=	push_swap

CC		=	gcc

VPATH	=	srcs

IDIR	=	./includes

_DEPS	=
DEPS	=	$(_DEPS:%.h=$(IDIR)/%.h)
# used to check if a .h has been modify when execute $NAME rule

LDIR	=	./libft
_LIBS	=	libft.a
LIBS	=	$(_LIBS:lib%.a=%)

SRCS	=	push_swap.c \
			algo.c \
			print.c \
			swap.c \
			stop.c

ODIR	=	./builds
OBJS	=	$(SRCS:%.c=$(ODIR)/%.o)

CFLAGS	=	-I$(IDIR) -g3 -Wall -Wextra -Werror

LFLAGS	=	-L$(LDIR) -l$(LIBS)



# - - - - - - - - - - - - - - #	target:	prerequisites	| $@ : target
#      rules to execute       #			recipe			| $< : 1st prerequisite
# - - - - - - - - - - - - - - #			recipe			| $^ : all prerequisites

all: $(NAME)

$(NAME): $(ODIR) $(OBJS) $(DEPS)
	make -C $(LDIR)
	$(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)

$(ODIR):
	mkdir -p $@

$(ODIR)/%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

clean:
	/bin/rm -f $(OBJS)

fclean: clean
	/bin/rm -rf $(ODIR)
	/bin/rm -f $(NAME)
	/bin/rm -rf a.out a.out.dSYM

re: fclean all

leaks: CFLAGS += -fsanitize=address
leaks: clean $(NAME)

valgrind: clean $(NAME)
	valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)

.PHONY: all clean fclean re gcc

