##################################################################
#
#   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 = cosy starg
SOLIB    = 
CINT     = M
INCLUDES = -I. -Imain  -Ibase -Icandrv -Iincl -Igui -Ivideodev -Icatalog
LIBS     = -lpng -lz -L/usr/X11R6/lib -lpthread

#
#  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 = \
        main     \
        gui      \
        candrv   \
        catalog  \
	devdrv   \
        videodev \
	base     \
        slalib

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
#
# We could link mars.so instead of all libraries. This would need
# some MBs less space on the HD. But this means, that the Shared
# Library Path in your system must be set properly to be able to start
# 'mars'
#
$(PROGRAMS): $(LIBRARIES) $(OBJS) $(HEADERS) $(PROGRAMS:=.o) 
	@echo " Linking $@ ..." 
	$(CXX) $(CXXFLAGS) $(LIBS) $@.o $(OBJS) $(MARS_LIB) $(ROOTGLIBS) -o $@

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

$(LIBRARIES):
	@echo " "  
	@echo " Creating lib$@:"
	(cd $*; make -f Makefile; 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 base"
	@cd base; make mrproper; cd ..
	@echo "cd .."
	@echo "cd candrv"
	@cd candrv; make mrproper; cd ..
	@echo "cd .."
	@echo "cd devdrv"
	@cd devdrv; make mrproper; cd ..
	@echo "cd .."
	@echo "cd gui"
	@cd gui; make mrproper; cd ..
	@echo "cd .."
	@echo "cd videodev"
	@cd videodev; make mrproper; cd ..
	@echo "cd .."
	@echo "cd catalog"
	@cd catalog; make mrproper; cd ..
	@echo "cd .."
	@echo "cd main"
	@cd main; make mrproper; cd ..
	@echo "cd .."

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

# @endcode
