#*****************************************************************************
#
# FILE NAME:    $Id: Makefile,v 1.4 2008/09/23 14:57:45 mocchiut Exp $    
# VERSION:      
# AUTHOR:       Nergal S.r.l.
# DATE:
#
# DESCRIPTION:  base Makefile
#
# REVISION HISTORY:
#
# Version     Date      Author         Change Description
#
#*****************************************************************************/


#------------------------------------------------------------------------------
include $(BASEDIR)/PamOffLineSW/Make.def
#------------------------------------------------------------------------------


#CFLAGS += -I $(PAMOFF_DIR) -I $(TECH_DIR_INC) -I $(ROOT_DIR_INC) -I $(BASEDIR) -I $(EVENT_DIR) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -fPIC -DPIC 
CFLAGS += -I $(BASEDIR) -I $(EVENT_DIR) -I $(TECH_DIR) -I $(PAMOFF_DIR) -I $(ROOT_DIR_INC) -fPIC -DPIC 

CXXSRCS =	\
	PamOffLineSW_Main.cpp 	\
	StateManager.cpp 	\
	R0_Init_State.cpp 	\
	R1_FA_State.cpp 	\
	R2_FAFE_State.cpp 	\
	R3_FAFEDE_State.cpp 	\
	R4_HEADER_State.cpp 	\
	CRC16.cpp 		\
	PacketSemanticAnalyzer.cpp \
	PacketUser.cpp 		\
	Logger.cpp


#------------------------------------------------------------------------------

TARGETLIB = $(PAMOFF_A)

#------------------------------------------------------------------------------
EXECUTABLES=chewbacca
#EXECUTABLES=PamOffLineSW

all: $(EXECUTABLES)

$(EXECUTABLES): $(TARGETLIB) $(EXTLIB)
	$(CXX) $(PAM_BIT) -o  $@    -L ../event -lyoda -lg2c `root-config --libs` -lRMySQL $^

$(EXTLIB): $(EXTDIR)
	for sub_dir in $(EXTDIR) ; do \
		$(MAKE) -C $$sub_dir libs ; \
	done

libs: $(TARGETLIB)

$(TARGETLIB) : ${OBJS}
	$(AR) -scrv $@ ${OBJS}

SUBPACKET_HEADER_FILES = \

INCLUDES = -I. -I$(ROOT_DIR)/include 
DICT_HEADER_FILES = \
	PamelaRun.h		yodaversion.h		RunInfoYoda.h	\
	SubPacket.h		PacketType.h		SubDetector.h	\
	DirectoryStructure.h	Algorithm.h		AlgorithmInfo.h	\
	EventHeader.h		PscuHeader.h		EventCounter.h  \
	endrun/PhysEndRunEvent.h 					\
	endrun/CaloEndRun.h						\
	endrun/TBEndRun.h 						\
	log/LogEvent.h		log/LogRecord.h	\
	varDump/VarDumpEvent.h varDump/VarDumpRecord.h	\
	arrDump/ArrDumpEvent.h arrDump/ArrDumpRecord.h	\
	tabDump/TabDumpEvent.h tabDump/TabDumpRecord.h	\
	tmtc/TmtcEvent.h 	tmtc/TmtcRecord.h	\
	mcmd/McmdEvent.h	mcmd/McmdRecord.h	\
	physics/neutronDetector/NeutronEvent.h		\
	physics/neutronDetector/NeutronRecord.h		\
	physics/anticounter/AnticounterEvent.h		\
	physics/calorimeter/CalorimeterEvent.h		\
	physics/S4/S4Event.h				\
	physics/tof/TofEvent.h				\
	physics/tracker/TrackerEvent.h			\
	physics/trigger/TriggerEvent.h 			\
	tsbt/TsbTEvent.h	tsbt/TsbTRecord.h	\
	tsbb/TsbBEvent.h	tsbb/TsbBRecord.h	\
	PscuEvent.h		\
	CalibCalPulse1Event.h	\
	CalibCalPulse2Event.h	\
	CalibTrkBothEvent.h	\
	CalibTrk1Event.h	\
	CalibTrk2Event.h	\
	CalibTofEvent.h		\
	CalibS4Event.h		\
	CalibCalPedEvent.h	\
	Calib1_Ac1Event.h	\
	Calib2_Ac1Event.h	\
	Calib1_Ac2Event.h   	\
	Calib2_Ac2Event.h   	\
	CalibCalEvent.h   	\
	RunHeaderEvent.h	\
	RunTrailerEvent.h	\
	CalibHeaderEvent.h	\
	CalibTrailerEvent.h	\
	InitHeaderEvent.h	\
	InitTrailerEvent.h	\
	EventTrkEvent.h		\
	ForcedFECmdEvent.h	\
	Ac1InitEvent.h		\
	CalInitEvent.h		\
	TrkInitEvent.h		\
	TofInitEvent.h		\
	TrgInitEvent.h		\
	NdInitEvent.h		\
	S4InitEvent.h		\
	Ac2InitEvent.h		\
	CalAlarmEvent.h		\
	Ac1AlarmEvent.h		\
	TrkAlarmEvent.h 	\
	TrgAlarmEvent.h		\
	TofAlarmEvent.h		\
	S4AlarmEvent.h		\
	Ac2AlarmEvent.h		\
	CRC.h			\
	Exception.h		\
	LinkDef.h

$(ROOTEVENTDICT).cpp: ${DICT_HEADER_FILES} 
	echo	$(ROOTCINT) -f $@ -c ${INCLUDES} $^ ;\
	LD_LIBRARY_PATH=$(ROOT_LIB):$(LD_LIBRARY_PATH); $(ROOTCINT) -f $@ -c ${INCLUDES} $^

clean: clean-subdir
	rm -f $(TARGETLIB) ${OBJS} $(OBJDIR)/.*.d $(EXECUTABLES)

clean-subdir: $(EXTDIR)
	for sub_dir in $(EXTDIR) ; do \
		$(MAKE) -C $$sub_dir clean ; \
	done

distclean: distclean-sub distclean-subdir clean
	rm -f $(ROOTEVENTDICT).{cpp,h}

distclean-subdir:
	for sub_dir in $(EXTDIR) ; do \
		$(MAKE) -C $$sub_dir distclean-sub ; \
	done

-include $(DEPEND)


#------------------------------------------------------------------------------
include $(BASEDIR)/PamOffLineSW/Make.def.post
#------------------------------------------------------------------------------
