diff --git a/.DS_Store b/.DS_Store index c5effae..3112e2f 100644 Binary files a/.DS_Store and b/.DS_Store differ 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 8a91bcf..78735ef 100644 Binary files a/test/builds/main.o and b/test/builds/main.o differ diff --git a/test/builds/to_uppercase.o b/test/builds/to_uppercase.o new file mode 100644 index 0000000..e8f61a5 Binary files /dev/null and b/test/builds/to_uppercase.o differ 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 e8415bc..0000000 Binary files a/test/test and /dev/null differ