##################################################################
#
#   makefile
# 
#   for the MARS software
#
##################################################################
# @maintitle

# @code

#
#  please change all system depend values in the 
#  config.mk.${OSTYPE} file 
#
#
include Makefile.conf.$(OSTYPE)
include Makefile.conf.general

#

PROGRAMS = merpp readraw mars
SOLIB    = mars.so
CINT     = M

#
#  connect the include files defined in the config.mk file
#
#    WARNING: the result (whether the linkage works or not) depends on the
#             order of the libraries. It seems, that the most base library
#             must be the last one
#

#
#  ----->>>   mars libraries
#
SUBDIRS = mgui manalysis meventdisp mdatacheck mmontecarlo mbase mraw mmc

LIBRARIES = $(SUBDIRS:=.a)

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

.SUFFIXES: .c .cc .h .o 

SRCFILES = 

SRCS    = $(SRCFILES)
HEADERS = $(SRCFILES:.cc=.h)
OBJS    = $(SRCFILES:.cc=.o) 

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

all: rmlib $(PROGRAMS) $(SOLIB)

# Use $(CXX) -v ... for a more verbose output
$(PROGRAMS): $(LIBRARIES) $(OBJS) $(HEADERS) MCint.o $(PROGRAMS:=.o) 
	@echo " Linking $@ ..." 
	$(CXX) $(CXXFLAGS) $@.o $(OBJS) $(MARS_LIB) MCint.o $(ROOTGLIBS) -o $@

$(SOLIB): $(LIBRARIES) $(OBJS) $(HEADERS) MCint.o
	@echo " Linking $(SOLIB) ..."
	$(CXX) -shared $(CXXFLAGS) $(SUBDIRS:=/*.o) $(ROOTGLIBS) -o $@
	mv mars.so lib

$(LIBRARIES):
	@echo " "  
	@echo " Creating lib$@:"
	(cd $*; make; cd ..; mv $*/$@ lib/lib$@) 

dox:
	@echo " Creating html documentation:"
	root -b -q dohtml.C

include Makefile.rules

clean:	rmlib rmcint rmobjs rmcore rmbin

mrproper:	clean rmbak
	@rm -f macros/*~
	@rm -rf htmldoc
	@echo "cd mbase"
	@cd mbase; make mrproper; cd ..
	@echo "cd .."
	@echo "cd mraw"
	@cd mraw; make mrproper; cd ..
	@echo "cd .."
	@echo "cd mgui"
	@cd mgui; make mrproper; cd ..
	@echo "cd .."
	@echo "cd mdatacheck"
	@cd mdatacheck; make mrproper; cd ..
	@echo "cd .."
	@echo "cd mmc"
	@cd mmc; make mrproper; cd ..
	@echo "cd .."
	@echo "cd meventdisp"
	@cd meventdisp; make mrproper; cd ..
	@echo "cd .."
	@echo "cd manalysis"
	@cd manalysis; make mrproper; cd ..
	@echo "cd .."
	@echo "cd mmontecarlo"
	@cd mmontecarlo; make mrproper; cd ..
	@echo "cd .."

tar:	mrproper
	@echo "Making tar-file"
	@tar -cvf ../mars.tar *
	@gzip -9 ../mars.tar

# @endcode
