petites transformations sur les makefiles
This commit is contained in:
@@ -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
BIN
d04/ex02/pure
Executable file
Binary file not shown.
82
d04/ex03/Makefile
Normal file
82
d04/ex03/Makefile
Normal 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
|
||||||
|
|
||||||
24
d04/ex03/headers/AMateria.hpp
Normal file
24
d04/ex03/headers/AMateria.hpp
Normal 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
|
||||||
18
d04/ex03/headers/Character.hpp
Normal file
18
d04/ex03/headers/Character.hpp
Normal 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
19
d04/ex03/headers/Cure.hpp
Normal 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
|
||||||
|
|
||||||
15
d04/ex03/headers/ICharacter.hpp
Normal file
15
d04/ex03/headers/ICharacter.hpp
Normal 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
18
d04/ex03/headers/Ice.hpp
Normal 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
32
d04/ex03/main.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
14
d04/ex03/srcs/AMateria.cpp
Normal file
14
d04/ex03/srcs/AMateria.cpp
Normal 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
15
d04/ex03/srcs/Cure.cpp
Normal 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
15
d04/ex03/srcs/Ice.cpp
Normal 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
14
d05/ex00/Bureaucrate.hpp
Normal 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
71
d05/ex00/Makefile
Normal 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
10
d05/ex00/main.cpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
int main() {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (std::exception & e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user