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

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

#-----[ Commands ]-----------------------------------------
ECHO				= echo
EXPORT				= export
MKDIR				= mkdir -p
TEST				= test
READ				= read
DATE				= date +%Y%m%d-%H%M%S
CD				= cd
CP				= cp
CAT				= cat
LS				= ls
RM				= rm -fr
PWD				= `pwd`
MAKE				= make -s
AR				= ar -v
RANLIB				= ranlib
BASENAME			= basename
GREP				= grep
GREP_NOT			= egrep -v
TR				= tr
UPPERtoLOWER			= $(TR) [:lower:] [:upper:]

#-----[ Compilation ]--------------------------------------

SYSTEMC_systemc			= $(TOOLS)/systemc
SYSTEMC_systemcass 		= $(TOOLS)/systemcass
SYSTEMC_systemcass_deps 	= $(SYSTEMC_systemcass)

SYSTEMC				= $(SYSTEMC_$(SIMULATOR))

INCDIR 				= -I$(SYSTEMC)/include 	\
				  -I$(DIR_MORPHEO) 

DIRLIB_systemc			= lib-$(TARGET_ARCH) 	
DIRLIB_systemcass 		= lib
DIRLIB_systemcass_deps         	= $(DIRLIB_systemcass)

LIBDIR 				= $(DIR_LIBRARY)			\
		 		  -L$(SYSTEMC)/$(DIRLIB_$(SIMULATOR))  	\
				  -L$(TOOLS)/soclib/lib 		\
				  -L$(TOOLS)/or1k/lib 				

LIBS		   		= $(LIBRARY) -lm -lsystemc -lsoclib -lbfd -liberty -ldl
# target architecture
TARGET_ARCH	 		= linux

XX_systemc			=
XX_systemcass			= -rdynamic				\
				  -ansi                       		\
   	                	  -Wno-long-long

XX_systemcass_deps		= $(XX_systemcass)

EXEC_PARAMS_systemc		= 
EXEC_PARAMS_systemcass 		= --nobanner 
EXEC_PARAMS_systemcass_deps     = --nobanner --p


XX_COMMON			= -O3					\
				  -g3   				\
				  -Wall					\
				  -Wunused
#				  -Wno-deprecated 			\
#				  -Wno-non-template-friend		\
#				  -Wno-pmf-conversions 			\
#				  -Wfatal-errors 			\
# 		                  -pedantic                   		\
# 				  -Werror				\

XX_OPT    			= $(XX_COMMON) $(XX_$(SIMULATOR))

CXX				= export LANG=C; g++
CXX_OPT				= $(XX_OPT) $(FLAGS) $(INCDIR)
LXX_OPT				= $(XX_OPT) $(FLAGS) $(LIBDIR)

EXEC_PARAMS 			= $(EXEC_PARAMS_$(SIMULATOR))

#-----[ 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 TOOLS), undefined)
				$(error "variable TOOLS       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) $(CXX_OPT) -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) ""
