makefile organise

This commit is contained in:
Hugo LAMY
2019-11-19 21:13:55 +01:00
parent 966241a6df
commit 32356ba7a0
85 changed files with 2052 additions and 116 deletions

139
Makefile
View File

@@ -2,26 +2,22 @@
# variables names #
# - - - - - - - - - #
NAME = libft.a
CC = gcc
VPATH = srcs
NAME = libft.a
CC = gcc
VPATH = srcs/part1/ \
srcs/part2/ \
srcs/bonus/ \
srcs/add/
IDIR = includes
_DEP = libft.h
DEPS = $(_DEP:%.h=$(IDIR)/%.h)
# - $(_DEP:%.h=$(IDIR)/%.h) is a built-in function called
# a "substitute reference", an abbreviation for the
# expansion function "patsubst" :
# $(patsubst %.h,$(IDIR)/%.h,$(_DEP))
# $(patsubst pattern,replacement,text)
# - % match everything, the value of the first % in
# "replacement" is replaced by the text matched by the
# first % in "pattern", it only works for the firsts
IDIR = includes
_DEP = libft.h \
libonnus.h
DEPS = $(_DEP:%.h=$(IDIR)/%.h)
CFLAGS = -I$(IDIR)
CFLAGS += -Wall -Wextra -Werror
CFLAGS = -I$(IDIR)
CFLAGS += -Wall -Wextra -Werror
SRCS = ft_memset.c \
SRCS = ft_memset.c \
ft_bzero.c \
ft_memcpy.c \
ft_memmove.c \
@@ -47,38 +43,35 @@ SRCS = ft_memset.c \
\
ft_substr.c \
ft_strjoin.c \
ft_strtrim.c \ #fonction un peu changee
ft_strsplit.c \ #ft_split.c
ft_strtrim.c \
ft_split.c \
ft_itoa.c \
ft_strmapi.c \
ft_putchar_fd.c \
ft_putstr_fd.c \ #change const
ft_putendl_fd.c \ #change const
ft_putstr_fd.c \
ft_putendl_fd.c \
ft_putnbr_fd.c \
\
ft_lstnew.c \ #fonction un peu changee
ODIR = ./builds
OBJS = $(SRCS:%.c=$(ODIR)/%.o)
SRCB = ft_lstnew.c \ #fonction un peu changee
ft_lstadd.c \ #ft_lstadd_front.c
lstsize \ #a creer
lstlast \ #a creer
lstadd_back \ #a creer
eart_lstdelone.c \ #fonction un peu changee
ft_lstdelone.c \ #fonction un peu changee
ft_lstdel.c \ #lstclear et un peu changee
ft_lstiter.c \ #fonction un peu changee
ft_lstmap.c \ #fonction un peu changee
\
ft_memccpy.c \
ft_strcat.c \
ft_strcmp.c \
ft_strcpy.c \
ft_strncat.c \
ft_strncpy.c \
ft_strstr.c \
ft_memalloc.c \
ft_memdel.c \
ft_putchar.c \
ft_putendl.c \
ft_putnbr.c \
ft_putstr.c \
ft_strjoinfree.c \
ft_strclr.c \
ft_strdel.c \
ft_strequ.c \
@@ -87,16 +80,25 @@ SRCS = ft_memset.c \
ft_strmap.c \
ft_strnequ.c \
ft_strnew.c \
ft_memalloc.c \
ft_memccpy.c \
ft_memdel.c \
ft_putchar.c \
ft_putendl.c \
ft_putnbr.c \
ft_putnbrendl.c \
ft_putnbrendl_fd.c \
ft_putnbrbase.c \
ft_putstr.c \
ft_any.c \
ft_atoibase.c \
ft_convertbase.c \
ft_foreach.c \
ft_issort.c \
ft_arraymap.c \
ft_putnbrbase.c \
ft_strmultisplit.c
ODIR = ./builds
OBJ = $(SRCS:%.c=$(ODIR)/%.o)
OBJB = $(SRCB:%.c=$(ODIR)/%.o)
# - - - - - - - - - - - #
@@ -105,91 +107,30 @@ OBJ = $(SRCS:%.c=$(ODIR)/%.o)
all: $(ODIR) $(NAME)
# - when you write "make" in command line it will execute
# the first rule wrote in the Makefile, wich is "all" by
# convention because usually when you type "make" you
# expect it to build all
# - it first verify if ODIR is created and if not create
# it, then it calls NAME to create the library
$(ODIR):
mkdir -p $(ODIR)
# create the folder where all the .o files will be stored
$(NAME): $(OBJS) $(DEPS)
ar -rc $@ $(OBJS)
@ranlib $@
# - NAME will create the library libft.a
# - first it checks if any OBJ (files.o) have more recent
# date of modification than NAME (libft.a), and for each
# it will execute
# - $(OBJ) will expand in the list of files.o and each of
# them will call the rule "$(ODIR)/%.o:" below because it
# has its exact pattern
# - NAME will execute only for the .c that has been
# modified since last creation of NAME
# - ranlib is precedeed by a "@" to avoid being print
# - if DEP (libft.h) is modified the library is remade
# - $@ means name of the rule
# - $< means first argument right to ":"
bonnus: $(OBJB)
ar rc $(NAME) $(OBJB)
@ranlib $(NAME)
$(ODIR)/%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
# - this rule depend of the list of files.c
# - if any of these files are more recent than the file
# builds/file.o equivalent then the rule will rebuild
# this .o file
# - the flag -o is there to put explicit name of the .o
# files since they must be written within a directory
# path (builds/)
clean:
/bin/rm -rf $(ODIR)
# clean the objects file
# rm is use with its native path to avoid using an alias
fclean: clean
/bin/rm -f $(NAME)
# clean the objects and executable files
re: fclean all
# remake the compilation
.PHONY: clean fclean re all
# all rules that are not names of a file are declared to
# be phony so that makefile knows he has to execute them
# even if a file name similarly exist and would prevent
# the rule to execute because it has not been changed
.PHONY: bonnus clean fclean re all