cppflags  = $(CFLAGS)

cpp       = g++
cppcomp   = $(cpp) -c -I${inc} $(cppflags)
cpplink   = $(cpp)

src       = ../src/
inc       = ../src/
mgr       = ../mgr/
bin       = ../${CMTBIN}/
binshort  = ../${CMTBIN}

cpp_silent =
cpp_echo = @--->
link_silent =
link_echo = @--->

SHELL     = /bin/sh

tag       = 

build_dependencies = ${CMTROOT}/mgr/cmt build dependencies

PACKAGE_ROOT = ${CMTROOT}

all :: dirs
	-@cd $(bin); /bin/rm -f last-rebuild; date >last-rebuild

dirs ::
	@if test ! -d $(bin) ; then mkdir $(binshort) ; fi

#---------------------------------------------------------
#
# A list of some hosts where it is possible to rebuild CMT
#
#---------------------------------------------------------
cxx_hosts   = as7 dxplus
CC_hosts    = papou1-fe
aCC_hosts   = hp2 aleph hp1 hpplus ccahp atlas04
BOOL_hosts  = ccasn atlas50
gmake_hosts = lx1 atlinux lxtest ax7 ccali ccali61 atlas
make_hosts  = virgo-control1 rio0a vmpc38a vmpc13a
zsh_hosts   = ccars rsplus
#---------------------------------------------------------

#---------------------------------------------------------
#
# Re-building CMT
#
#---------------------------------------------------------

done :
	@echo "CMT has been succesfully rebuilt."
	@echo "A mail to Christian Arnault is now being sent to acknowledge"
	@echo "your use of CMT".
	@echo "Congratulations !!!"
	@echo "CMT rebuilt at $(target)(`hostname`) by ${USER} in ${CMTROOT}" | \
	mail arnault@lal.in2p3.fr

###	mailx -s "CMT rebuilt by ${USER} at `hostname`" arnault@lal.in2p3.fr

LAL : as7 lx1 atlas papou1-fe hp2 aleph hp1 virgo-control1
	@gmake done target=$@
LHCB : lxtest hpplus dxplus rsplus
	@gmake done target=$@
Atlas : atlinux atlas50 atlas04
	@gmake done target=$@
Virgo : ax7 vmpc13a rio0a
	@gmake done target=$@
CCIN2P3 : ccars ccahp ccali ccali61 ccasn
	@gmake done target=$@

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

$(cxx_hosts) : 
	rsh $@ "zsh -c '(cd $(PACKAGE_ROOT)/mgr; . setup.sh; $(MAKE) cpp=cxx cppflags=-g $(MAKEFLAGS))'"

$(CC_hosts) : 
	rsh $@ "sh -c '(cd $(PACKAGE_ROOT)/mgr; . setup.sh; $(MAKE) cpp=CC $(MAKEFLAGS))'"

$(aCC_hosts) :
	rsh $@ "zsh -c '(cd $(PACKAGE_ROOT)/mgr; . setup.sh; $(MAKE) cpp=aCC $(MAKEFLAGS))'"

$(BOOL_hosts) :
	rsh $@ "zsh -c '(cd $(PACKAGE_ROOT)/mgr; . setup.sh; $(MAKE) cppflags=-D_BOOL $(MAKEFLAGS))'"

$(gmake_hosts) :
	rsh $@ "sh -c '(cd $(PACKAGE_ROOT)/mgr; . setup.sh; gmake $(MAKEFLAGS))'"

$(zsh_hosts) :
	rsh $@ "zsh -c '(cd $(PACKAGE_ROOT)/mgr; . setup.sh; gmake $(MAKEFLAGS))'"

$(make_hosts) :
	rsh $@ "sh -c '(cd $(PACKAGE_ROOT)/mgr; . setup.sh; make $(MAKEFLAGS))'"
#---------------------------------------------------------


CFLAGS = 
clinkflags = 

#---------------------------------------------------------
all :: cmt done
	@echo all ok
	@cd $(bin); /bin/ln -fs cmt.exe cmt

include cmt.make
#---------------------------------------------------------

#---------------------------------------------------------
# This procedure installs a hook into the commitinfo management file.
# then the 
#---------------------------------------------------------
installcvs :
	cd `echo ${CVSROOT} | cut -f4 -d':'`/CVSROOT;\
	if [ "`grep cmt_buildcvsinfos loginfo`" = "" ] ; then \
	  echo "======== Configuring loginfo in `pwd`>>>>>> "; \
	  chmod u+w loginfo; \
	  echo '.cmtcvsinfos $${CVSROOT}/CVSROOT/cmt_buildcvsinfos2.sh' >> loginfo; \
	  chmod u-w loginfo; \
	else \
	  echo "======== loginfo already configured in `pwd` >>>>>> "; \
	fi; \
	cp ${CMTROOT}/mgr/cmt_buildcvsinfos2.sh .; \
	/bin/rm -rf ../.cmtcvsinfos/*

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

#---------------------------------------------------------
binaries = Linux-i686 LynxOS-PowerPC VisualC alpha hp9000s735 hp9000s780 i386_linux22 sun4u sun4x_57

doxygen ::
	rsh lx1 "(cd `pwd`; source /lal/Doxygen/Linux/setup.csh; cd ../doc; /bin/rm -Rf Doxygen; doxygen)"
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/Doxygen

docs ::
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMT.htm
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMTDoc.html
	html2ps -nu -o ../doc/CMTDoc.ps ../doc/CMTDoc.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMTDoc.ps
	ps2pdf ../doc/CMTDoc.ps ../doc/CMTDoc.pdf
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMTDoc.pdf
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMTFAQ.html
	html2ps -nu -o ../doc/CMTFAQ.ps ../doc/CMTFAQ.html
	ps2pdf ../doc/CMTFAQ.ps ../doc/CMTFAQ.pdf
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMTFAQ.ps
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMTFAQ.pdf

bintar :: #docs #doxygen
	cd ..; root=`pwd`; \
	tag=`cmt version`; \
	tag=v1r8p20010710; \
	version=`basename $${root}`; \
	package=`dirname $${root}`; \
	package=`basename $${package}`; \
	${CMTROOT}/mgr/cmt_export.sh $${package}/ $${root}/doc/CMTDownload.html $${tag}; \
	cd ../../; \
	for branch in $(binaries) ; \
	do \
	  echo $${branch} ; \
	  tarfile=$${package}/$${package}$${version}$${branch}.tar; \
	  tar cf $${tarfile} $${package}/$${version}/$${branch} ; \
	  compress $${tarfile}; \
	  ${CMTROOT}/mgr/cmt_export.sh $${package}/ $${tarfile}.Z $${tag} ; \
	done


Export :: bintar
	${CMTROOT}/mgr/cmt_tar_export.sh CVS mgr src fragments Visual doc

democlean ::
	/bin/rm -rf ../demo/*

demo :: democlean
	mkdir -p ../demo
	cd ../demo; \
	${CMTROOT}/${CMTBIN}/cmt.exe create demoA v1 ${CMTROOT}/demo; \
	${CMTROOT}/${CMTBIN}/cmt.exe create demoB v1 ${CMTROOT}/demo; \
	${CMTROOT}/${CMTBIN}/cmt.exe create demoC v1 ${CMTROOT}/demo; \
	mkdir ${CMTROOT}/demo/demoA/v1/demoA; \
	mkdir ${CMTROOT}/demo/demoA/v1/cmt/fragments; \
	mkdir ${CMTROOT}/demo/demoA/v1/cmt/fragments/nmake; \
	cp ${CMTROOT}/src/demo/demoA/requirements demoA/v1/cmt; \
	cp ${CMTROOT}/src/demo/demoA/init.* demoA/v1/cmt; \
	cp ${CMTROOT}/src/demo/demoA/*.cxx demoA/v1/src; \
	cp ${CMTROOT}/src/demo/demoA/demoA.h demoA/v1/demoA; \
	cp ${CMTROOT}/src/demo/demoA/*.java demoA/v1/src; \
	cp ${CMTROOT}/src/demo/demoA/fragments/rename* demoA/v1/cmt/fragments; \
	cp ${CMTROOT}/src/demo/demoA/fragments/nmake/rename* demoA/v1/cmt/fragments/nmake; \
	cp ${CMTROOT}/src/demo/demoB/requirements demoB/v1/cmt; \
	cp ${CMTROOT}/src/demo/demoB/init.* demoB/v1/cmt; \
	cp ${CMTROOT}/src/demo/demoB/*.cxx demoB/v1/src; \
	cp ${CMTROOT}/src/demo/demoB/*.java demoB/v1/src; \
	cp ${CMTROOT}/src/demo/demoC/requirements demoC/v1/cmt; \
	cp ${CMTROOT}/src/demo/demoC/*.cxx demoC/v1/src
	-cd ${CMTROOT}/demo/demoA/v1/cmt; gmake all_groups check
	-cd ${CMTROOT}/demo/demoB/v1/cmt; gmake all check
	-cd ${CMTROOT}/demo/demoC/v1/cmt; ${CMTROOT}/${CMTBIN}/cmt.exe config; . setup.sh ; gmake all check


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

