ajout explications
This commit is contained in:
BIN
.OLDMakefile.swp
Normal file
BIN
.OLDMakefile.swp
Normal file
Binary file not shown.
119
Makefile
119
Makefile
@@ -1,9 +1,11 @@
|
|||||||
|
# - - - - - - - - - #
|
||||||
|
# variables names #
|
||||||
|
# - - - - - - - - - #
|
||||||
|
|
||||||
# - - - - - - - - -
|
# each variable will expand in its value when used
|
||||||
# variables names
|
|
||||||
# - - - - - - - - -
|
|
||||||
|
|
||||||
NAME = libft.a
|
NAME = libft.a
|
||||||
|
DEP = libft.h
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall -Wextra -Werror -I. -c
|
CFLAGS = -Wall -Wextra -Werror -I. -c
|
||||||
SRCS = ft_atoi.c \
|
SRCS = ft_atoi.c \
|
||||||
@@ -75,59 +77,67 @@ SRCS = ft_atoi.c \
|
|||||||
ft_arraymap.c \
|
ft_arraymap.c \
|
||||||
ft_putnbrbase.c \
|
ft_putnbrbase.c \
|
||||||
ft_strmultisplit.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))
|
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
|
# rules to execute #
|
||||||
# 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
|
# - 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)
|
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):
|
$(ODIR):
|
||||||
mkdir -p $(ODIR)
|
mkdir -p $(ODIR)
|
||||||
|
|
||||||
# NAME will create the library libft.a
|
# - NAME will create the library libft.a
|
||||||
# first it checks if any OBJ (files.o) have more recent
|
# - first it checks if any OBJ (files.o) have more recent
|
||||||
# date of modification than NAME (libft.a), and for each
|
# date of modification than NAME (libft.a), and for each
|
||||||
# it will execute
|
# it will execute
|
||||||
|
# - $(OBJ) will expand in the list of files.o and each of
|
||||||
# first it checks if the date of modification of any .o (OBJ)
|
# them will call the rule "$(ODIR)/%.o:" below because it
|
||||||
# is more recent thant the one of libft.a (NAME)
|
# has its exact pattern
|
||||||
# and for each of them it will execute
|
# - NAME will execute only for the .c that has been
|
||||||
# if only one .c has been modified then only one .o will have been too
|
# modified since last creation of NAME
|
||||||
# so NAME will execute only for this one
|
# - ranlib is precedeed by a "@" to avoid being print
|
||||||
# ranlib doesn't need to be seen so it's precedeed by a "@"
|
$(NAME): $(OBJ) $(DEP)
|
||||||
$(NAME): $(OBJ)
|
|
||||||
ar -rc $@ $<
|
ar -rc $@ $<
|
||||||
@ranlib $@
|
@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
|
$(ODIR)/%.o: %.c
|
||||||
$(COMPILE.c) -o $@ $<
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
/bin/rm -rf $(ODIR)
|
/bin/rm -rf $(ODIR)
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
/bin/rm -f $(NAME)
|
/bin/rm -f $(NAME)
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
.PHONY: clean
|
.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
|
# 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
|
# exemple d'un makefilede basic
|
||||||
#
|
#
|
||||||
|
# # |DECLARATION VARIABLES
|
||||||
# # NAME = libtest.h
|
# # NAME = libtest.h
|
||||||
# # CC = gcc
|
# # CC = gcc
|
||||||
# # CFLAGS = -I. -c
|
# # CFLAGS = -I. -c
|
||||||
@@ -476,6 +475,19 @@ re: fclean all
|
|||||||
# par exemple pour construire des .o a partir de .c
|
# par exemple pour construire des .o a partir de .c
|
||||||
# qui sont utilisees par défaut si les variables
|
# qui sont utilisees par défaut si les variables
|
||||||
# sont bien nomee (genre CC ou CFLAGS)
|
# 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
|
# cependant si on veut mettre les fichiers .o dans un
|
||||||
# sous-fichier BUILDS il n'y a pas de built-in pattern
|
# 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 :"
|
# $< = "la premiere valeur a droite de :"
|
||||||
# $^ = "toutes les valeurs 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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
24
main.c
24
main.c
@@ -1,24 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
BIN
astuce → test/.Makefile.swp
Executable file → Normal file
BIN
astuce → test/.Makefile.swp
Executable file → Normal file
Binary file not shown.
9
test/Makefile
Normal file
9
test/Makefile
Normal file
@@ -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 $<
|
||||||
|
|
||||||
9
test/main.c
Normal file
9
test/main.c
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int a = 't';
|
||||||
|
a = transform(a);
|
||||||
|
ft_putchar(a);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
BIN
test/main.o
Normal file
BIN
test/main.o
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
#include <unistd.h>
|
#include "test.h"
|
||||||
|
|
||||||
void ft_putchar(char c)
|
void ft_putchar(char c)
|
||||||
{
|
{
|
||||||
Binary file not shown.
9
test/test.h
Normal file
9
test/test.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# ifndef TEST_H
|
||||||
|
# define TEST_H
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void ft_putchar(char c);
|
||||||
|
int transform(int a);
|
||||||
|
|
||||||
|
# endif
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "test.h"
|
||||||
|
|
||||||
int transform(int a)
|
int transform(int a)
|
||||||
{
|
{
|
||||||
return(--a);
|
return(--a);
|
||||||
Reference in New Issue
Block a user