#!/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.
#
#   Brad Whitlock, Fri May 14 10:23:41 PDT 2010
#   I removed double builds and made the the packages always include
#   the 3rd party libs since the size difference isn't worth the
#   extra build time IMHO.
#
#   Cyrus Harrison, Thu Oct 14 09:59:13 PDT 2010
#   Added cyrush@llnl.gov to the email list & fixed problem with
#   creating proper config-site.cmake on alastor.
#
#   Eric Brugger, Fri Nov  5 15:21:42 PDT 2010
#   I replaced yana with aztec.
#
#   Eric Brugger, Fri Nov  5 16:06:28 PDT 2010
#   I removed up.
#
#   Cyrus Harrison, Tue Jan 11 11:42:58 PST 2011
#   Pass types on command line for cmake vars:
#      CMAKE_BUILD_TYPE & VISIT_THIRD_PARTY_INSTALL
#
#   Eric Brugger, Mon May 16 14:51:39 PDT 2011
#   I added glory and redsky.
#
#   Eric Brugger, Fri Jun 10 13:24:20 PDT 2011
#   I added -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON to the cmake command
#   for ellipse.
#
#   Eric Brugger, Fri Aug  5 09:48:13 PDT 2011
#   I added kickit.
#
#   Eric Brugger, Tue Sep  6 13:58:32 PDT 2011
#   I added rzzeus.
#
#   Eric Brugger, Mon Jan 23 11:59:40 PST 2012
#   I added sidious.
#
#   Eric Brugger, Wed Feb 29 12:15:34 PST 2012
#   I added ubuntu1104_64.
#
#   Eric Brugger, Thu Mar  1 07:57:45 PST 2012
#   I modified the builds on hoth and sidious to use the serial config
#   site files.
#
#   Eric Brugger, Wed May  2 08:45:05 PDT 2012
#   I removed ellipse and xchem.  I modified hoth since it is now an x86_64
#   rhel6 system instead of an x86 rhel3 system.  I updated the e-mail
#   addresses.
#
#   Eric Brugger, Wed Jun 13 08:38:15 PDT 2012
#   I added atlas and rzthriller.
#
#   Eric Brugger, Thu Jun 21 16:17:04 PDT 2012
#   I modified many of the builds to use cmake 2.8.8.
#
#   Eric Brugger, Wed Jun 27 11:40:14 PDT 2012
#   I deleted alastor.
#
#   Eric Brugger, Mon Jul 30 10:13:05 PDT 2012
#   I replaced atlas with prism.
#
#   Eric Brugger, Wed Sep 26 17:09:04 PDT 2012
#   I deleted prism.
#
#   Eric Brugger, Wed Nov 14 09:15:07 PST 2012
#   I deleted hoth.
#
#   Eric Brugger, Wed Nov 14 14:22:16 PST 2012
#   I made the sidious build off by default. I modified the kickit build
#   since it is now a linux-x86_64 system instead of a linux-intel system.
#
#   Eric Brugger, Wed Nov 14 15:53:56 PST 2012
#   I modified the carver build to point to the new cmake.
#
#   Eric Brugger, Wed Nov 28 08:38:09 PST 2012
#   I modified the ubuntu1104_64 build to point to the new cmake.
#
#   Brad Whitlock, Fri May 31 10:21:17 PDT 2013
#   Replace "carver" with "carver". Add build for rzuseq.
#
#   Eric Brugger, Tue Oct 22 11:05:47 PDT 2013
#   I removed rzthriller. I modified many of the builds to use cmake
#   2.8.10.2.
#
#   Eric Brugger, Fri Aug 29 09:51:18 PDT 2014
#   I modified the cmake execute line to build the paraDIS reader to
#   several of the LLNL builds.
#
#   Eric Brugger, Wed Dec 10 13:26:12 PST 2014
#   I added ubuntu1404_64.
#
#   Eric Brugger, Thu Feb 19 09:05:16 PST 2015
#   I removed redsky. I modified many of the builds to use cmake 3.0.2.
#
#   Kathleen Biagas, Thu May  7 09:33:43 PDT 2015
#   Added build for vulcan (copied from rzuseq).
#
#   Eric Brugger, Fri Sep 25 09:04:35 PDT 2015
#   I removed sidious.
#
#   Eric Brugger, Tue Nov 22 16:07:04 PST 2016
#   I added quartz.
#
#   Eric Brugger, Mon Jan  9 13:46:38 PST 2017
#   I replaced aztec with surface.
#
#   Eric Brugger, Tue Feb  7 08:58:27 PST 2017
#   I added rztrona.
#
#-----------------------------------------------------------------------

test=no

user=`whoami`

#
# Set the user e-mail address.
#
emailName=brugger1@llnl.gov
case $user in
   biagas2)
      emailName=biagas2@llnl.gov
      ;; 
   kbonnell)
      emailName=biagas2@llnl.gov
      ;; 
   brugger1)
      emailName=brugger1@llnl.gov
      ;;
   brugger)
      emailName=brugger1@llnl.gov
      ;;
   harrison37)
      emailName=cyrush@llnl.gov
      ;;
   cyrush)
      emailName=cyrush@llnl.gov
      ;;
   mcmiller)
      emailName=miller86@llnl.gov
      ;;
   miller)
      emailName=miller86@llnl.gov
      ;;
esac

#
# Parse the execute line, providing default values for error checking.
#
kickit=true
ubuntu1104_64=false
ubuntu1404_64=false
surface=true
quartz=true
rztrona=true
rzzeus=true
rzuseq=false
carver=true
glory=false
vulcan=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)
         kickit=false
         ubuntu1104_64=false
         ubuntu1404_64=false
         surface=false
         quartz=false
         rztrona=false
         rzzeus=false
         rzuseq=false
         carver=false
         glory=false
         vulcan=false
         shift
         ;;
      -kickit)
         kickit=false
         shift
         ;;
      +kickit)
         kickit=true
         shift
         ;;
      -ubuntu1104_64)
         ubuntu1104_64=false
         shift
         ;;
      +ubuntu1104_64)
         ubuntu1104_64=true
         shift
         ;;
      -ubuntu1404_64)
         ubuntu1404_64=false
         shift
         ;;
      +ubuntu1404_64)
         ubuntu1404_64=true
         shift
         ;;
      -surface)
         surface=false
         shift
         ;;
      +surface)
         surface=true
         shift
         ;;
      -quartz)
         quartz=false
         shift
         ;;
      +quartz)
         quartz=true
         shift
         ;;
      -rztrona)
         rztrona=false
         shift
         ;;
      +rztrona)
         rztrona=true
         shift
         ;;
      -rzzeus)
         rzzeus=false
         shift
         ;;
      +rzzeus)
         rzzeus=true
         shift
         ;;
      -rzuseq)
         rzuseq=false
         shift
         ;;
      +rzuseq)
         rzuseq=true
         shift
         ;;
      -carver)
         carver=false
         shift
         ;;
      +carver)
         carver=true
         shift
         ;;
      -glory)
         glory=false
         shift
         ;;
      +glory)
         glory=true
         shift
         ;;
      -vulcan)
         vulcan=false
         shift
         ;;
      +vulcan)
         vulcan=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 "    kickit (B-Div, Linux, x86_64),"
   echo "    ubuntu1104_64(B-Div, Linux, x86_64),"
   echo "    ubuntu1404_64(B-Div, Linux, x86_64),"
   echo "    surface (LC, Linux, x86_64),"
   echo "    quartz (LC, Linux, x86_64),"
   echo "    rztrona (LC, Linux, x86_64),"
   echo "    rzzeus (LC, Linux, x86_64),"
   echo "    rzuesq (LC, Linux, ppc64-BG/Q),"
   echo "    carver (LBNL, Linux, x86_64),"
   echo "    glory (Sandia, 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 kickit.
#
rm -f kickit
cat <<EOF > kickit
#!/bin/sh
if test ! -e /scratch/$user ; then
   mkdir /scratch/$user
fi
if test ! -e /scratch/$user/kickit ; then
   mkdir /scratch/$user/kickit
fi
rm -rf /scratch/$user/kickit/visitbuild
mkdir /scratch/$user/kickit/visitbuild
mv kickit_$dist.tar.gz /scratch/$user/kickit/visitbuild/$dist.tar.gz
cd /scratch/$user/kickit/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_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.8/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON -DVISIT_ENABLE_XDB:BOOL=ON -DVISIT_PARADIS:BOOL=ON >> ../../buildlog 2>&1
make -j 4 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on kickit"       > 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
rm -rf $dist
gunzip -c $dist.tar.gz | tar xvf - >> buildlog 2>&1
cd $dist/src
/usr/gapps/visit/thirdparty_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.8/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON -DVISIT_ENABLE_XDB:BOOL=ON -DVISIT_PARADIS:BOOL=ON -DVISIT_MESA_DIR="/usr/gapps/visit/thirdparty_shared/2.12.0/mesa/7.10.2/linux-x86_64_gcc-4.8" >> ../../buildlog 2>&1
make -j 4 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../../visit\$ver2.linux-x86_64-wmesa.tar.gz
cd ../..
echo ""                                       >> resultlog 2>&1
echo "        build of visit on kickit"       >> 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
EOF

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

#
# Build on ubuntu1104_64.
#
rm -f ubuntu1104_64
cat <<EOF > ubuntu1104_64
#!/bin/sh
if test ! -e /home/visit/ubuntu1104_64; then
   mkdir /home/visit/ubuntu1104_64
fi
rm -rf /home/visit/ubuntu1104_64/visitbuild
mkdir /home/visit/ubuntu1104_64/visitbuild
mv ubuntu1104_64_$dist.tar.gz /home/visit/ubuntu1104_64/visitbuild/$dist.tar.gz
cd /home/visit/ubuntu1104_64/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/home/visit/visit/thirdparty_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.5/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON >> ../../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 ubuntu1104_64"    > 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
rm -rf $dist
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
/home/visit/visit/thirdparty_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.5/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON -DVISIT_MESA_DIR="/home/visit/visit/thirdparty_shared/2.12.0/mesa/7.10.2/linux-x86_64_gcc-4.5" >> ../../buildlog 2>&1
make -j 3 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../../visit\$ver2.linux-x86_64-wmesa.tar.gz
cd ../..
echo ""                                       >> resultlog 2>&1
echo "     build of visit on ubuntu1104_64"   >> 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
EOF

if [ $ubuntu1104_64 = true ]
then
   if [ $test = no ]
   then
      echo "Building on ubuntu1104_64"
      cp ubuntu1104_64 ubuntu1104_64_buildit
      cp $dist.tar.gz ubuntu1104_64_$dist.tar.gz
      chmod 750 ubuntu1104_64_buildit;./ubuntu1104_64_buildit &
   fi
fi

#
# Build on ubuntu1404_64.
#
rm -f ubuntu1404_64
cat <<EOF > ubuntu1404_64
#!/bin/sh
if test ! -e /home/brugger1/ubuntu1404_64; then
   mkdir /home/brugger1/ubuntu1404_64
fi
rm -rf /home/brugger1/ubuntu1404_64/visitbuild
mkdir /home/brugger1/ubuntu1404_64/visitbuild
mv ubuntu1404_64_$dist.tar.gz /home/brugger1/ubuntu1404_64/visitbuild/$dist.tar.gz
cd /home/brugger1/ubuntu1404_64/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/home/brugger1/visit/thirdparty_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.8/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON >> ../../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 ubuntu1404_64"    > 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
rm -rf $dist
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
/home/brugger1/visit/thirdparty_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.8/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON -DVISIT_MESA_DIR="/home/brugger1/visit/thirdparty_shared/2.12.0/mesa/7.10.2/linux-x86_64_gcc-4.8" >> ../../buildlog 2>&1
make -j 3 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../../visit\$ver2.linux-x86_64-wmesa.tar.gz
cd ../..
echo ""                                       >> resultlog 2>&1
echo "     build of visit on ubuntu1404_64"   >> 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
EOF

if [ $ubuntu1404_64 = true ]
then
   if [ $test = no ]
   then
      echo "Building on ubuntu1404_64"
      cp ubuntu1404_64 ubuntu1404_64_buildit
      cp $dist.tar.gz ubuntu1404_64_$dist.tar.gz
      chmod 750 ubuntu1404_64_buildit;./ubuntu1404_64_buildit &
   fi
fi

#
# Build on surface.
#
rm -f surface
cat <<EOF > surface
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/surface ; then
   mkdir /usr/tmp/$user/surface
fi
rm -rf /usr/tmp/$user/surface/visitbuild
mkdir /usr/tmp/$user/surface/visitbuild
mv surface_$dist.tar.gz /usr/tmp/$user/surface/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/surface/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/thirdparty_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.4/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON -DVISIT_PARADIS:BOOL=ON >> ../../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 surface"      > 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): surface" $emailName < resultlog
EOF

if [ $surface = true ]
then
   if [ $test = no ]
   then
      echo "Building on surface"
      scp surface surface:surface_buildit
      scp $dist.tar.gz surface:surface_$dist.tar.gz
      ssh surface86 "chmod 750 surface_buildit;./surface_buildit" &
   fi
fi

#
# Build on quartz.
#
rm -f quartz
cat <<EOF > quartz
#!/bin/sh
XLOCALEDIR=/usr/lib/X11/locale
PATH=/usr/bin/X11:\$PATH
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/quartz ; then
   mkdir /usr/tmp/$user/quartz
fi
rm -rf /usr/tmp/$user/quartz/visitbuild
mkdir /usr/tmp/$user/quartz/visitbuild
mv quartz_$dist.tar.gz /usr/tmp/$user/quartz/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/quartz/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/usr/workspace/wsa/visit/visit/thirdparty_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.9/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON -DVISIT_PARADIS:BOOL=ON >> ../../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 quartz"       > 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
EOF

if [ $quartz = true ]
then
   if [ $test = no ]
   then
      echo "Building on quartz"
      scp quartz quartz386:quartz_buildit
      scp $dist.tar.gz quartz386:quartz_$dist.tar.gz
      ssh quartz386 "chmod 750 quartz_buildit;./quartz_buildit" &
   fi
fi

#
# Build on rztrona.
#
rm -f rztrona
cat <<EOF > rztrona
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/rztrona ; then
   mkdir /usr/tmp/$user/rztrona
fi
rm -rf /usr/tmp/$user/rztrona/visitbuild
mkdir /usr/tmp/$user/rztrona/visitbuild
mv rztrona_$dist.tar.gz /usr/tmp/$user/rztrona/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/rztrona/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/workspace/wsrzc/visit/visit/thirdparty_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.9/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON -DVISIT_PARADIS:BOOL=ON >> ../../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 rztrona"      > 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): rztrona" $emailName < resultlog
EOF

if [ $rztrona = true ]
then
   if [ $test = no ]
   then
      echo "Building on rztrona"
      scp rztrona rztrona:rztrona_buildit
      scp $dist.tar.gz rztrona:rztrona_$dist.tar.gz
      ssh rztrona5 "chmod 750 rztrona_buildit;./rztrona_buildit" &
   fi
fi

#
# Build on rzzeus.
#
rm -f rzzeus
cat <<EOF > rzzeus
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/rzzeus ; then
   mkdir /usr/tmp/$user/rzzeus
fi
rm -rf /usr/tmp/$user/rzzeus/visitbuild
mkdir /usr/tmp/$user/rzzeus/visitbuild
mv rzzeus_$dist.tar.gz /usr/tmp/$user/rzzeus/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/rzzeus/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/thirdparty_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.4/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON -DVISIT_PARADIS:BOOL=ON >> ../../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 rzzeus"       > 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): rzzeus" $emailName < resultlog
EOF

if [ $rzzeus = true ]
then
   if [ $test = no ]
   then
      echo "Building on rzzeus"
      scp rzzeus rzzeus:rzzeus_buildit
      scp $dist.tar.gz rzzeus:rzzeus_$dist.tar.gz
      ssh rzzeus286 "chmod 750 rzzeus_buildit;./rzzeus_buildit" &
   fi
fi

#
# Build on rzuseq.
#
rm -f rzuseq
cat <<EOF > rzuseq
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/rzuseq ; then
   mkdir /usr/tmp/$user/rzuseq
fi
rm -rf /usr/tmp/$user/rzuseq/visitbuild
mkdir /usr/tmp/$user/rzuseq/visitbuild
mv rzuseq_$dist.tar.gz /usr/tmp/$user/rzuseq/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/rzuseq/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
cd ..
# **NOTE** We do 2 in-source builds because of a weird problem with cmake
# Make a copy of src called login_build
cp -R src login_build
# Rename src to compute_build
mv src compute_build
# Rename the data directory since the data programs won't run.
mv data .data
# install dir
mkdir visit\${ver2}.linux-ppc64
bgqinstdir=\`pwd\`/visit\${ver2}.linux-ppc64
# Build for compute node, engine-only version
cd compute_build
/usr/gapps/visit/thirdparty_static/2.12.0/cmake/3.0.2/linux-ppc64_gcc-4.4_BGQ/bin/cmake -DVISIT_CONFIG_SITE:PATH=config-site/rzuseqlac2-compute.cmake -DVISIT_ENGINE_ONLY:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=\$bgqinstdir -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON . >> ../../buildlog 2>&1
sh svn_bin/filter_link_commands_BGQ.sh >> ../../buildlog 2>&1
make install >> ../../buildlog 2>&1
cd ..
# Restore data directory
mv .data data
# Build for login node, server-components-only version
cd login_build
/usr/gapps/visit/thirdparty_static/2.12.0/cmake/3.0.2/linux-ppc64_gcc-4.4/bin/cmake -DVISIT_CONFIG_SITE:PATH=config-site/rzuseqlac2-login.cmake -DVISIT_SERVER_COMPONENTS_ONLY:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=\$bgqinstdir -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON . >> ../../buildlog 2>&1
make install >> ../../buildlog 2>&1
cd ..
# Now, tar up the common install directory.
tar zcf ../visit\$ver2.linux-ppc64-BGQ.tar.gz visit\${ver2}.linux-ppc64
cd ..
rm -f resultlog
echo "        build of visit on rzuseq"       > 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 = (statically linked)" >> resultlog 2>&1
echo "number of operator plugins = (statically linked)" >> resultlog 2>&1
echo "number of plot plugins = (statically linked)" >> resultlog 2>&1
mail  -s "VisIt build ($dist): rzuseq" $emailName < resultlog
EOF

if [ $rzuseq = true ]
then
   if [ $test = no ]
   then
      echo "Building on rzuseq"
      scp rzuseq rzuseqlac2:rzuseq_buildit
      scp $dist.tar.gz rzuseqlac2:rzuseq_$dist.tar.gz
      ssh rzuseqlac2 "chmod 750 rzuseq_buildit;./rzuseq_buildit" &
   fi
fi

#
# Build on carver.
#
rm -f carver
cat <<EOF > carver
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/carver; then
   mkdir /usr/tmp/$user/carver
fi
rm -rf /usr/tmp/$user/carver/visitbuild
mkdir /usr/tmp/$user/carver/visitbuild
mv carver_$dist.tar.gz /usr/tmp/$user/carver/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/carver/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/carver_2_6_0/cmake/2.8.8/linux-x86_64_gcc-4.1/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON >> ../../buildlog 2>&1
make -j 4 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on carver"       > 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): carver" $emailName < resultlog
EOF

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

#
# Build on glory.
#
rm -f glory
cat <<EOF > glory
#!/bin/sh
module load compilers/gcc-4.3.4
if test ! -d /usr/tmp ; then
   mkdir /usr/tmp
fi
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/glory; then
   mkdir /usr/tmp/$user/glory
fi
rm -rf /usr/tmp/$user/glory/visitbuild
mkdir /usr/tmp/$user/glory/visitbuild
mv glory_$dist.tar.gz /usr/tmp/$user/glory/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/glory/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/projects/visit/thirdparty_shared/2.12.0/cmake/3.0.2/linux-x86_64_gcc-4.3/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release >> ../../buildlog 2>&1
make -j 2 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on glory"        > 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): glory" $emailName < resultlog
EOF

if [ $glory = true ]
then
   if [ $test = no ]
   then
      echo "Building on glory"
      cp glory glory_buildit
      cp $dist.tar.gz glory_$dist.tar.gz
      chmod 750 glory_buildit;./glory_buildit &
   fi
fi


#
# Build on vulcan.
#
rm -f vulcan
cat <<EOF > vulcan
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/vulcan ; then
   mkdir /usr/tmp/$user/vulcan
fi
rm -rf /usr/tmp/$user/vulcan/visitbuild
mkdir /usr/tmp/$user/vulcan/visitbuild
mv vulcan_$dist.tar.gz /usr/tmp/$user/vulcan/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/vulcan/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
cd ..
# **NOTE** We do 2 in-source builds because of a weird problem with cmake
# Make a copy of src called login_build
cp -R src login_build
# Rename src to compute_build
mv src compute_build
# Rename the data directory since the data programs won't run.
mv data .data
# install dir
mkdir visit\${ver2}.linux-ppc64
bgqinstdir=\`pwd\`/visit\${ver2}.linux-ppc64
# Build for compute node, engine-only version
cd compute_build
/usr/workspace/wsa/visit/visit/thirdparty_static/2.12.0/cmake/3.0.2/linux-ppc64_gcc-4.4_BGQ/bin/cmake -DVISIT_CONFIG_SITE:PATH=config-site/vulcanlac4-compute.cmake -DVISIT_ENGINE_ONLY:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=\$bgqinstdir -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON . >> ../../buildlog 2>&1
sh svn_bin/filter_link_commands_BGQ.sh >> ../../buildlog 2>&1
make install >> ../../buildlog 2>&1
cd ..
# Restore data directory
mv .data data
# Build for login node, server-components-only version
cd login_build
/usr/workspace/wsa/visit/visit/thirdparty_static/2.12.0/cmake/3.0.2/linux-ppc64_gcc-4.4/bin/cmake -DVISIT_CONFIG_SITE:PATH=config-site/vulcanlac4-login.cmake -DVISIT_SERVER_COMPONENTS_ONLY:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=\$bgqinstdir -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON . >> ../../buildlog 2>&1
make install >> ../../buildlog 2>&1
cd ..
# Now, tar up the common install directory.
tar zcf ../visit\$ver2.linux-ppc64-BGQ.tar.gz visit\${ver2}.linux-ppc64
cd ..
rm -f resultlog
echo "        build of visit on vulcan"       > 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 = (statically linked)" >> resultlog 2>&1
echo "number of operator plugins = (statically linked)" >> resultlog 2>&1
echo "number of plot plugins = (statically linked)" >> resultlog 2>&1
mail  -s "VisIt build ($dist): vulcan" $emailName < resultlog
EOF

if [ $vulcan = true ]
then
   if [ $test = no ]
   then
      echo "Building on vulcan"
      scp vulcan vulcanlac4:vulcan_buildit
      scp $dist.tar.gz vulcanlac4:vulcan_$dist.tar.gz
      ssh vulcanlac4 "chmod 750 vulcan_buildit;./vulcan_buildit" &
   fi
fi

#
# Clean up.
#
if [ $test = no ]
then
   rm -f kickit ubuntu1104_64 ubuntu1404_64 surface quartz rztrona rzzeus rzuseq carver glory vulcan
fi
