# $Id: Makefile,v 1.0 2007/06/01

############################### geant4vmc Makefile ###########################

PACKAGE   = PamVMC_fc


ifeq ($(PLATFORM),)
PLATFORM = $(shell root-config --arch)
endif

TOPDIR  = $(PWD)
BINDIR  = $(TOPDIR)/tmp/tgt_$(PLATFORM)/$(PACKAGE)
LIBDIR  = $(TOPDIR)/lib/tgt_$(PLATFORM)
#BINDIR  = $(G4WORKDIR)/tmp/tgt_$(PLATFORM)/$(PACKAGE)
#LIBDIR  = $(G4WORKDIR)/lib/tgt_$(PLATFORM)

ifeq ($(ROOTSYS),)
ROOT_INCDIR = $(shell root-config --incdir)
ROOT_BINDIR = $(shell root-config --prefix)/bin
ROOT_ETCDIR = $(shell root-config --prefix)/etc/vmc
else
ROOT_INCDIR = $(ROOTSYS)/include
ROOT_BINDIR = $(ROOTSYS)/bin
ROOT_ETCDIR = $(ROOTSYS)/etc/vmc
endif

include $(ROOT_ETCDIR)/Makefile.$(PLATFORM)

############################### Sources #######################################

# Rules
#
include $(ROOT_ETCDIR)/MakeRules

# Dictionary
#
GDICT    := $(BINDIR)/$(PACKAGE)Cint.cxx
GDICTH   := $(GDICT:.cxx=.h)
GDICTO   := $(patsubst %.cxx,%.o,$(GDICT))

# Sources
#
CXXSRC	:= $(wildcard src/*.cxx)
CALSRC  := $(wildcard cal/src/*.cxx)
TRKSRC  := $(wildcard trk/src/*.cxx)
TRKFSRCS  :=$(wildcard trk/src/f77/*.F)
TOFSRC  := $(wildcard tof/src/*.cxx)
ACSRC  := $(wildcard ac/src/*.cxx)
S4SRC  := $(wildcard s4/src/*.cxx)
NDSRC  := $(wildcard nd/src/*.cxx)

 
SRCS	:= $(CXXSRC) $(CALSRC) $(TRKSRC) $(TOFSRC) $(ACSRC) $(S4SRC) $(NDSRC)
FSRCS   := $(TRKFSRCS)


# C++ Headers
#
HDRS    := $(wildcard include/*.h)
HDRS    += $(wildcard cal/include/*.h)
HDRS    += $(wildcard trk/include/*.h)
HDRS    += $(wildcard tof/include/*.h)
HDRS    += $(wildcard ac/include/*.h)
HDRS    += $(wildcard s4/include/*.h)
HDRS    += $(wildcard nd/include/*.h)

HDRS    := $(filter-out include/$(PACKAGE)LinkDef.h,$(HDRS))
HDRS    += include/$(PACKAGE)LinkDef.h

# Objects
#
CXXOBJ	:= $(patsubst %.cxx,$(BINDIR)/%.o,$(SRCS))
FOBJ    := $(patsubst %.F,$(BINDIR)/%.o,$(FSRCS))
OBJS	:= $(CXXOBJ) $(GDICTO) $(FOBJ)

# PAMELA LIBS
#
PAMLIBS := -L${PAM_LIB} -lTrkLevel2  
SHLIBS := ${PAMLIBS}
# Make include list
#
PAMINC :=   -I$(PAM_INC) -I$(PAM_INC)/yoda 
INCDIR  := -Iinclude -I$(TOPDIR) \
           -Ical/include \
           -Itrk/include \
           -Itof/include \
           -Iac/include \
           -Is4/include \
           -Ind/include \
           -I$(G4VMC_DIR)/include \
           -I$(CLHEP_BASE_DIR)/include \
           -Iinclude -I$(G4INCLUDE)

FINCDIR := -Itrk/include/f77
# C++ compilation flags
#
CXXFLAGS := $(CXXOPTS) -I. $(INCDIR) $(PAMINC) -I$(ROOT_INCDIR) ${PAMOPTS}
FFLAGS :=  $(FINCDIR)  -fvxt -fno-automatic -Wno-globals 

DEPINC 		+= -I. -I$(ROOT_INCDIR) $(INCDIR)

############################### Targets #######################################

RM_FILE=$(shell rm -f $(LIBDIR)/resxy_new.root)\
        $(shell rm -f $(LIBDIR)/CalibTrk_00110_000_000.root)

AUXDIR='aux'
CP_FILE=$(shell mkdir -p  ${LIBDIR})\
        $(shell cp -rf ${AUXDIR}/resxy_new.root ${AUXDIR}/CalibTrk_00110_000_000.root ${LIBDIR}/)

SLIBRARY	= $(LIBDIR)/lib$(PACKAGE).$(SL)
ALIBRARY	= $(LIBDIR)/lib$(PACKAGE).a

default:	depend $(SLIBRARY)


$(LIBDIR)/lib$(PACKAGE).$(SL):$(CP_FILE) $(OBJS) $(FOBS) 

$(LIBDIR)/lib$(PACKAGE).a: $(CP_FILE) $(OBJS) $(FOBS)

DICT:=	 	$(GDICT)

$(DICT): 	$(HDRS)

depend:		$(SRCS)  $(FSRCS)

TOCLEAN		= $(BINDIR) $(RM_FILE)
TOCLEANALL	= $(BINDIR) $(LIBDIR) $(RM_FILE)

include $(ROOT_ETCDIR)/MakeMacros


############################### Dependencies ##################################

-include $(BINDIR)/Make-depend
