include                         $(MORPHEO_TOPLEVEL)/Makefile.tools

#-----[ Directory ]----------------------------------------
DIR_TST                         = selftest
DIR_INC				= include
DIR_SRC				= src
DIR_OBJ				= obj
DIR_BIN				= bin

#-----[ Compilation ]--------------------------------------
INCDIR 				= $(SYSTEMC_INCDIR_$(SIMULATOR)) 	\
				  -I$(DIR_INC) 

LIBDIR 				= 

FLAGS				= $(SYSTEMC_CFLAGS_$(SIMULATOR))	\
				  $(CXX_FLAGS)

CFLAGS				= $(MORPHEO_FLAGS) $(FLAGS) $(INCDIR)
LFLAGS				= $(MORPHEO_FLAGS) $(FLAGS) $(LIBDIR)

#-----[ Variable ]-----------------------------------------

ENTITY				= `$(BASENAME) $$PWD`

OBJECTS				= $(patsubst $(DIR_SRC)/%.cpp,$(DIR_OBJ)/%.o,$(wildcard $(DIR_SRC)/*.cpp))
OBJECTS_BIN			= $(patsubst $(DIR_TST)/%.cpp,$(DIR_OBJ)/%.o,$(wildcard $(DIR_TST)/*.cpp))

HEADERS  			= $(wildcard $(DIR_INC)/*.h)

EXE				= $(DIR_BIN)/soft.x

#-----[ Rules ]--------------------------------------------

.PRECIOUS			: $(DIR_OBJ)/%.o $(DIR_BIN)/%.x

test_env			:
				@$(ECHO) "-------------------[ $(ENTITY) ]"

$(DIR_OBJ)/%.o			: $(DIR_SRC)/%.cpp $(HEADERS)
				@\
				$(ECHO) "Compilation        : $*";\
				$(CXX) $(CFLAGS) -c -o $@ $<;

$(DIR_OBJ)/%.o			: $(DIR_TST)/%.cpp $(HEADERS)
				@\
				$(ECHO) "Compilation        : $*";\
				$(CXX) $(CFLAGS) -c -o $@ $<;

$(DIR_BIN)/%.x			: $(OBJECTS_DEPS) $(OBJECTS) $(OBJECTS_BIN)
				\
				$(ECHO) "Compilation        : $*";\
				$(CXX) $(LFLAGS)    -o $@ $^;

$(DIR_OBJ)			:
				@\
				$(ECHO) "Create directory   : $@";\
				$(MKDIR) $@

$(DIR_BIN)			:
				@\
				$(ECHO) "Create directory   : $@";\
				$(MKDIR) $@


exe				: all_environnement
				@\
				$(VALGRIND) ./$(EXE)

all_environnement		: test_env $(DIR_OBJ) $(DIR_BIN)
				@\
				$(MAKE) $(EXE)

environnement_clean		:
				@\
				$(ECHO) "Delete     temporary files in directory "$(PWD);\
				$(RM) 	*~ 		\
					$(DIR_OBJ) 	\
					$(DIR_BIN) 	\
					$(DIR_TST)/*~	\
					$(DIR_SRC)/*~	\
					$(DIR_INC)/*~;

environnement_help		:
				@\
				$(ECHO) " -----[ Environnement ]------------------------------";\
				$(ECHO) "";\
				$(ECHO) " * test_env             : test if environnment's variable is set";\
				$(ECHO) " * all_environnement    : generate object";\
				$(ECHO) "";
