From 848931d53767b282f379807560b606ea3dbf7fef Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Fri, 15 Nov 2019 19:39:02 +0100 Subject: [PATCH] explicaiton des makefiles presque fini --- .DS_Store | Bin 6148 -> 6148 bytes Makefile | 324 +++++++++++++++++++++++++++++++------ test/Makefile | 4 +- test/builds/main.o | Bin 728 -> 780 bytes test/builds/to_uppercase.o | Bin 0 -> 632 bytes test/includes/test.h | 1 + test/srcs/main.c | 3 +- test/srcs/to_uppercase.c | 7 + test/test | Bin 8520 -> 0 bytes 9 files changed, 289 insertions(+), 50 deletions(-) create mode 100644 test/builds/to_uppercase.o create mode 100644 test/srcs/to_uppercase.c delete mode 100755 test/test diff --git a/.DS_Store b/.DS_Store index c5effae810f6131b3bdaf6c24b66dc4cc767dfec..3112e2f31ebdbe23cc2ba982599557781cbd25d8 100644 GIT binary patch delta 107 zcmZoMXfc@J&&ahgU^gQp*JK_hQ&kQIUxq}6Y=%^ZG=@xu9EMcSoc!dZoctsP1_l8j qUdh0~$g$asshm-ng`otfteBw$O^G!~$$v1|ypfrmWiva+Uw!~pMI0gk delta 36 scmZoMXfc@J&&aVcU^gQp$7CKR)6IoUIgFddI0RWHHh6Ak=lIJH0K`)YjsO4v diff --git a/Makefile b/Makefile index f5dc3cc..a48f294 100644 --- a/Makefile +++ b/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) diff --git a/test/Makefile b/test/Makefile index 280bff1..6b0b884 100644 --- a/test/Makefile +++ b/test/Makefile @@ -13,7 +13,7 @@ LDIR = ./ _LIBS = libtest.a LIBS = $(_LIBS:lib%.a=%) # FUNCTIONS et OBJETS # -SRCS = main.c #putchar.c transform.c +SRCS = main.c to_uppercase.c #putchar.c transform.c ODIR = ./builds OBJS = $(SRCS:%.c=$(ODIR)/%.o) # OPTIONS de GCC # @@ -25,7 +25,7 @@ LFLAGS = -L$(LDIR) -l$(LIBS) #---------# all: $(ODIR) $(NAME) $(NAME): $(OBJS) $(DEPS) - $(CC) $(CFLAGS) -o test $(OBJS) $(LFLAGS) + $(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS) $(ODIR): mkdir -p $@ $(ODIR)/%.o: %.c diff --git a/test/builds/main.o b/test/builds/main.o index 8a91bcf5ec6123301d0efa883e5a7535f2188f79..78735eff22a9fd6d79eba2dc35d483e9bee6fc4b 100644 GIT binary patch delta 221 zcmcb?+QT-%L2v~F1l(YR&?_be+KW0O39^%nMP&z+ehg3v{ZkDv)NLT*_q3C^vZ~lPzC-Nq&53K|yL!a$<2R F0|54kDa-%> delta 194 zcmeBSyTLlaL2w2G1l(YR&@(0m+KZYY39;TdVlUo_(8JQ+;WK^GgfRShN4MwHOtW0u@W|K9U%vC%7 hLjcTn21h=DHYR6YHmG@8K$>xKFO%`)3ru=I(*Uj@B0m5C diff --git a/test/builds/to_uppercase.o b/test/builds/to_uppercase.o new file mode 100644 index 0000000000000000000000000000000000000000..e8f61a51cded7bf9ae841a5fc1be8ea837d58db8 GIT binary patch literal 632 zcmX^A>+L^w1_nlE1|R{%EI_;i#83cYAdm!N3lJX%sDO&!fU1GtHx zttf%8A^Z^6h!6xH#u9}xK<0tm0tYM%4RAJ)5g(tNpIeZaToPZJSDu-d5+Cp5f-Elq zJYEg1xF))k){sug6 literal 0 HcmV?d00001 diff --git a/test/includes/test.h b/test/includes/test.h index 618baa2..c40b808 100644 --- a/test/includes/test.h +++ b/test/includes/test.h @@ -5,5 +5,6 @@ void ft_putchar(char c); int transform(int a); +int to_uppercase(int a); # endif diff --git a/test/srcs/main.c b/test/srcs/main.c index 45b5479..e096911 100644 --- a/test/srcs/main.c +++ b/test/srcs/main.c @@ -3,7 +3,8 @@ int main() { int a = 't'; + a = to_uppercase(a); a = transform(a); ft_putchar(a); - return (0); + return(0); } diff --git a/test/srcs/to_uppercase.c b/test/srcs/to_uppercase.c new file mode 100644 index 0000000..35d56ba --- /dev/null +++ b/test/srcs/to_uppercase.c @@ -0,0 +1,7 @@ +#include "test.h" + +int to_uppercase(int a) +{ + a -= 32; + return(a); +} diff --git a/test/test b/test/test deleted file mode 100755 index e8415bc3b952cfb8aee3c5e6e99f32b45711875a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8520 zcmeHNO=}ZD7@oCNi({j%Dw&V+F$j|YCQ7?5r z9gs2|-;U45c=m78{fWbTTqj|?v2I5$U%lcET@Kcq(=<sg)hM7V{dNP zcKr;i?LRBc_7vl`Y;5jquu;G$U=%P47zK<1MggOMQNSo*6fg=H1&jj!g#ukY_81fG zitzAI9fr#U&YN*~J?4p$@a(RLyz8a>Bmm8lIFE0YnHib9mz>P|Nt|`Z*?lk*Pi4gg z--~B+)3aViM5lc@m-i=U;-0v~?-MOzu^X4yynO0bY=}f0*4W-@)lMGy{b8TNLfp~c zBltC@lMNc