##################################################################
#
# makefile
#
# @file        makefile 
# @title       Simulation of the camera and trigger logic
# @author      J C Gonz\'alez
# @email       gonzalez@mppmu.mpg.de
# @date        Fri Mar 12 11:51:11 MET 1999
#
#_______________________________________________________________
#
# Created: Fri Mar 12 11:51:11 MET 1999
# Author:  Jose Carlos Gonzalez
# Purpose: Makefile for the compilation of the camera program
# Notes:   
#    
#---------------------------------------------------------------
#
# $RCSfile: Makefile,v $
# $Revision: 1.30 $
# $Author: moralejo $ 
# $Date: 2005-02-10 12:09:33 $
#
##################################################################
# @maintitle

# @code

INCLUDEMK = config.mk.${OSTYPE}
include ${INCLUDEMK}

# @endcode

# @code 

# common flags
INCLUDES = -I${INCLUDE}      \
	-I${INCLUDE_COR}  \
	-I${INCLUDE_MC}   \
	-I${INCLUDE_LONS}   \
	-I${INCLUDE_STAR}   \
	-I${INCLUDE_TRIGGER}   \
	-I${INCLUDE_FADC}   \
        -I${INCLUDE_ROOT} \
        -I${INCLUDE_CPLUS} \
	-I${INCLUDE_MARS_MBASE} \
	-I${INCLUDE_MARS_MGEOM} \
	-I${INCLUDE_MARS_MGUI} \
	-I${INCLUDE_MARS_MC} \
	-I${INCLUDE_MARS_MRAW} \
	-I${INCLUDE_MARS_MCALIB} \
	-I${INCLUDE_MARS_MTRIGGER}

RANLIB  = -L${RANLIBDIR} -lranlib

# what is needed for ROOT is inside the config.mk... file


# special flags

osf_FORLIBS = -lUfor -lfor -lutil -lots -lm 
linux_FORLIBS =  -lm -ldl 
generic_FORLIBS = -lm 

FORLIBS = ${${SYSTEM}_FORLIBS}
MARSLIBS = ../../../Mars/libmars.so

# compilation and linking flags

CXXFLAGS  = -D__${SYSTEM}__ $(ROOTCFLAGS) ${INCLUDES} ${OPTIM} ${DEBUG}
CFLAGS    = ${CXXFLAGS}
FFLAGS    = ${CXXFLAGS}
LIBS      = ${RANLIB} ${ROOTLIBS} ${ROOTGLIBS} ${GLIBS} ${MARSLIBS}

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

#.SILENT:

.SUFFIXES: .c .cc .cxx .C .c++ .h .hxx .H .h++ .o .so .f

SRCS = \
	${INCLUDE_MC}/MCEventHeader.cxx \
	${INCLUDE_MC}/MCEventHeader_2.cxx \
	${INCLUDE_MC}/MCCphoton.cxx \
	${INCLUDE_LONS}/MLons.cxx \
	${INCLUDE_STAR}/MStarLight.cxx \
	${INCLUDE_TRIGGER}/MTrigger.cxx \
	${INCLUDE_TRIGGER}/MGTriggerSignal.cxx \
	${INCLUDE_FADC}/MFadc.cxx \
	${INCLUDE_FADC}/MGFadcSignal.cxx \
	creadparam.cxx \
	camera.cxx   

HEADERS = \
	MCEventHeader.hxx \
	MCEventHeader_2.hxx \
	MCCphoton.hxx \
	MLons.hxx \
	MStarLight.hxx \
	MTRigger.hxx \
	MGTriggerSignal.hxx \
	MFadc.hxx \
	MGFadcSignal.hxx \
	lagrange.h \
	atm.h \
	creadparam.h \
	camera.h

OBJS = \
	${INCLUDE_MC}/MCEventHeader.o \
	${INCLUDE_MC}/MCEventHeader_2.o \
	${INCLUDE_MC}/MCCphoton.o \
	${INCLUDE_LONS}/MLons.o \
	${INCLUDE_STAR}/MStarLight.o \
	${INCLUDE_TRIGGER}/MTrigger.o \
	${INCLUDE_TRIGGER}/MGTriggerSignal.o \
	${INCLUDE_FADC}/MFadc.o \
	${INCLUDE_FADC}/MGFadcSignal.o \
	creadparam.o \
	camera.o      

############################################################

all: $(PROGRAM) 
	@echo " Done. "
	@echo " "

$(PROGRAM): $(LIBRARIES) $(OBJS) $(PROGRAMS:=.o) 
	@echo " Linking $@ ..." 
	$(CXX) $(CXXFLAGS) $(OBJS) $(LIBS) -o $@

$(CLEANERS): makefiles
	@echo "Cleaning $(@:.clean=):"
	(cd $(@:.clean=); make clean; cd ..;) 

depend: 
	@makedepend $(SRCS) $(INCLUDES) -fMakefile 2> kk.kk ; cat kk.kk

doc: camera-doc

camera-doc: 
	@echo "Generating documentation for camera . . . "
	$(DOCUM) -latex -o camera.tex \
	camera.cxx camera.h \
	creadparam.cxx creadparam.h \
	moments.cxx moments.h
	latex "\nonstopmode\input{camera.tex}" && \
	makeindex camera && \
	latex "\nonstopmode\input{camera.tex}" && \
	latex "\nonstopmode\input{camera.tex}"
	@echo "Files camera.tex and camera.dvi generated."

.cxx.o:	
	@echo "Compiling " $<
	$(CXX) $(CXXFLAGS) -c $< -o $@

.cc.o:	
	@echo "Compiling "  $<
	$(CXX) $(CXXFLAGS) -c $< -o $@

.c.o:	
	@echo "Compiling " $<
	$(CC) $(CFLAGS) -c $< -o $@

makefiles:
	@cp Makefile.* ${INCLUDE_EVITA}

lclean:
	@echo "Cleanning..."
	@rm -f *.o core 

clean:  $(CLEANERS) rmcint rmobjs
	@echo "Cleanning...done"

mrproper: clean $(MRPROPERS)
	@echo "Mr.Proper in action . . ."
	@rm -f $(PROGRAM)

listsrc:
	@ls -m $(SRCS) $(HEADERS) | sed 's/,//g'

redo: clean all

cflags: 
	@echo $(INCLUDES) $(CXXFLAGS)

#
# The cleaning facility
#

rmcint:	
	@echo " Removing cint-stuff..."
	@rm -f *Cint.*

rmobjs:	
	@echo " Removing object files..."
	@rm -f *.o ../*/*.o

rmcore:	
	@echo " Removing core files..."
	@rm -f core*

rmbin:	
	@echo " Removing binary files..."
	@rm -f $(PROGRAM) lib/$(SOLIB) so_locations

rmbak:
	@echo " Removing backup files..."
	@rm -f *~ kk.kk *.bak

rmbakmac:
	@echo " Removing backup files in macros"
	@rm -f macros/*~

rmhtml:
	@echo " Removing htmldoc-tree"
	@rm -rf htmldoc
# @endcode

# DO NOT DELETE THIS LINE -- make depend depends on it.
