diff --git a/.OLDMakefile.swp b/.OLDMakefile.swp new file mode 100644 index 0000000..8086d06 Binary files /dev/null and b/.OLDMakefile.swp differ 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 7160f6f..0000000 Binary files a/main.o and /dev/null differ diff --git a/astuce b/test/.Makefile.swp old mode 100755 new mode 100644 similarity index 53% rename from astuce rename to test/.Makefile.swp index ca2a6d4..8699658 Binary files a/astuce and b/test/.Makefile.swp differ 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 0000000..8a91bcf Binary files /dev/null and b/test/main.o differ diff --git a/putchar.c b/test/putchar.c similarity index 71% rename from putchar.c rename to test/putchar.c index 81b5035..07d8c03 100644 --- a/putchar.c +++ b/test/putchar.c @@ -1,4 +1,4 @@ -#include +#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 ca2a6d4..b532226 100755 Binary files a/a.out and b/test/test differ diff --git a/test/test.h b/test/test.h new file mode 100644 index 0000000..618baa2 --- /dev/null +++ b/test/test.h @@ -0,0 +1,9 @@ +# ifndef TEST_H +# define TEST_H + +#include + +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 704aeb3..0000000 Binary files a/truc and /dev/null differ