petites transformations sur les makefiles

This commit is contained in:
hugogogo
2022-02-27 22:07:04 +01:00
parent c056db80b7
commit 8f6c8259c8
15 changed files with 351 additions and 0 deletions

View File

@@ -9,6 +9,10 @@ NAME = pure
#TYPE = c #TYPE = c
TYPE = cpp TYPE = cpp
ifndef TYPE
echo hello
endif
ifeq "$(TYPE)" "c" ifeq "$(TYPE)" "c"
CC = c CC = c
EXT = c EXT = c

BIN
d04/ex02/pure Executable file

Binary file not shown.

82
d04/ex03/Makefile Normal file
View File

@@ -0,0 +1,82 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# . name = value \ . += append to a variable #
# VARIABLES . value . != set result of command #
# . name is case sensitive . ?= set if not already set #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
NAME = materia
#TYPE = c
TYPE = cpp
ifeq "$(TYPE)" "c"
CC = c
EXT = c
else ifeq "$(TYPE)" "cpp"
CC = c++
EXT = cpp
endif
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
ifeq "$(TYPE)" "cpp"
CFLAGS += -std=c++98
endif
VPATH = $(D_SRCS)
LIBS =
INCLUDES = -I$(D_HEADERS)
D_SRCS = srcs
SRCS = main.cpp \
Animal.cpp \
Dog.cpp \
Cat.cpp \
Brain.cpp
D_HEADERS = headers
HEADERS = Animal.hpp \
Dog.hpp \
Cat.hpp \
Brain.hpp
D_OBJS = builds
OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)
ifeq "$(D_OBJS)" "."
RM_OBJS = rm -f $(OBJS)
else
RM_OBJS = rm -rf $(D_OBJS)
endif
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# . target: prerequisites . $@ : target #
# RULES . recipe . $< : 1st prerequisite #
# . recipe . $^ : all prerequisites #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
all: $(NAME)
$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS)
$(CC) $(CFLAGS) -c $< -o $@
$(D_OBJS):
mkdir $@
$(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
$(NAME): $(OBJS)
$(CC) $(OBJS) -o $@ $(LIBS)
clean:
$(RM_OBJS)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY : all clean fclean re

View File

@@ -0,0 +1,24 @@
#ifndef AMATERIA_HPP
# define AMATERIA_HPP
# include <iostream>
#include "ICharacter.hpp"
class AMateria {
public:
AMateria(std::string const & type);
virtual ~AMateria();
std::string const & getType() const; //Returns the materia type
virtual AMateria* clone() const = 0;
virtual void use(ICharacter& target);
protected:
std::string _type;
};
#endif

View File

@@ -0,0 +1,18 @@
#ifndef CHARACTER_HPP
# define CHARACTER_HPP
#include "ICharacter.hpp"
class Character : public ICharacter {
public:
Character();
Character( Character const & src );
~Character();
Character & operator=( Character const & rhs );
private:
};
#endif

19
d04/ex03/headers/Cure.hpp Normal file
View File

@@ -0,0 +1,19 @@
#ifndef CURE_HPP
# define CURE_HPP
#include "AMateria.hpp"
class Cure : public AMateria {
public:
Cure();
Cure( Cure const & src );
~Cure();
Cure & operator=( Cure const & rhs );
private:
};
#endif

View File

@@ -0,0 +1,15 @@
#ifndef ICE_HPP
# define ICE_HPP
class ICharacter {
public:
virtual ~ICharacter() {}
virtual std::string const & getName() const = 0;
virtual void equip(AMateria* m) = 0;
virtual void unequip(int idx) = 0;
virtual void use(int idx, ICharacter& target) = 0;
};
#endif

18
d04/ex03/headers/Ice.hpp Normal file
View File

@@ -0,0 +1,18 @@
#ifndef ICE_HPP
# define ICE_HPP
#include "AMateria.hpp"
class Ice : public AMateria {
public:
Ice();
Ice( Ice const & src );
~Ice();
Ice & operator=( Ice const & rhs );
private:
};
#endif

32
d04/ex03/main.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include "AMateria.hpp"
#include "Ice.hpp"
#include "Cure.hpp"
#include "ICharacter"
#include "IMateriaSource"
int main() {
IMateriaSource* src = new MateriaSource();
src->learnMateria(new Ice());
src->learnMateria(new Cure());
ICharacter* me = new Character("me");
AMateria* tmp;
tmp = src->createMateria("ice");
me->equip(tmp);
tmp = src->createMateria("cure");
me->equip(tmp);
ICharacter* bob = new Character("bob");
me->use(0, *bob);
me->use(1, *bob);
delete bob;
delete me;
delete src;
return 0;
}

View File

@@ -0,0 +1,14 @@
#include "AMateria.hpp"
AMateria::AMateria(std::string const & type) {
_type = type;
}
std::string const & AMateria::getType() const {
return _type;
}
virtual AMateria * AMateria::clone() const {
AMateria clone = new AMateria;
return clone;
}

15
d04/ex03/srcs/Cure.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include "Cure.hpp"
Cure::Cure() : _type("cure") {}
Cure::Cure( Cure const & src ) {
*this = src
}
Cure & Cure::operator=( Cure const & rhs ) {
return *this;
}
virtual void Ice::use(ICharacter & target) {
std::cout << "* heals " << target.name << "s wounds *"
}

15
d04/ex03/srcs/Ice.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include "Ice.hpp"
Ice::Ice() : _type("ice") {}
Ice::Ice( Ice const & src ) {
*this = src
}
Ice & Ice::operator=( Ice const & rhs ) {
return *this;
}
virtual void Ice::use(ICharacter & target) {
std::cout << "* shoots an ice bolt at " << target.name << " *"
}

14
d05/ex00/Bureaucrate.hpp Normal file
View File

@@ -0,0 +1,14 @@
#ifndef BUREAUCRATE_HPP
# define BUREAUCRATE_HPP
class Bureaucrate {
public:
Bureaucrate();
Bureaucrate(std::string name, int grade);
private:
std::string const _name;
int _grade;
}
#endif

71
d05/ex00/Makefile Normal file
View File

@@ -0,0 +1,71 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# . name = value \ . += append to a variable #
# VARIABLES . value . != set result of command #
# . name is case sensitive . ?= set if not already set #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
NAME = bureaucrate
#CC = gcc
CXX = c++
#CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
CXXFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98
#EXT = c
EXT = cpp
VPATH = $(D_SRCS)
LIBS =
INCLUDES = -I$(D_HEADERS)
D_SRCS = .
SRCS = main.cpp \
Bureaucrate.cpp
D_HEADERS = .
HEADERS = Bureaucrate.hpp
D_OBJS = builds
OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)
ifeq "$(D_OBJS)" "."
RM_OBJS = rm -f $(OBJS)
else
RM_OBJS = rm -rf $(D_OBJS)
endif
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# . target: prerequisites . $@ : target #
# RULES . recipe . $< : 1st prerequisite #
# . recipe . $^ : all prerequisites #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
all: $(NAME)
$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS)
# $(CC) $(CFLAGS) -c $< -o $@
$(CXX) $(CXXFLAGS) -c $< -o $@
$(D_OBJS):
mkdir $@
$(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
$(NAME): $(OBJS)
# $(CC) $(OBJS) -o $@ $(LIBS)
$(CXX) $(OBJS) -o $@ $(LIBS)
clean:
$(RM_OBJS)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY : all clean fclean re

10
d05/ex00/main.cpp Normal file
View File

@@ -0,0 +1,10 @@
int main() {
try
{
}
catch (std::exception & e)
{
}
}