# 
#
#
export debug=0
export release=1
#
export RED='\E[1;31;40m'
export GREEN='\E[1;32;40m'
export YELLOW='\E[1;33;40m'
export BLUE='\E[1;34;40m'
export WHITE='\E[1;37;40m'
export VIOLET='\E[1;35;40m'
export CYAN='\E[1;36;40m'
# Here the echo definition to use them
export EVIOLET=echo -e ${VIOLET}
export ECYAN=echo -e ${CYAN}
export ERED=echo -e ${RED}
export EGREEN=echo -e ${GREEN}
export EYELLOW=echo -e ${YELLOW}
export EBLUE=echo -e ${BLUE}
export EWHITE=echo -e ${WHITE}
# Reset the terminal
export RESET=tput sgr0
#
export BASEDIR=$(shell echo `pwd`)
export LD_LIBRARY_PATH+=$(BASEDIR)/event
#
export LDFLAGS+=$(PAM_BIT) 
export CFLAGS+=$(PAM_BIT) 
export FFLAGS+=$(PAM_BIT) 
#
DIRS=event PamOffLineSW YodaProfiler
#
all: 
	for sub_dir in $(DIRS) ; do \
		( cd $$sub_dir && make BASEDIR=$(BASEDIR)) ; \
	done

distclean: 
	for sub_dir in $(DIRS) ; do \
		( cd $$sub_dir && make distclean) ; \
	done
	for sub_dir in `find ./ -name obj` ; do \
		rm -rf $$sub_dir ; \
	done

install:
	@(${EGREEN} " Creating PAMELA environment "; ${RESET})
	@if [ "$(PAM_SOFTWARE)" == "" ]; then (${ERED} ""; ${RESET}); \
		(${ERED} " PLEASE SET THE PAMELA ENVIRONMENT BEFORE INSTALLING "; ${RESET}); \
		(${ERED} ""; ${RESET}); \
		exit; fi
	@if [ ! -d $(PAM_HOME) ]; then mkdir $(PAM_HOME); fi
	@if [ ! -d $(PAM_SOFTWARE) ]; then mkdir $(PAM_SOFTWARE); fi
	@if [ ! -d $(PAM_LIB) ]; then mkdir $(PAM_LIB); fi
	@if [ ! -d $(PAM_INC) ]; then mkdir $(PAM_INC); fi
	@ln -sf $(PAM_SOFTWARE)/inc $(PAM_SOFTWARE)/include
	@if [ ! -d $(PAM_BIN) ]; then mkdir $(PAM_BIN); fi
	@if [ ! -d $(PAM_DOC) ]; then mkdir $(PAM_DOC); fi
	@if [ ! -d $(PAM_MACROS) ]; then mkdir $(PAM_MACROS); fi
	@if [ ! -d $(PAM_SRC) ]; then mkdir $(PAM_SRC); fi
	@if [ ! -d $(PAM_CALIB) ]; then mkdir $(PAM_CALIB); fi
	@if [ ! -d $(FEV_PLUGIN) ]&&[ "$(FEV_PLUGIN)" != "" ]; then mkdir $(FEV_PLUGIN); fi
	@(${EGREEN} " Installing "${EWHITE}"libyoda.so "; ${RESET})  
	@cp -f $(BASEDIR)/event/libyoda.so.0.0.0 $(PAM_LIB)/
	@ln -sf $(PAM_LIB)/libyoda.so.0.0.0 $(PAM_LIB)/libyoda.so 
	@ln -sf $(PAM_LIB)/libyoda.so.0.0.0 $(PAM_LIB)/libyoda.so.0 
	@(${EGREEN} " Installing exec file "${EWHITE}"chewbacca"; ${RESET})  
	@cp -f $(BASEDIR)/PamOffLineSW/chewbacca $(PAM_BIN)/
	@(${EGREEN} " Installing "${EWHITE}"yoda headers";${RESET})  
	@(cd $(BASEDIR)/event/ && make distclean)
	@rm -rf $(PAM_INC)/yoda/
	@cp -rf $(BASEDIR)/event/ $(PAM_INC)/yoda/
	@cp -rf $(PAM_LIB)/libyoda.so $(BASEDIR)/event/
	@(${EGREEN}"")
	@(cd YodaProfiler && make forceinstall)
