79 lines
1.6 KiB
Makefile
79 lines
1.6 KiB
Makefile
|
|
# have the .c in a "srcs/" directory
|
|
# have the .h in a "includes/" directory
|
|
|
|
# - - - - - - - - - - - - - - #
|
|
# variables names #
|
|
# - - - - - - - - - - - - - - #
|
|
# name = value \
|
|
# value
|
|
# name is case sensitive
|
|
|
|
# VPATH where to look for rules preriquisites not found in "./"
|
|
# best to use only for ".c", not ".o" nor ".h"
|
|
NAME = fdf
|
|
CC = gcc
|
|
VPATH = srcs
|
|
|
|
IDIR = ./includes
|
|
_DEPS = fdf.h
|
|
DEPS = $(_DEPS:%.h=$(IDIR)/%.h)
|
|
|
|
LDIR = ./libft
|
|
_LIBS = libft.a
|
|
LIBS = $(_LIBS:lib%.a=%)
|
|
|
|
SRCS = fdf.c
|
|
|
|
ODIR = ./builds
|
|
OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
|
|
|
# flag -g generates debug informations, g3 is maximal version
|
|
CFLAGS = -I$(IDIR) -g3 -Wall -Wextra -Werror
|
|
LFLAGS = -L$(LDIR) -l$(LIBS)
|
|
CFLAGS += -I./minilibx-linux-master
|
|
LFLAGS += -lm -lmlx -lXext -lX11 -L./minilibx-linux-master
|
|
|
|
# - - - - - - - - - - - - - - #
|
|
# rules to execute #
|
|
# - - - - - - - - - - - - - - #
|
|
# target: prerequisites ...
|
|
# recipe ...
|
|
|
|
|
|
all: $(NAME)
|
|
|
|
# it verify if anything has changed in .c and .h files
|
|
# then it makes LDIR library, then it compiles NAME
|
|
$(NAME): $(ODIR) $(OBJS) $(DEPS)
|
|
make -C $(LDIR)
|
|
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
|
|
|
# create "builds/" if doesn't exist
|
|
$(ODIR):
|
|
mkdir -p $@
|
|
|
|
# if a file.c has been modified, it's recompiled in object file.o
|
|
$(ODIR)/%.o: %.c
|
|
$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
debug: CFLAGS += -fsanitize=address
|
|
debug: clean $(NAME)
|
|
|
|
leaks: clean $(NAME)
|
|
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)
|
|
|
|
clean:
|
|
/bin/rm -f $(OBJS)
|
|
|
|
fclean: clean
|
|
make fclean -C $(LDIR)
|
|
/bin/rm -rf $(ODIR)
|
|
/bin/rm -f $(NAME)
|
|
/bin/rm -rf a.out a.out.dSYM
|
|
|
|
re: fclean all
|
|
|
|
.PHONY: all clean fclean re gcc
|
|
|