#!/bin/sh
#-----------------------------------------------------------------------
#
# VISIT-BUILD-OPEN - Build the visit distributions on the open network.
#
# Author: Eric Brugger
# Date:   October 27, 2000
#
# Usage:
#    visit-build-open -d <distribution>
#
# Modifications:
#   Brad Whitlock, Fri Dec 15 09:51:55 PDT 2006
#   Added --enable-visitmodule for some platforms.
#
#   Hank Childs, Mon Oct 15 09:04:12 PDT 2007
#   Add some print statements for usability.  Also make sure that 
#   /usr/bin/X11 is in the path for yana and prism.  If you are a ksh
#   user, your environment will not get sourced and xmkmf will not be
#   found, leading configure to not find the right X libraries, which 
#   will lead to a compile error.
#
#   Hank Childs, Wed Oct 17 14:28:48 PDT 2007
#   Add support for ksh users on sunspot.  (Default environment
#   inherited by "sh" is not enough to do a compile.)
#
#   Hank Childs, Wed Oct 17 16:25:14 PDT 2007
#   Add a subject line to the status e-mails.  Also workaround problem
#   with quad mailing out.
#
#   Hank Childs, Mon Oct 22 09:25:47 PDT 2007
#   More ksh sunspot fixes.
#
#   Hank Childs, Sat Feb  9 14:18:54 PST 2008
#   Change clearcase_bin to svn_bin.
#
#   Brad Whitlock, Fri Oct 10 15:25:27 PST 2008
#   Added --enable-slivr to some of the Linux targets.
#
#   Brad Whitlock, Tue Dec  2 13:49:50 PST 2008
#   Add --prefix for Linux targets so we can use -rpath for the engine
#   wrapper library. I commented out sunspot since Qt4 does not build
#   there.
#
#-----------------------------------------------------------------------

test=no

user=`whoami`

#
# Set the user e-mail address.
#
emailName=brugger1@llnl.gov
case $user in
   kbonnell)
      emailName=bonnell2@llnl.gov
      ;; 
   brugger)
      emailName=brugger1@llnl.gov
      ;;
   childs)
      emailName=childs3@llnl.gov
      ;;
   mcmiller)
      emailName=miller86@llnl.gov
      ;;
   miller)
      emailName=miller86@llnl.gov
      ;;
   whitlocb)
      emailName=whitlock2@llnl.gov
      ;;
esac

#
# Parse the execute line, providing default values for error checking.
#
hoth=true
up=true
yana=true
alastor=false
xchem=true
davinci=true
ellipse=true

dist=undefined

#
# The loop is executed once for each symbol on the execute line.  This means
# that $1 may be blank for later executions of the loop if any "shift 2"
# commands are executed.  The variable abc is not used in the loop.  
#
for abc
do
   case $1 in
      -none)
         hoth=false
         up=false
         yana=false
         alastor=false
         xchem=false
         davinci=false
         ellipse=false
         shift
         ;;
      -hoth)
         hoth=false
         shift
         ;;
      +hoth)
         hoth=true
         shift
         ;;
      -up)
         up=false
         shift
         ;;
      +up)
         up=true
         shift
         ;;
      -yana)
         yana=false
         shift
         ;;
      +yana)
         yana=true
         shift
         ;;
      -alastor)
         alastor=false
         shift
         ;;
      +alastor)
         alastor=true
         shift
         ;;
      -xchem)
         xchem=false
         shift
         ;;
      +xchem)
         xchem=true
         shift
         ;;
      -davinci)
         davinci=false
         shift
         ;;
      +davinci)
         davinci=true
         shift
         ;;
      -ellipse)
         ellipse=false
         shift
         ;;
      +ellipse)
         ellipse=true
         shift
         ;;
      -d)
         dist=$2
         shift 2
         ;;
   esac
done

#
# Check that the distribution name was provided.
#
if [ $dist = undefined ]
then
   echo "Usage: [-none] [-<machine name>] -d <distribution>"
   echo "Valid machine names:"
   echo "    hoth (B-Div, Linux),"
   echo "    up (LC, AIX),"
   echo "    yana (LC, Linux, x86_64),"
   echo "    alastor (LC, Linux, x86_64),"
   echo "    xchem (HEAF, Linux),"
   echo "    davinci (LBNL, Altix),"
   echo "    ellipse (UChicago, Linux)"
   exit
fi

#
# Check that the distribution exists.
#
distfile=$dist.tar.gz
if [ ! -f $distfile ]
then
   echo "Distribution file doesn't exist."
   exit
fi

#
# Build on hoth.
#
rm -f hoth
cat <<EOF > hoth
#!/bin/sh
if test ! -e /scratch/$user ; then
   mkdir /scratch/$user
fi
if test ! -e /scratch/$user/hoth ; then
   mkdir /scratch/$user/hoth
fi
rm -rf /scratch/$user/hoth/visitbuild
mkdir /scratch/$user/hoth/visitbuild
mv hoth_$dist.tar.gz /scratch/$user/hoth/visitbuild/$dist.tar.gz
cd /scratch/$user/hoth/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/usr/gapps/visit/thirdparty_static/cmake/2.8.0/linux-i686_gcc-3.2/bin/cmake . -DCMAKE_BUILD_TYPE=Release -DVISIT_INSTALL_THIRD_PARTY=ON >> ../../buildlog 2>&1
make -j 4 >> ../../buildlog 2>&1
make -j 4 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-intel.tar.gz ../../visit_llnl\$ver2.linux-intel.tar.gz
/usr/gapps/visit/thirdparty_static/cmake/2.8.0/linux-i686_gcc-3.2/bin/cmake . -DCMAKE_BUILD_TYPE=Release -DVISIT_INSTALL_THIRD_PARTY=OFF >> ../../buildlog 2>&1
make -j 4 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-intel.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on hoth"         > resultlog 2>&1
echo "       ------------------------"        >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/src/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/src/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/src/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/src/plugins/databases/libI* | sed "s/$dist\/src\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail  -s "VisIt build ($dist): hoth" $emailName < resultlog
EOF

if [ $hoth = true ]
then
   if [ $test = no ]
   then
      echo "Building on hoth"
      scp hoth hoth:hoth_buildit
      scp $dist.tar.gz hoth:hoth_$dist.tar.gz
      ssh hoth "chmod 750 hoth_buildit;./hoth_buildit" &
   fi
fi

#
# Build on up, both 32 and 64 bit versions.
#
rm -f up32
cat <<EOF > up32
#!/bin/sh
PATH=/usr/local/bin:\$PATH
if test ! -d /p/gup1/$user ; then
   mkdir /p/gup1/$user
fi
if test ! -d /p/gup1/$user/up32 ; then
   mkdir /p/gup1/$user/up32
fi
rm -rf /p/gup1/$user/up32/visitbuild
mkdir /p/gup1/$user/up32/visitbuild
mv up32_$dist.tar.gz /p/gup1/$user/up32/visitbuild/$dist.tar.gz
cd /p/gup1/$user/up32/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
OBJECT_MODE=32
export OBJECT_MODE
cp config-site/up041_32.cmake config-site/up041.cmake
/usr/gapps/visit/cmake/2.8.0/aix_xlc_32/bin/cmake . -DCMAKE_BUILD_TYPE=Release -DVISIT_INSTALL_THIRD_PARTY=ON >> ../../buildlog 2>&1
gmake -j 3 >> ../../buildlog 2>&1
gmake -j 3 package >> ../../buildlog 2>&1
mv visit\$ver2.ibm-aix-pwr.tar.gz ../../visit_llnl\$ver2.ibm-aix-pwr.tar.gz
/usr/gapps/visit/cmake/2.8.0/aix_xlc_32/bin/cmake . -DCMAKE_BUILD_TYPE=Release -DVISIT_INSTALL_THIRD_PARTY=OFF >> ../../buildlog 2>&1
gmake -j 3 package >> ../../buildlog 2>&1
mv visit\$ver2.ibm-aix-pwr.tar.gz ../..
cd ../..
echo "        build of visit on up"           > resultlog 2>&1
echo "       ----------------------"          >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "            32 bit build"               >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/src/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/src/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/src/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/src/plugins/databases/libI* | sed "s/$dist\/src\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail  -s "VisIt build ($dist): up32" $emailName < resultlog
EOF

rm -f up64
cat <<EOF > up64
#!/bin/sh
PATH=/usr/local/bin:\$PATH
if test ! -d /p/gup1/$user ; then
   mkdir /p/gup1/$user
fi
if test ! -d /p/gup1/$user/up64 ; then
   mkdir /p/gup1/$user/up64
fi
rm -rf /p/gup1/$user/up64/visitbuild
mkdir /p/gup1/$user/up64/visitbuild
mv up64_$dist.tar.gz /p/gup1/$user/up64/visitbuild/$dist.tar.gz
cd /p/gup1/$user/up64/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
OBJECT_MODE=64
export OBJECT_MODE
/usr/gapps/visit/cmake/2.8.0/aix_xlc_64/bin/cmake . -DCMAKE_BUILD_TYPE=Release -DVISIT_INSTALL_THIRD_PARTY=ON >> ../../buildlog 2>&1
gmake -j 3 >> ../../buildlog 2>&1
gmake -j 3 package >> ../../buildlog 2>&1
mv visit\$ver2.ibm-aix-pwr64.tar.gz ../../visit_llnl\$ver2.ibm-aix-pwr64.tar.gz
/usr/gapps/visit/cmake/2.8.0/aix_xlc_64/bin/cmake . -DCMAKE_BUILD_TYPE=Release -DVISIT_INSTALL_THIRD_PARTY=OFF >> ../../buildlog 2>&1
gmake -j 3 package >> ../../buildlog 2>&1
mv visit\$ver2.ibm-aix-pwr64.tar.gz ../..
cd ../..
echo "        build of visit on up"           > resultlog 2>&1
echo "       ----------------------"          >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "            64 bit build"               >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/src/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/src/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/src/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/src/plugins/databases/libI* | sed "s/$dist\/src\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail  -s "VisIt build ($dist): up64" $emailName < resultlog
EOF

if [ $up = true ]
then
   if [ $test = no ]
   then
      echo "Building on up"
      scp up32 up:up32_buildit
      scp up64 up:up64_buildit
      scp $dist.tar.gz up:up32_$dist.tar.gz
      scp $dist.tar.gz up:up64_$dist.tar.gz
      ssh up "chmod 750 up32_buildit;./up32_buildit" &
      ssh up "chmod 750 up64_buildit;./up64_buildit" &
   fi
fi

#
# Build on yana.
#
rm -f yana
cat <<EOF > yana
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/yana ; then
   mkdir /usr/tmp/$user/yana
fi
rm -rf /usr/tmp/$user/yana/visitbuild
mkdir /usr/tmp/$user/yana/visitbuild
mv yana_$dist.tar.gz /usr/tmp/$user/yana/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/yana/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
export PATH=\$PATH:/usr/bin/X11
/usr/gapps/visit/cmake/2.8.0/linux-x86_64_gcc-4.1/bin/cmake . -DCMAKE_BUILD_TYPE=Release -DVISIT_INSTALL_THIRD_PARTY=ON >> ../../buildlog 2>&1
make -j 6 >> ../../buildlog 2>&1
make -j 6 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../../visit_llnl\$ver2.linux-x86_64.tar.gz
/usr/gapps/visit/cmake/2.8.0/linux-x86_64_gcc-4.1/bin/cmake . -DCMAKE_BUILD_TYPE=Release -DVISIT_INSTALL_THIRD_PARTY=OFF >> ../../buildlog 2>&1
make -j 6 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on yana"         > resultlog 2>&1
echo "       ------------------------"        >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/src/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/src/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/src/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/src/plugins/databases/libI* | sed "s/$dist\/src\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail  -s "VisIt build ($dist): yana" $emailName < resultlog
EOF

if [ $yana = true ]
then
   if [ $test = no ]
   then
      echo "Building on yana"
      scp yana yana3:yana_buildit
      scp $dist.tar.gz yana3:yana_$dist.tar.gz
      ssh yana3 "chmod 750 yana_buildit;./yana_buildit" &
   fi
fi

#
# Build on alastor.
#
rm -f alastor
cat <<EOF > alastor
#!/bin/sh
if test ! -d /nfs/tmp2/$user ; then
   mkdir /nfs/tmp2/$user
fi
if test ! -d /nfs/tmp2/$user/alastor ; then
   mkdir /nfs/tmp2/$user/alastor
fi
rm -rf /nfs/tmp2/$user/alastor/visitbuild
mkdir /nfs/tmp2/$user/alastor/visitbuild
mv alastor_$dist.tar.gz /nfs/tmp2/$user/alastor/visitbuild/$dist.tar.gz
cd /nfs/tmp2/$user/alastor/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
export PATH=\$PATH:/usr/bin/X11
ln -s yana1.conf config-site/\`hostname\`.conf
/usr/gapps/visit/cmake/2.8.0/linux-x86_64_gcc-4.1/bin/cmake . -DCMAKE_BUILD_TYPE=Release -DVISIT_INSTALL_THIRD_PARTY=OFF >> ../../buildlog 2>&1
make -j 12 >> ../../buildlog 2>&1
make -j 12 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on alastor"      > resultlog 2>&1
echo "       ---------------------------"     >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/src/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/src/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/src/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/src/plugins/databases/libI* | sed "s/$dist\/src\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail  -s "VisIt build ($dist): alastor" $emailName < resultlog
EOF

if [ $alastor = true ]
then
   if [ $test = no ]
   then
      echo "Building on alastor"
      scp alastor alastor:alastor_buildit
      scp $dist.tar.gz alastor:alastor_$dist.tar.gz
      ssh alastor "chmod 750 alastor_buildit;srun -n 1 -p pdebug --exclusive ./alastor_buildit" &
   fi
fi

#
# Build on xchem.
#
rm -f xchem
cat <<EOF > xchem
#!/bin/sh
PATH=/usr/X11R6/bin:\$PATH
if test ! -d tmp ; then
   mkdir tmp
fi
if test ! -d tmp/$user ; then
   mkdir tmp/$user
fi
if test ! -d tmp/$user/xchem ; then
   mkdir tmp/$user/xchem
fi
rm -rf tmp/$user/xchem/visitbuild
mkdir tmp/$user/xchem/visitbuild
mv xchem_$dist.tar.gz tmp/$user/xchem/visitbuild/$dist.tar.gz
cd tmp/$user/xchem/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/usr/gapps/visit/cmake/2.8.0/linux-x86_64-gcc-4.0.2/bin/cmake . -DCMAKE_BUILD_TYPE=Release >> ../../buildlog 2>&1
make -j 3 >> ../../buildlog 2>&1
make -j 3 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on xchem"        > resultlog 2>&1
echo "       -------------------------"       >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/src/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/src/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/src/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/src/plugins/databases/libI* | sed "s/$dist\/src\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail  -s "VisIt build ($dist): xchem" $emailName < resultlog
EOF

if [ $xchem = true ]
then
   if [ $test = no ]
   then
      echo "Building on xchem"
      scp xchem xchem:xchem_buildit
      scp $dist.tar.gz xchem:xchem_$dist.tar.gz
      ssh xchem "chmod 750 xchem_buildit;./xchem_buildit" &
   fi
fi

#
# Build on davinci.
#
rm -f davinci
cat <<EOF > davinci
#!/bin/sh
if test ! -d tmp ; then
   mkdir tmp
fi
if test ! -d tmp/$user ; then
   mkdir tmp/$user
fi
if test ! -d tmp/$user/davinci; then
   mkdir tmp/$user/davinci
fi
rm -rf tmp/$user/davinci/visitbuild
mkdir tmp/$user/davinci/visitbuild
mv davinci_$dist.tar.gz tmp/$user/davinci/visitbuild/$dist.tar.gz
cd tmp/$user/davinci/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/project/projectdirs/visit/visit_3rdparty/cmake/2.8.0/linux-ia64_gcc-4.1/bin/cmake . -DCMAKE_BUILD_TYPE=Release -DVISIT_INSTALL_THIRD_PARTY=ON >> ../../buildlog 2>&1
make -j 4 >> ../../buildlog 2>&1
make -j 4 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-ia64.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on davinci"      > resultlog 2>&1
echo "       ---------------------------"     >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/src/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/src/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/src/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/src/plugins/databases/libI* | sed "s/$dist\/src\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail  -s "VisIt build ($dist): davinci" $emailName < resultlog
EOF

if [ $davinci = true ]
then
   if [ $test = no ]
   then
      echo "Building on davinci"
      scp davinci davinci.nersc.gov:davinci_buildit
      scp $dist.tar.gz davinci.nersc.gov:davinci_$dist.tar.gz
      ssh davinci.nersc.gov "chmod 750 davinci_buildit;./davinci_buildit" &
   fi
fi

#
# Build on ellipse.
#
rm -f ellipse
cat <<EOF > ellipse
#!/bin/sh
PATH=/soft/intel-c-9.1.042-f-9.1.036-r1/bin:\$PATH
export PATH
LD_LIBRARY_PATH=/soft/intel-c-9.1.042-f-9.1.036-r1/lib:\$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
INTEL_HOME=/soft/intel-c-9.1.042-f-9.1.036-r1
export INTEL_HOME
if test ! -d tmp ; then
   mkdir tmp
fi
if test ! -d tmp/$user ; then
   mkdir tmp/$user
fi
if test ! -d tmp/$user/ellipse; then
   mkdir tmp/$user/ellipse
fi
rm -rf tmp/$user/ellipse/visitbuild
mkdir tmp/$user/ellipse/visitbuild
mv ellipse_$dist.tar.gz tmp/$user/ellipse/visitbuild/$dist.tar.gz
cd tmp/$user/ellipse/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/home/brugger/visit/cmake/2.8.0/linux-i686-gcc-3.4.6/bin/cmake . -DCMAKE_BUILD_TYPE=Release >> ../../buildlog 2>&1
make -j 2 >> ../../buildlog 2>&1
make -j 2 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-intel.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on ellipse"      > resultlog 2>&1
echo "       ---------------------------"     >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/src/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/src/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/src/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/src/plugins/databases/libI* | sed "s/$dist\/src\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail  -s "VisIt build ($dist): ellipse" $emailName < resultlog
EOF

if [ $ellipse = true ]
then
   if [ $test = no ]
   then
      echo "Building on ellipse"
      scp ellipse ellipse.uchicago.edu:ellipse_buildit
      scp $dist.tar.gz ellipse.uchicago.edu:ellipse_$dist.tar.gz
      ssh ellipse.uchicago.edu "chmod 750 ellipse_buildit;./ellipse_buildit" &
   fi
fi

#
# Clean up.
#
if [ $test = no ]
then
   rm -f hoth up32 up64 yana alastor xchem davinci ellipse
fi
