ajout explications
This commit is contained in:
119
Makefile
119
Makefile
@@ -1,9 +1,11 @@
|
||||
# - - - - - - - - - #
|
||||
# variables names #
|
||||
# - - - - - - - - - #
|
||||
|
||||
# - - - - - - - - -
|
||||
# variables names
|
||||
# - - - - - - - - -
|
||||
# each variable will expand in its value when used
|
||||
|
||||
NAME = libft.a
|
||||
DEP = libft.h
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra -Werror -I. -c
|
||||
SRCS = ft_atoi.c \
|
||||
@@ -75,59 +77,67 @@ SRCS = ft_atoi.c \
|
||||
ft_arraymap.c \
|
||||
ft_putnbrbase.c \
|
||||
ft_strmultisplit.c
|
||||
|
||||
ODIR = ./builds
|
||||
|
||||
# - "addprefix" is a built-in expansion function used by
|
||||
# makefile to perform a transformation on file names, in
|
||||
# this case we want to put all the .o files in a
|
||||
# subdirectory named "build"
|
||||
# - $(SRCS:.c=.o) is a "substitute reference", an
|
||||
# abbreviation for the expansion function "patsubst" :
|
||||
# $(patsubst %.c,%.o,$(SRCS))
|
||||
OBJ = $(addprefix $(ODIR)/, $(SRCS:.c=.o))
|
||||
|
||||
# - - - - - - - - - -
|
||||
# rules to execute
|
||||
# - - - - - - - - - -
|
||||
|
||||
# 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
|
||||
# - - - - - - - - - - - #
|
||||
# rules to execute #
|
||||
# - - - - - - - - - - - #
|
||||
|
||||
# - 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
|
||||
all: $(ODIR) $(NAME)
|
||||
|
||||
# ODIR create the folder where all the .o files will be stored
|
||||
# create the folder where all the .o files will be stored
|
||||
$(ODIR):
|
||||
mkdir -p $(ODIR)
|
||||
|
||||
# NAME will create the library libft.a
|
||||
# first it checks if any OBJ (files.o) have more recent
|
||||
# - 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
|
||||
|
||||
# first it checks if the date of modification of any .o (OBJ)
|
||||
# is more recent thant the one of libft.a (NAME)
|
||||
# and for each of them it will execute
|
||||
# if only one .c has been modified then only one .o will have been too
|
||||
# so NAME will execute only for this one
|
||||
# ranlib doesn't need to be seen so it's precedeed by a "@"
|
||||
$(NAME): $(OBJ)
|
||||
# - $(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
|
||||
$(NAME): $(OBJ) $(DEP)
|
||||
ar -rc $@ $<
|
||||
@ranlib $@
|
||||
|
||||
# - this rule depend of the list of files.c and file.h
|
||||
# - if any of these files are more recent than the file
|
||||
# builds/file.o equivalent then the rule will rebuild
|
||||
# this .o file
|
||||
$(ODIR)/%.o: %.c
|
||||
$(COMPILE.c) -o $@ $<
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
clean:
|
||||
/bin/rm -rf $(ODIR)
|
||||
|
||||
fclean: clean
|
||||
/bin/rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
|
||||
all: $(NAME)
|
||||
$(NAME): $(OBJ)
|
||||
ar rc $(NAME) $(OBJ)
|
||||
@ranlib $(NAME)
|
||||
clean:
|
||||
/bin/rm -f $(OBJ)
|
||||
fclean: clean
|
||||
/bin/rm -f $(NAME)
|
||||
re: fclean all
|
||||
.PHONY: clean fclean all re
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -446,20 +456,9 @@ re: fclean all
|
||||
# makefile basique
|
||||
# - - - - - - - - -
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# ne pas tout recompiler a la moindre modification
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - -
|
||||
# mettre les fichiers .o dans un dossier
|
||||
# - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
# - - - - - - - - - - - -
|
||||
# make un autre makefile
|
||||
# - - - - - - - - - - - -
|
||||
|
||||
# exemple d'un makefilede basic
|
||||
#
|
||||
# # |DECLARATION VARIABLES
|
||||
# # NAME = libtest.h
|
||||
# # CC = gcc
|
||||
# # CFLAGS = -I. -c
|
||||
@@ -476,6 +475,19 @@ re: fclean all
|
||||
# par exemple pour construire des .o a partir de .c
|
||||
# qui sont utilisees par défaut si les variables
|
||||
# sont bien nomee (genre CC ou CFLAGS)
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# ne pas tout recompiler a la moindre modification
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - -
|
||||
# mettre les fichiers .o dans un dossier
|
||||
# - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
# - - - - - - - - - - - -
|
||||
# make un autre makefile
|
||||
# - - - - - - - - - - - -
|
||||
|
||||
#
|
||||
# cependant si on veut mettre les fichiers .o dans un
|
||||
# sous-fichier BUILDS il n'y a pas de built-in pattern
|
||||
@@ -507,3 +519,16 @@ re: fclean all
|
||||
# $< = "la premiere valeur a droite de :"
|
||||
# $^ = "toutes les valeurs a droite de :"
|
||||
#
|
||||
|
||||
|
||||
|
||||
# shape of a rule :
|
||||
#
|
||||
# target: prerequisites
|
||||
# recipe
|
||||
#
|
||||
# before executing its recipes, makefile verify if any of
|
||||
# the prerequisites has been more recently modify than
|
||||
# the target, and if so execute the recipes
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user