
cppflags  = $(CFLAGS)

ifeq ($(CMTBIN),OSF1)
cpp           = cxx -g
remote_launch = rsh

else

remote_launch = ssh

ifeq ($(CMTBIN),SunOS)
cpp       = CC
else

ifeq ($(CMTBIN),HP-UX)
cpp       = aCC
else

ifeq ($(CMTBIN),Darwin)
cpp       = c++
else
cpp       = g++
endif

endif

endif

endif

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       = 

application_suffix = .exe
cmtexe    = $(CMTROOT)/$(CMTBIN)/cmt.exe

build_dependencies = test -d $(bin) || mkdir -p $(binshort); test -f $(cmtexe) || cp ../mgr/cmt_dependencies.make $(bin) ; echo 

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
#
#---------------------------------------------------------
hosts       = asc dxplus papou1-fe hp2 aleph hp1 hpplus ccahp atlas04 atlas50
BOOL_hosts  = ccasn
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 : asc lx1 papou1-fe hp2 #virgo-control1
	@gmake done target=$@
LHCB : lxtest hpplus dxplus rsplus
	@gmake done target=$@
Atlas : atlinux atlas50
	@gmake done target=$@
Virgo : ax7 vmpc13a rio0a
	@gmake done target=$@
CCIN2P3 : ccars ccahp ccali ccasn
	@gmake done target=$@

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

$(hosts) : 
	$(remote_launch) $@ "sh -c '(cd $(PACKAGE_ROOT)/mgr; . setup.sh; $(MAKE) --no-print-directory $(MAKEFLAGS))'"

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

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

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

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


CFLAGS = 
clinkflags = 

#---------------------------------------------------------
all :: cmt done
	@echo all ok
	@cd $(bin); /bin/rm -f cmt; /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 OSF1 HP-UX VisualC

doxygen ::
	$(remote_launch) 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

#	html2ps -nu -o ../doc/CMTDoc.ps ../doc/CMTDoc.html
#	ps2pdf ../doc/CMTDoc.ps ../doc/CMTDoc.pdf

docs ::
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/index.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/table.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/intro.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/projectmanagement.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/copyright.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/documents.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/discussion.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/repository.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/download.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/install.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMTDoc.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMTDoc.ps
	${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`; \
	version=`basename $${root}`; \
	tag=$${version} ; \
	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 grafviz java doc

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

demo :: democlean
	@echo "------------------------------------------"; \
	sequence=demo1; \
	location=../demo; \
	echo "Starting general auto test sequence"; \
	echo "  Creating $${location} work area..."; \
	mkdir -p $${location}; \
	cd $${location}; \
	version=`$(cmtexe) version`; \
	echo "  Creating all $${sequence} packages..."; \
	($(cmtexe) run_sequence ${CMTROOT}/src/demo/$${sequence}.cmt | \
	  sed -e "s#$${CMTROOT}#"'$${CMTROOT}'"#" \
	      -e "s#$${version}#"'$${version}'"#" \
	      -e "s#$${CMTCONFIG}#"'$${CMTCONFIG}'"#"; \
	  ) >$${sequence}.txt; \
	echo "  Comparing results with reference output (${CMTROOT}/src/demo/$${sequence}.out) ..."; \
	diff $${sequence}.txt ${CMTROOT}/src/demo/$${sequence}.out; s=$$?; \
	if test $${s} = 0; then \
	  echo "    => no differences"; \
	else \
	  echo "    => errors?"; \
	  cp $${sequence}.txt ${CMTROOT}/src/demo/$${sequence}.out; \
	fi

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


tprivate :: democlean
	@echo "------------------------------------------"; \
	sequence=tprivate; \
	location=../demo; \
	echo "Starting auto test sequence on private uses"; \
	echo "  Creating $${location} work area..."; \
	mkdir -p $${location}; \
	cd $${location}; \
	version=`$(cmtexe) version`; \
	echo "  Creating all $${sequence} packages..."; \
	($(cmtexe) run_sequence ${CMTROOT}/src/demo/$${sequence}.cmt | \
	  sed -e "s#$${CMTROOT}#"'$${CMTROOT}'"#" \
	      -e "s#$${version}#"'$${version}'"#" \
	      -e "s#$${CMTCONFIG}#"'$${CMTCONFIG}'"#"; \
	  ) >$${sequence}.txt; \
	echo "  Comparing results with reference output (${CMTROOT}/src/demo/$${sequence}.out) ..."; \
	diff $${sequence}.txt ${CMTROOT}/src/demo/$${sequence}.out; s=$$?; \
	if test $${s} = 0; then \
	  echo "    => no differences"; \
	else \
	  echo "    => errors?"; \
	  cp $${sequence}.txt ${CMTROOT}/src/demo/$${sequence}.out; \
	fi



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

help ::
	@echo "------------------------------------------------------------"
	@echo "  [all]"
	@echo "      Default target"
	@echo "  "
	@echo "  LAL : asc lx1 papou1-fe hp2 #virgo-control1"
	@echo "  LHCB : lxtest hpplus dxplus rsplus"
	@echo "  Atlas : atlinux atlas50"
	@echo "  Virgo : ax7 vmpc13a rio0a"
	@echo "  CCIN2P3 : ccars ccahp ccali ccasn"
	@echo "      Site-specific targets for building CMT"
	@echo ""
	@echo "  installcvs"
	@echo "  doxygen"
	@echo "      Documentation generation"
	@echo "  docs"
	@echo "      Documentation production and installation"
	@echo "  bintar"
	@echo "      Production and installation of binary tar-balls"
	@echo "  Export"
	@echo "      Installation in the web site"
	@echo ""
	@echo "  democlean"
	@echo "      Cleaning the demo area"
	@echo "  demo"
	@echo "      Run the demo sequence"
	@echo "  tprivate"
	@echo "      Run the demo sequence on private uses"
	@echo "------------------------------------------------------------"
