# 
# $Id$
# 
# [ Description ]
# 
# Makefile
# 

include                         $(MORPHEO_TOPLEVEL)/Makefile.tools

#-----[ Directory ]----------------------------------------
DIR_INC				= include
DIR_SRC				= src
DIR_OBJ				= obj
DIR_SCRIPT			= $(MORPHEO_SCRIPT)

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

LIBDIR 				= $(DIR_LIBRARY)			\
				  $(SYSTEMC_LIBDIR_$(SIMULATOR)) 	\
				  $(SOCLIB_LIBDIR)   			\
				  $(OR1K_LIBDIR) 				

LIBS		   		= $(LIBRARY) -lm $(SYSTEMC_LIBNAME_$(SIMULATOR)) $(SOCLIB_LIBNAME) $(OR1K_LIBNAME) -lbfd  -ldl

FLAGS_COMMON			= $(SYSTEMC_CFLAGS_$(SIMULATOR))	\
				  -O3					\
				  -g3   				\
				  -Wall					\
				  -Wunused

#				  -Wno-deprecated 			\
#				  -Wno-non-template-friend		\
#				  -Wno-pmf-conversions 			\
#				  -Wfatal-errors 			\
# 		                  -pedantic                   		\
# 				  -Werror				\

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

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

ENTITY				= `$(BASENAME) $$PWD`

OBJECTS_COMMON			= $(patsubst $(DIR_SRC)/%.cpp,$(DIR_OBJ)/%.o,$(wildcard $(DIR_SRC)/*.cpp))

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

#-----[ Rules ]--------------------------------------------
.PRECIOUS			: $(DIR_OBJ)/%.o

test_env			:
				@$(ECHO) "-------------------[ $(ENTITY) ]"
ifeq ($(origin MORPHEO_TOPLEVEL), undefined)
				$(error "variable MORPHEO_TOPLEVEL is undefined");
endif
ifeq ($(origin MORPHEO_SCRIPT), undefined)
				$(error "variable MORPHEO_SCRIPT   is undefined");
endif
ifeq ($(origin DIR_MORPHEO), undefined)
				$(error "variable DIR_MORPHEO      is undefined");
endif

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

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

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

common_help			:
				@$(ECHO) " -----[ Common ]-------------------------------------"
				@$(ECHO) ""
				@$(ECHO) " * test_env             : test if environnment's variable is set"
				@$(ECHO) ""
