# - - - - - - - - - - - - - - #		name =	value \
#       variables names       #				value
# - - - - - - - - - - - - - - #		! name is case sensitive

NAME	=	libftest
	
CC		=	gcc

VPATH	=	srcs

DEPS	=	../includes/libft.h \
			./includes/libftest.h
IDIR	=	$(dir $(DEPS))
# $(dir PATH/TO/FILE) expands to "PATH/TO/" -> the directory of a file

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

SRCS	=	main.c \
			test_memset.c \
			test_bzero.c \
			test_memcpy.c \
			test_memccpy.c \
			test_memmove.c \
			test_memchr.c \
			test_memcmp.c \
			test_strlen.c \
			test_isalpha.c \
			test_isdigit.c \
			test_isalnum.c \
			test_isascii.c \
			test_isprint.c \
			test_toupper.c \
			test_tolower.c \
			test_strchr.c \
			test_strrchr.c \
			test_strchrset.c \
			test_strncmp.c \
			test_strlcpy.c \
			test_strlcat.c \
			test_strnstr.c \
			test_atoi.c \
			test_calloc.c \
			test_strdup.c \
			test_substr.c \
			test_strjoin.c \
			test_strtrim.c \
			test_split.c \
			test_itoa.c \
			test_utoa.c \
			test_strmapi.c \
			test_putchar_fd.c \
			test_putstr_fd.c \
			test_putendl_fd.c \
			test_putnbr_fd.c \
			test_lstnew.c \
			test_lstadd_front.c \
			test_lstsize.c \
			test_lstlast.c \
			test_lstadd_back.c \
			test_lstdelone.c \
			test_lstclear.c \
			test_lstiter.c \
			test_lstmap.c \
			test_strcat.c \
			test_strcmp.c \
			test_strcpy.c \
			test_strncat.c \
			test_strncpy.c \
			test_strstr.c \
			test_strjoinfree.c \
			test_strclr.c \
			test_strdel.c \
			test_strequ.c \
			test_striter.c \
			test_striteri.c \
			test_strmap.c \
			test_strnequ.c \
			test_strnew.c \
			test_memalloc.c \
			test_memdel.c \
			test_putchar.c \
			test_putendl.c \
			test_putnbr.c \
			test_putnbrendl.c \
			test_putnbrendl_fd.c \
			test_putnbrbase.c \
			test_putstr.c \
			test_any.c \
			test_atoibase.c \
			test_convertbase.c \
			test_convertbase_free.c \
			test_foreach.c \
			test_issort.c \
			test_arraymap.c \
			test_strmultisplit.c \
			test_gnl.c \
			test_concat_free.c \
			test_printf.c \
			test_abs.c \
			test_greater.c \
			test_smaller.c \
			test_sign.c \
			test_sqrt.c

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

CFLAGS	=	$(IDIR:%=-I%)
# flag -g generates debug informations, g3 is maximal version
CFLAGS	+=	-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 $@ $<

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

leaks: $(NAME)
	valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) maps/42_color.fdf

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

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

libfclean:
	make fclean -C $(LDIR)

re: fclean all

relib: libfclean re

.PHONY: all clean fclean re gcc

