explicaiton des makefiles presque fini
This commit is contained in:
324
Makefile
324
Makefile
@@ -80,15 +80,14 @@ SRCS = ft_atoi.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))
|
||||
|
||||
# - $(SRCS:%.c=$(ODIR)/%.o) is a built-in function called a
|
||||
# "substitute reference", an abbreviation for the
|
||||
# expansion function "patsubst" :
|
||||
# $(patsubst %.c,$(ODIR)/%.o,$(SRCS))
|
||||
# - % match everything, the value of the first % in
|
||||
# "replacement" is replaced by the text matched by the
|
||||
# first one in "pattern", it only works for the firsts
|
||||
OBJ = $(SRCS:%.c=$(ODIR)/%.o)
|
||||
|
||||
# - - - - - - - - - - - #
|
||||
# rules to execute #
|
||||
@@ -468,76 +467,307 @@ re: fclean all
|
||||
# makefile basique
|
||||
# - - - - - - - - -
|
||||
|
||||
# exemple d'un makefilede basic qui sert a creer un
|
||||
# executable pour un programme :
|
||||
# exemple for a basic makefile :
|
||||
#
|
||||
# [archtecture]
|
||||
# [architecture]
|
||||
# # main.c
|
||||
# # function01.c
|
||||
# # function02.c
|
||||
# # header.h
|
||||
# # libtest.a
|
||||
# # Makefile
|
||||
#
|
||||
# [Makefile]
|
||||
# # # DECLARATION VARIABLES
|
||||
# #
|
||||
# # NAME = bin_output
|
||||
# # #-------------#
|
||||
# # # VARIABLES #
|
||||
# # #-------------#
|
||||
# # NAME = program_test
|
||||
# # CC = gcc
|
||||
# # CFLAGS = -I. -c
|
||||
# # CFLAGS = -I.
|
||||
# # LFLAGS = -L. -ltest
|
||||
# # DEPS = header.h
|
||||
# # SRCS = main.c \
|
||||
# # function01.c \
|
||||
# # function02.c
|
||||
# # ODIR = ./builds
|
||||
# # OBJS = $(addprefix $(ODIR)/, $(SRCS:.c=.o))
|
||||
# # OBJS = $(SRCS:%.c=%.o)
|
||||
# #
|
||||
# #
|
||||
# # # RULES TO EXECUTE
|
||||
# #
|
||||
# # #---------#
|
||||
# # # RULES #
|
||||
# # #---------#
|
||||
# # all: $(ODIR) $(NAME)
|
||||
# # $(NAME): $(OBJ)
|
||||
# # ar -rc $@ $<
|
||||
# # #clean:
|
||||
# # $(NAME): $(OBJS) $(DEPS)
|
||||
# # $(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||
# # %.o: %.c
|
||||
# # $(CC) $(CFLAGS) -c -o $@ $<
|
||||
# # clean:
|
||||
# # /bin/rm -rf $(ODIR)
|
||||
# # fclean: clean
|
||||
# # /bin/rm -f $(NAME)
|
||||
# # re: fclean all
|
||||
# # .PHONY: all clean fclean re
|
||||
#
|
||||
# apres avoir ecrit "make" dans le terminal le Makefile
|
||||
# va s'executer et l'architecture du fichier racine sera
|
||||
# un peu changee :
|
||||
# # prompt "make" execute the first rule ("all")
|
||||
#
|
||||
# [archtecture]
|
||||
# # main.c
|
||||
# # main.o
|
||||
# # function01.c
|
||||
# # function01.o
|
||||
# # function01.o ++
|
||||
# # function02.c
|
||||
# # function02.o
|
||||
# # function02.o ++
|
||||
# # header.h
|
||||
# # libtest.a
|
||||
# # Makefile
|
||||
# # bin_output
|
||||
# # program_test ++
|
||||
#
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# # - "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))
|
||||
#
|
||||
# # - 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)
|
||||
#
|
||||
# shape of a rule :
|
||||
#
|
||||
# target: prerequisites ...
|
||||
# recipe ...
|
||||
#
|
||||
# when a target is called, its execution depends of the
|
||||
# prerequisites, if they have been more recently modify
|
||||
# than the target the makefile execute the recipe
|
||||
#
|
||||
# to execute a rull you have to call it's name with make :
|
||||
# "make rule", and by default the first rule is execute
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# "automatic variables"
|
||||
#
|
||||
# $@ is the name of the target that called the rule
|
||||
# $< is the name of the first prerequisite
|
||||
# $^ is the name of all the prerequisites
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# $(SRCS:%.c=%.o)
|
||||
#
|
||||
# is a built-in function called a "substitute reference",
|
||||
# an abbreviation for the expansion function "patsubst" :
|
||||
#
|
||||
# $(patsubst pattern,replacement,text)
|
||||
# $(text:pattern=replacement)
|
||||
#
|
||||
# $() is a variable which expand in its value
|
||||
#
|
||||
# % match everything, the value of the first % in
|
||||
# "replacement" is replaced with the text matched by the
|
||||
# first % in "pattern", it only works for the firsts
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# all: $(ODIR) $(NAME)
|
||||
#
|
||||
# ALL depends on ODIR and NAME, so if ODIR doesn't exist
|
||||
# it will be created, and then NAME is called
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# $(NAME): $(OBJS) $(DEPS)
|
||||
# $(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||
#
|
||||
# NAME depends on OBJS and DEPS, so if any .o or any .h
|
||||
# have more recent date of modification NAME will execute
|
||||
# only for them
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# %.o: %.c
|
||||
# $(CC) $(CFLAGS) -c -o $@ $<
|
||||
#
|
||||
# when $(OBJS) expand in the list of .o files at the call
|
||||
# of the NAME rule, each of them call the rule "%.o" wich
|
||||
# depends on the equivalent .c, so if one has been
|
||||
# modified since last execution of ALL, it's recompiled in
|
||||
# object file with use of automatic variables $@ and $<
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# #clean:
|
||||
# /bin/rm -rf $(ODIR)
|
||||
#
|
||||
# "make clean" suppress all the .o files
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# fclean: clean
|
||||
# /bin/rm -f $(NAME)
|
||||
#
|
||||
# "make fclean" call CLEAN and suppress the executable
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# re: fclean all
|
||||
#
|
||||
# "make fclean" basically rerun make
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# .PHONY: all clean fclean re
|
||||
#
|
||||
# a phony target is one that is not the name of a file
|
||||
# if a file called "clean" for instance exist, the rule
|
||||
# CLEAN will never be executed when prompt "make clean"
|
||||
# because it will be considered up to date, but if it's
|
||||
# declared to be phony it will be executed in any case
|
||||
|
||||
# - - - - - - - - - - - - - - -
|
||||
# makefile with subdirectories
|
||||
# - - - - - - - - - - - - - - -
|
||||
|
||||
# put the .o in a "builds/" directory
|
||||
#
|
||||
# have the .c in a "srcs/" directory
|
||||
#
|
||||
# have the .h in an "includes" directory
|
||||
#
|
||||
# have multiples .a files
|
||||
#
|
||||
# [archtecture]
|
||||
# # srcs/
|
||||
# # main.c
|
||||
# # function01.c
|
||||
# # function02.c
|
||||
# # includes/
|
||||
# # header01.h
|
||||
# # header02.h
|
||||
# # libtest.a
|
||||
# # liboption.a
|
||||
# # Makefile
|
||||
#
|
||||
# # #-------------#
|
||||
# # # VARIABLES #
|
||||
# # #-------------#
|
||||
# # NAME = program_test
|
||||
# # CC = gcc
|
||||
# # VPATH = srcs
|
||||
# #
|
||||
# # IDIR = includes
|
||||
# # _DEPS = header01.h \
|
||||
# # header02.h
|
||||
# # DEPS = $(_DEPS:%.h=$(IDIR)/%.h)
|
||||
# #
|
||||
# # LDIR = ./
|
||||
# # _LIBS = libtest.a \
|
||||
# # liboption.a
|
||||
# # LIBS = $(_LIBS:lib%.a=%)
|
||||
# #
|
||||
# # SRCS = main.c \
|
||||
# # function01.c
|
||||
# # function02.c
|
||||
# # ODIR = ./builds
|
||||
# # OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||
# #
|
||||
# # CFLAGS = -I$(IDIR)
|
||||
# # LFLAGS = -L$(LDIR) -l$(LIBS)
|
||||
# #
|
||||
# # #---------#
|
||||
# # # RULES #
|
||||
# # #---------#
|
||||
# # all: $(ODIR) $(NAME)
|
||||
# # $(NAME): $(OBJS) $(DEPS)
|
||||
# # $(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||
# # $(ODIR):
|
||||
# # mkdir -p $@
|
||||
# # $(ODIR)/%.o: %.c
|
||||
# # $(CC) $(CFLAGS) -c -o $@ $<
|
||||
# # clean:
|
||||
# # /bin/rm -rf $(ODIR)
|
||||
# # fclean: clean
|
||||
# # /bin/rm -f $(NAME)
|
||||
# # re: fclean all
|
||||
# # .PHONY: all clean fclean re
|
||||
#
|
||||
# # prompt "make" execute the first rule ("all")
|
||||
#
|
||||
# [archtecture]
|
||||
# # srcs/
|
||||
# # main.c
|
||||
# # function01.c
|
||||
# # function02.c
|
||||
# # includes/
|
||||
# # header01.h
|
||||
# # header02.h
|
||||
# # builds/
|
||||
# # main.o
|
||||
# # function01.o
|
||||
# # function02.o
|
||||
# # libtest.a
|
||||
# # liboption.a
|
||||
# # Makefile
|
||||
# # program_test
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# LIBS = $(_LIBS:lib%.a=%)
|
||||
#
|
||||
# from "libtest.a" abd "liboption.a" it creates "test"
|
||||
# and option
|
||||
#
|
||||
# as said, the value of the % in "replacement" is
|
||||
# replaced with the text matched by the % in "pattern"
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||
#
|
||||
# creates the list of .o from the .c with addition of the
|
||||
# path directory "builds/main.o"
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# all: $(ODIR) $(NAME)
|
||||
# $(ODIR):
|
||||
# mkdir -p $@
|
||||
#
|
||||
# ALL call the rull ODIR wich verify if the objects files
|
||||
# directory already exist and if not, create it
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# $(NAME): $(OBJS) $(DEPS)
|
||||
# $(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||
#
|
||||
# NAME depends on OBJS and DEPS, so if any .o or any .h
|
||||
# have more recent date of modification NAME will execute
|
||||
# only for them
|
||||
#
|
||||
# -----
|
||||
#
|
||||
# clean:
|
||||
# /bin/rm -rf $(ODIR)
|
||||
#
|
||||
# "make clean" suppress all the .o files
|
||||
#
|
||||
# -----
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - -
|
||||
# makefile qui make un autre makefile
|
||||
# - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
|
||||
# - - - - - - - - - - - - - - -
|
||||
# makefile pour une librairie
|
||||
# - - - - - - - - - - - - - - -
|
||||
|
||||
|
||||
|
||||
# # create the folder where all the .o files will be stored
|
||||
# $(ODIR):
|
||||
# mkdir -p $(ODIR)
|
||||
|
||||
Reference in New Issue
Block a user