#!/bin/csh -f

#####################
#
# script to build ADDtarball for validation of calibrations
#
# TODO: 
#       - remove explicit cvs checkouts
#	
#e.g.:./buildCalibAddTarball 6.1.6 6.1.4 top_614_p18 top_614_p18
#
# author: lysak@fnal.gov
#####################

set relversionTOF = $1
set relversionTop = $2
set tagname = $3
set relname = $4


unsetenv USESHLIBS

###########
#
# Build TOF and ValidationExe
# 
##########
source ~cdfsoft/cdf2.cshrc
setup cdfsoft2 $relversionTOF
newrel -t $relversionTOF ${relname}Tof
cd ${relname}Tof
addpkg TofValidation
gmake TofValidation.all 
#gmake TofValidation.all USESHLIBS=1 

addpkg Production
#just for now since these files are only in head version 
cvs co -r HEAD Production/val/dqm_CalibValidation.tcl
cvs co -r HEAD Production/calib/topevent_datalocal_val.tcl
gmake Production._val  
cd ..
unsetup cdfsoft2 $relversionTOF

###########
#
# Build TopFind
# 
##########
source ~cdfsoft/cdf2.cshrc
setup cdfsoft2 $relversionTop
# do not use maxopt
srt_setup -a SRT_QUAL=default
# do not use shared object libs in exe
unsetenv USESHLIBS
newrel -t $relversionTop top
cd top
cvs co -r $tagname TopMods/test/buildRelease.csh
cp TopMods/test/buildRelease.csh .
rmpkg -f TopMods
./buildRelease.csh $relversionTop $tagname $relname  >& build_00.log 
cd ..

###########
#
# make tarball
# 
##########
mkdir CalibAddTarball
cd CalibAddTarball
tar xzvf ../top/tarball_${relname}.tgz
#add TOF and DQM stuff
ln -s $PWD/../${relname}Tof/bin/{$BFARCH}/tofValNt       ./bin/tofValNt
ln -s $PWD/../${relname}Tof/bin/{$BFARCH}/ValidationExe  ./bin/ValidationExe 
ln -s $PWD/../${relname}Tof/Production/val/dqm_CalibValidation.tcl       ./tcl/dqm_CalibValidation.tcl
ln -s $PWD/../${relname}Tof/Production/calib/topevent_datalocal_val.tcl  ./tcl/topevent_datalocal_val.tcl
cd bin/
strip *
cd ../

#make tarball
tar czvhf ../CalibAddTarball_{$relname}.tgz ./

cd ..

echo "DONE"
