##################################################################
#
#   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 mdatacheck mbase mraw

#
# Library rules
#
MARS_LIB  = -Llib $(SUBDIRS:%=-l%)
MARS_LIBB = $(SUBDIRS:%=lib%.a)
INCLUDES  = -I. $(SUBDIRS:%=-I%)


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

.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): $(MARS_LIBB) $(PROGRAMS:=.o) $(OBJS) MCint.o
	@echo " Linking $@ ..." 
	$(CXX) $(CXXFLAGS) $@.o $(OBJS) $(MARS_LIB) MCint.o $(ROOTGLIBS) -o $@

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

$(MARS_LIBB):
	@echo " Creating $@:"
	(cd $(@:lib%.a=%); make; cd ..; mv $(@:lib%.a=%)/$@ 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 .."


# @endcode
