From ac4a5e088cfb8c6d138fc228838c66ac515d33ae Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Wed, 13 Nov 2019 12:48:59 +0100 Subject: [PATCH] ajout explications --- .OLDMakefile.swp | Bin 0 -> 16384 bytes Makefile | 119 +++++++++++++++++++------------- main.c | 24 ------- main.o | Bin 676 -> 0 bytes astuce => test/.Makefile.swp | Bin 8520 -> 12288 bytes test/Makefile | 9 +++ libtest.a => test/libtest.a | Bin test/main.c | 9 +++ test/main.o | Bin 0 -> 728 bytes putchar.c => test/putchar.c | 2 +- putchar.o => test/putchar.o | Bin a.out => test/test | Bin 8520 -> 8520 bytes test/test.h | 9 +++ transform.c => test/transform.c | 2 + transform.o => test/transform.o | Bin truc | Bin 8520 -> 0 bytes 16 files changed, 102 insertions(+), 72 deletions(-) create mode 100644 .OLDMakefile.swp delete mode 100644 main.c delete mode 100644 main.o rename astuce => test/.Makefile.swp (53%) mode change 100755 => 100644 create mode 100644 test/Makefile rename libtest.a => test/libtest.a (100%) create mode 100644 test/main.c create mode 100644 test/main.o rename putchar.c => test/putchar.c (71%) rename putchar.o => test/putchar.o (100%) rename a.out => test/test (88%) create mode 100644 test/test.h rename transform.c => test/transform.c (67%) rename transform.o => test/transform.o (100%) delete mode 100755 truc diff --git a/.OLDMakefile.swp b/.OLDMakefile.swp new file mode 100644 index 0000000000000000000000000000000000000000..8086d06240e9debb33e5fb236abda90bec36d7fe GIT binary patch literal 16384 zcmeI2TZ|-C8Gs8xa6m4)fFWu;J2TibuwA{gOT-Mfh1ms0XIb3g5)8{)T~$3(&|TGA zm)TwArV`0Uj870v@JW0i5#d1+B@z`)d{RR+8s0=-1VzO_Vg!ue|DUSro@H5F0tqHH zJ6}&%)w%tb^PhA6+V18X7I&IYx^oUcXE@Fe&;I$I-wYk+#~*N<)uQhW4$6b0|Abr9 z3x{)?-3zw3z4RzW@3ake`cb!+cXlmp-|5{J_M(1xlse6$Mgxro-YyNC>TKOIw^>@7 zn%rnMeDM0WtKp`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5nIi_)JKZAc2adReUS_2Iob5ZVmDD<+qbHejXOv6l+Iu(HaLr32IgeF|3;X>| z&8G$44K}Q^qtmw-G(D;58=G8RBQ3=IB^wl^B#<=&H9sj)V)|k&+aG)XVhbOs?6#_G zU1Y^8Bs>rRY;)(Ljk0TLUV0FP>MNbh;5?kkN?)^y$5Cod%9iVe=J+%tg(KzdNK&%a zHpDP8fcD^Bwr^AXbpdZU)GRj=*%wK6k?3faB+*wAwuXHwxvH{?MADRy&#JLJYlcOX z=@CqXn3{Nl#Z2--W2i(PRa~g(PgKwTB*WZBk9B`r$B)N$Kb-2$DT(^3tcw z^oVDbP3kL)GV{a0`IR?Vx#{v+M_!_YylGkqV{)iS#Cs^~gX#_9QChYt~`_>?3A~sOlO96 MxY|rAB~kl-0i4)QBme*a literal 0 HcmV?d00001 diff --git a/Makefile b/Makefile index 0b0b671..55736c4 100644 --- a/Makefile +++ b/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 + + diff --git a/main.c b/main.c deleted file mode 100644 index f282343..0000000 --- a/main.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* main.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: hulamy +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/08 13:33:32 by hulamy #+# #+# */ -/* Updated: 2019/11/08 13:33:45 by hulamy ### ########.fr */ -/* */ -/* ************************************************************************** */ - - -/*void ft_putchar(char c); - -int transform(int a); -*/ -int main() -{ - int a = 't'; - a = transform(a); - ft_putchar(a); - return (0); -} diff --git a/main.o b/main.o deleted file mode 100644 index 7160f6f25d3c6a0013abc94f16c945abc8bee520..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 676 zcma)3F-yZ>5WQ4sMQzQXpx}^#gNvX}j*1pCIEYkmku$`UbVv*(#o{Csif$eKDQ*f1 zj;{Uz!9o9ki25$y_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bUBSKhauCWZw|^$vkOdOzZHzNgYy=ia^rd-HI4 z*Uzxp{i9F)Qpo6(J5EX=G}?uxFfFd`$U6S>cHhKFP}OT8zK>lHMX~f$|sNf{%}-bAs*`Q z5uF@u!F%yU-$j{p{7-NK3W?m5Un%2LfoR_CK-*rk&q F{R05D^`rm* diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..6596621 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,9 @@ +SRC = main.c putchar.c transform.c +DEP = test.h +OBJ = $(SRC:.c=.o) + +test: $(OBJ) + gcc -I. -o test $(OBJ) +%.o: %.c $(DEP) + gcc -I. -c $< + diff --git a/libtest.a b/test/libtest.a similarity index 100% rename from libtest.a rename to test/libtest.a diff --git a/test/main.c b/test/main.c new file mode 100644 index 0000000..45b5479 --- /dev/null +++ b/test/main.c @@ -0,0 +1,9 @@ +#include "test.h" + +int main() +{ + int a = 't'; + a = transform(a); + ft_putchar(a); + return (0); +} diff --git a/test/main.o b/test/main.o new file mode 100644 index 0000000000000000000000000000000000000000..8a91bcf5ec6123301d0efa883e5a7535f2188f79 GIT binary patch literal 728 zcmb7BF-yZ>5WQ4sMQt01feF2M3V~UF0LwmUc*5Vv0o&3I%ED;^
e?H6mE&G$vm+%LsZi->jt<0hIgf= ziI@Oi%K4u351|=&^wSnjl(fZbH6;Ps;` +#include "test.h" void ft_putchar(char c) { diff --git a/putchar.o b/test/putchar.o similarity index 100% rename from putchar.o rename to test/putchar.o diff --git a/a.out b/test/test similarity index 88% rename from a.out rename to test/test index ca2a6d453345a84aa7ba9f965e656d76186ea2df..b5322265e5aec77c5ce693c8bc9901bdb395f7b1 100755 GIT binary patch delta 360 zcmX@%bi!%E1wjFR1_nk328I?O1_6PI5A7!xFmiCRLHG<)CL1!^3(kQmlY)xQncN5z z-2oN#fQs(ee36l#Nnp!q^KSPSw#7@&o$VBR74UHK2WAUKfz6sM*SRJyU=f(aFDd&X z2&kpg^+&hskB)=<`+mL<0`d(Hcr+goh&?G}aGWXmru@?W(KY>`i| zY$}l982n!~bn*gz9bS+pOn@RFJazI-etpI@n*{|N1nSdD;tNVkk~0#E7#vHA67!1F z@{4jA+?assm>DL>0f`GBqCp-g00a}{91K7-NS>cj0K^0bju@EFzz_iSuM(6G3p@=d QzX2+54AI9p`GP_P01-t@$p8QV delta 368 zcmX@%bi!%E1wjUW1_nk328LcB27`$Y?FIXwf^1N+zR8A+_LCJDIXI=DB2y+eGTIAn zfU5I=if-6^k&&NCz%lRnEY=j0#t!kd#*y=$%%A*$*@BT_vnI=RuE_%Yk}4Y*UMK){ zbh`fNuKfYz7y~(m|2tj3bpG&YJ|Yl%c*2AUlWY0KnShiVzosHLP~M}{^#fG$ziJIo zz^7L>7f3k<|5uHjyn + +void ft_putchar(char c); +int transform(int a); + +# endif diff --git a/transform.c b/test/transform.c similarity index 67% rename from transform.c rename to test/transform.c index 4fa854c..36b8f0d 100644 --- a/transform.c +++ b/test/transform.c @@ -1,3 +1,5 @@ +#include "test.h" + int transform(int a) { return(--a); diff --git a/transform.o b/test/transform.o similarity index 100% rename from transform.o rename to test/transform.o diff --git a/truc b/truc deleted file mode 100755 index 704aeb393fda8aaa24f743376925b3ee50e8be39..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8520 zcmeHNOKVd>6rR|sMN6By@NK;m6m`+o$D&9ViS*hOi?3D?p^QnJkU)}_n;Y7K#bOl_ zN~H_;y6^}13w%_exN<4Da-kBzg3DNn@%tuo)0~gy(U}o%V(!k*$J7-CMFTonBOyv$2FqR zuEVRkYbDpA1eJ0iJQ}XK1^KR92X8%m>wrB{!h%R~LR4y$rCb z&u&4zpSBjuQq+lF)K}pn_v|mg<{ZnY>E8`y?HBG#>fhF@WHszx4bX-fU7{7*lg~Ll z=~S#|Vm3Vin{o)sJnp{lOYZyBzxFtvjD8q=d+!W<7Bm1AZM&4Rt+;Di37kSZ$UZG6 zFn{7$*jIkxbNis|WB!5lPnb$zGZ*ADGMjVbneGeS$SV~?5ac+N`14kk&y(6FUq%cA zh5^HXVZbn87%&VN1`GrLnt>aU;^*Sr#^T(@!fFMLVtMR!qPzX*ef8kPGW#P7--4_5 z20g2GnJ=G9FW1ByA1ahz@SI&-FW42; ziY(GHFkl!k3>XFs1BL;^fMLKeU>GnA z7zX|e20FTe*O+KWh?j@zGF--R-;B%aYmQhJPOu{+r=64=hd~KQ+{ZV|Oj5>Y;^TQY zj=SzC!~0w(n$0C9os8(uL{nK2PPlR^?~W&