
cppflags  = $(CFLAGS)


cpp = g++ -O2

ifeq ($(CMTBIN),LinuxDebug)
cpp = g++ -g
endif

ifeq ($(CMTBIN),Linux-i686Debug)
cpp = g++ -g
endif

ifeq ($(CMTBIN),LinuxProf)
cpp = g++ -g -pg
endif

ifeq ($(CMTBIN),Linux-i686Prof)
cpp = g++ -g -pg
endif


ifeq ($(CMTBIN),LinuxInsure)
cpp = insure -g
endif

ifeq ($(CMTBIN),OSF1DEB)
cpp           = cxx -g3 -pg
endif

ifeq ($(CMTBIN),OSF1-alpha)
cpp           = cxx
endif

ifeq ($(CMTBIN),SunOS-sun4u)
cpp       = CC
endif

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

ifeq ($(CMTBIN),Darwin)
cpp       = c++ -O2
endif

#ifeq ($(CMTBIN),OSF1)
#remote_launch = rsh
#else
remote_launch = ssh
#endif

ifeq ($(CMTBIN),CYGWIN_NT-5.1-i686)
cpp = g++ -O2 -Wno-deprecated
cpp = g++ -g -Wno-deprecated
endif

ifeq ($(CMTBIN),LynxOS-PowerPC)
cpp = g++
endif

ifeq ($(CMTBIN),AIX-002065204C00)
cpp = g++ -O2 -Wno-deprecated
endif

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

ifeq ($(STATIC),1)
    cpplink   = $(cpp) -static
else
    cpplink   = $(cpp)
endif

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); test -f $(bin)CMT_setup.make || touch $(bin)CMT_setup.make ; echo 

PACKAGE_ROOT = ${CMTROOT}

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

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

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

done : cmt post_build 
	@echo "CMT has been succesfully rebuilt."

CFLAGS = 
clinkflags = 

#---------------------------------------------------------
all :: cmt post_build done
	@cd $(bin); /bin/rm -f cmt; cp cmt.exe cmt
	@echo all ok

cmt_install_action = echo
cmt_uninstall_action = echo
CMTINSTALLAREA = 


include cmt.make

post_build :: cmt cmt_dependencies.make $(bin)/cmt_dependencies.make 
	echo post_build done

cmt_dependencies.make $(bin)/cmt_dependencies.make : $(cmtexe)
	$(cmtexe) -quiet build dependencies cmt -all_sources -no_stamps
	cp $(bin)/cmt_dependencies.make ../mgr
	$(cmtexe) -quiet build dependencies cmt -all_sources

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

#---------------------------------------------------------
# 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
##binaries = $(shell '/usr/bin/find ../ -name cmt.exe')


#---------------------------------------------------------
# Regenerates the Doxygen documentation of CMT
# A priori as it is written it works at LAL only
# The result is also transported to the Web site
#---------------------------------------------------------
doxygen ::
	. /lal/Doxygen/Linux/setup.sh; cd ../doc; /bin/rm -Rf Doxygen; doxygen
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/Doxygen

#---------------------------------------------------------
# Converts CMTDoc.html CMTFAQ.html into pdf and ps
#---------------------------------------------------------
pdf ::
	html2ps -nu -o ../doc/CMTDoc.ps ../doc/CMTDoc.html
	ps2pdf ../doc/CMTDoc.ps ../doc/CMTDoc.pdf
	html2ps -nu -o ../doc/CMTFAQ.ps ../doc/CMTFAQ.html
	ps2pdf ../doc/CMTFAQ.ps ../doc/CMTFAQ.pdf

#python = python
python = /afs/cern.ch/sw/lcg/external/Python/2.3.4/rh73_gcc323/bin/python
#python = /cygdrive/c/Arnault/Python23/python.exe

#---------------------------------------------------------
# Generates the html form of the doc from the XML form
#---------------------------------------------------------
gendoc ::
	@cd ../doc; python gendoc.py CMTDoc.xml > CMTDoc.html
	@echo "CMTDoc.html generated from CMTDoc.xml"


#---------------------------------------------------------
# Transfer the docs into the Web site.
#---------------------------------------------------------
docs ::
	${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
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/ReleaseNotes.html
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/ChangeLog
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/mgr/ChangeLog.php
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMTFAQ.ps
	${CMTROOT}/mgr/cmt_export.sh CMT/ ${CMTROOT}/doc/CMTFAQ.pdf

#        echo '  <tr><td><a href="CMT-'$${version}'-1.i386.rpm">RPM for redhat 7.2</a></td></tr>' >>doc/CMTDownload.html;

#---------------------------------------------------------
# Construct the pacman file from the generic form
#---------------------------------------------------------
pacman ::
	version=`cmt version`; \
	sed -e 's#<version>#'"$${version}"'#g' CMT.pacman >CMT-$${version}.pacman

#---------------------------------------------------------
# Construct the tar balls for the binary kits for all
# existing binaries available in ../*.cmt.exe
# Binary kits are now autonomous (ie they don't require
# the source kit)
#---------------------------------------------------------
bintar ::
	cd ..; root=`pwd`; \
	tag=`cmt version`; \
	version=`basename $${root}`; \
	tag=$${version} ; \
	cat doc/CMTDownload1.html >| doc/CMTDownload.html; \
        echo '  <tr><td><a href="CMT'$${version}'.tar.gz">Source kit</a> </td></tr>' >> doc/CMTDownload.html; \
	binaries=`/usr/bin/find ./ -name cmt.exe | sed -e 's#[.]/##' -e 's#/.*##'`; \
        for f in `echo $${binaries}`; do \
          echo '  <tr><td><a href="CMT'$${version}$${f}'.tar.gz">'$${f}'</a> </td></tr>' >> doc/CMTDownload.html; \
        done; \
	cat doc/CMTDownload2.html >> doc/CMTDownload.html; \
	${CMTROOT}/mgr/cmt_export.sh CMT/ $${root}/doc/CMTDownload.html $${tag}; \
	if test -d rpm; then \
	  ${CMTROOT}/mgr/cmt_export.sh CMT/ $${root}/rpm/CMT-$${version}-1.i386.rpm $${tag}; \
	fi; \
	cd ../../; \
	for branch in `echo $${binaries}` ; \
	do \
	  if test $${branch} = VisualC; then \
	    /bin/rm -rf CMT/$${version}/$${branch}/cmt ; \
	  else \
	    /bin/rm -rf CMT/$${version}/$${branch}/*.o ; \
	    ln -s cmt.exe CMT/$${version}/$${branch}/cmt ; \
	  fi ; \
	  echo $${branch} ; \
	  tarfile=CMT/CMT$${version}$${branch}.tar; \
	  tar cf $${tarfile} CMT/$${version}/mgr CMT/$${version}/src CMT/$${version}/$${branch} ; \
	  gzip $${tarfile}; \
	  ${CMTROOT}/mgr/cmt_export.sh CMT/ $${tarfile}.gz $${tag} ; \
	done


#----------------------------------------------------------
#
#  Building an RPM for CMT.
#
#   reinstallation is done by:
#
#  rpm -Uvh --relocate /CMT=/newdir/CMT CMT-${version}-1.i386.rpm
#
#----------------------------------------------------------
rpm ::
	version=`$(cmtexe) -quiet version`; \
	tempdir=/tmp/CMT; \
	rm -rf $${tempdir}; \
	for f in BUILD RPMS SOURCES SPECS SRPMS ; do \
	  mkdir -p $${tempdir}/$${f}; \
	done; \
	(cd ../; tar cf $${tempdir}/SOURCES/CMT$${version}.tar --exclude mgr src source); \
	gzip $${tempdir}/SOURCES/CMT$${version}.tar; \
	if test ! -d ../rpm; then mkdir -p ../rpm; fi; \
	rpmbuild -ba --define "_topdir $${tempdir}" --define "_version $${version}" CMT.spec; \
	cp $${tempdir}/RPMS/i386/CMT-$${version}-1.i386.rpm ../rpm ; \
	cp $${tempdir}/SRPMS/CMT-$${version}-1.src.rpm ../rpm ; \
	rm -r $${tempdir}

#
#        cp CMT.spec $${tempdir}; \
#        find ../fragments ../mgr ../src ! -path '*/CVS*' ! -name '*~' ! -type d | \
#          sed -e 's#[.][.]#%{prefix}/%{version}#' >>$${tempdir}/CMT.spec ; \
#


#----------------------------------------------------------
# Construct a source kit
#----------------------------------------------------------
srctar ::
	${CMTROOT}/mgr/cmt_tar_export.sh source mgr src Visual java doc


#----------------------------------------------------------
# Construct the kits
#----------------------------------------------------------
Export :: docs srctar bintar
	@echo Export done

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

demo_location = ../demo
demo_sequence = demo1

#----------------------------------------------------------
# Run the autotest sequence
#----------------------------------------------------------
demo :: democlean
	@echo "------------------------------------------"
	@echo "Starting general auto test sequence"
	@echo "  Creating $(demo_location) work area..."
	@mkdir -p $(demo_location)
	@echo "  Creating all $(demo_sequence) packages..."
	cd $(demo_location); \
	version=`$(cmtexe) -quiet version`; \
	($(cmtexe) -quiet run_sequence ${CMTROOT}/src/demo/$(demo_sequence).cmt | \
	  sed -e "s#$${CMTROOT}#"'$${CMTROOT}'"#" \
	      -e "s#$${version}#"'$${version}'"#" \
	      -e "s#$${CMTCONFIG}#"'$${CMTCONFIG}'"#"; \
	  ) >$(demo_sequence).txt
	@echo "  Comparing results with reference output (${CMTROOT}/src/demo/$(demo_sequence).out) ..."
	@cd $(demo_location); \
	diff $(demo_sequence).txt ${CMTROOT}/src/demo/$(demo_sequence).out; s=$$?; \
	if test $${s} = 0; then \
	  echo "    => no differences"; \
	else \
	  echo "    => errors?"; \
	  cp $(demo_sequence).txt ${CMTROOT}/src/demo/$(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) -quiet version`; \
	echo "  Creating all $${sequence} packages..."; \
	($(cmtexe) -quiet 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]      : Default target"
	@echo "  "
	@echo "  installcvs : "
	@echo "  doxygen    : Documentation generation"
	@echo "  docs       : Documentation production and installation"
	@echo "  pdf        : Convert html docs into pdf and ps"
	@echo "  gendoc     : Convert xml doc into html"
	@echo "  srctar     : Production and installation of source tar-ball"
	@echo "                (include Linux binary directory)"
	@echo "  bintar     : Production and installation of binary tar-balls"
	@echo "  rpm        : Production of the RPM"
	@echo "  Export     : Installation in the web site"
	@echo "  democlean  : Cleaning the demo area"
	@echo "  demo       : Run the demo sequence on private uses"
	@echo "      (Site-specific targets for building CMT)"
	@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 "------------------------------------------------------------"

