#!/bin/sh
#-----------------------------------------------------------------------
#
# VISIT-BUILD-CLOSED - Build the visit distributions on the closed
#                      network.
#
# Author: Eric Brugger
# Date:   February 12, 2001
#
# Usage:
#    visit-build-closed -d <distribution>
#
#
# Modifications:
#
#   Hank Childs, Mon Oct 15 09:04:12 PDT 2007
#   Add some print statements for usability.
#
#   Hank Childs, Thu Oct 18 15:40:05 PDT 2007
#   Add ksh support for sunset.
#
#   Hank Childs, Mon Oct 22 09:25:47 PDT 2007
#   More ksh support for sunset.
#
#   Hank Childs, Sat Feb  9 14:18:54 PST 2008
#   Change clearcase_bin to svn_bin.
#
#   Eric Brugger, Mon Apr  7 13:51:23 PDT 2008
#   Removed sc build.
#
#   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 sunset since Qt4 does not build
#   there.
#
#   Eric Brugger, Fri Nov  5 15:39:05 PDT 2010
#   Replaced hopi with inca and removed pruple.
#
#   Eric Brugger, Wed Jan  5 09:39:22 PST 2011
#   Added terminator.
#
#   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, Fri Mar 25 10:20:22 PDT 2011
#   Added cielo.
#
#   Eric Brugger, Tue Jun 21 15:06:05 PDT 2011
#   I removed the code to swap out the xt-mpt module with the xt-mpich2
#   module on cielo since the xt-mpich2 module was now the default.
#
#   Eric Brugger, Wed Jun 27 11:36:45 PDT 2012
#   Deleted terminator.
#
#   Eric Brugger, Mon Jul 30 10:27:10 PDT 2012
#   Added gremlin.
#
#   Eric Brugger, Wed Mar 20 11:48:51 PDT 2013
#   Deleted gremlin. Replaced termite with hitit.
#
#   Eric Brugger, Thu Jun 20 10:36:14 PDT 2013
#   I modified the hitit build since it is now an x86_64 system instead
#   of an i686 system.
#
#   Eric Brugger, Tue Jul  9 11:23:43 PDT 2013
#   I changed the gateway node to login to cielo.
#
#   Eric Brugger, Tue Oct 22 11:06:24 PDT 2013
#   I modified many of the builds to use cmake 2.8.10.2.
#
#   Eric Brugger, Fri Aug 29 09:52:43 PDT 2014
#   I modified the cmake execute line to build the paraDIS reader to
#   several of the LLNL builds.
# 
#   Eric Brugger, Thu Feb 19 09:12:51 PST 2015
#   I modified many of the builds to use cmake 3.0.2.
#
#   Eric Brugger, Mon Sep 19 14:13:23 PDT 2016
#   Deleted cielo. Added trinity.
#
#   Eric Brugger, Mon Nov 21 11:47:57 PST 2016
#   Added jade.
#
#   Eric Brugger, Mon Jan  9 13:33:33 PST 2017
#   I replaced inca with zin.
#
#   Eric Brugger, Tue Jan 17 17:09:23 PST 2017
#   I replaced hitit with winnipeg.
#
#   Eric  Brugger, Mon Oct  9 09:33:38 PDT 2017
#   I updated the builds for visit 2.13.0.
#
#   Eric Brugger, Mon Nov 19 15:45:52 PST 2018
#   Added shark.
#
#-----------------------------------------------------------------------

test=no

user=`whoami`

#
# Parse the execute line, providing default values for error checking.
#
winnipeg=true
zin=true
jade=true
shark=true
trinity=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)
         winnipeg=false
         zin=false
         jade=false
         shark=false
         trinity=false
         shift
         ;;
      -winnipeg)
         winnipeg=false
         shift
         ;;
      +winnipeg)
         winnipeg=true
         shift
         ;;
      -zin)
         zin=false
         shift
         ;;
      +zin)
         zin=true
         shift
         ;;
      -jade)
         jade=false
         shift
         ;;
      +jade)
         jade=true
         shift
         ;;
      -shark)
         shark=false
         shift
         ;;
      +shark)
         shark=true
         shift
         ;;
      -trinity)
         trinity=false
         shift
         ;;
      +trinity)
         trinity=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 "    winnipeg (B-Div, x86_64),"
   echo "    zin (LC, x86_64)"
   echo "    jade (LC, x86_64)"
   echo "    shark (LC, ppc)"
   echo "    trinity (LANL, x86_64)"
   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 winnipeg.
#
rm -f winnipeg
cat <<EOF > winnipeg
#!/bin/sh
if test ! -e winnipeg ; then
   mkdir winnipeg
fi
rm -rf winnipeg/visitbuild
mkdir winnipeg/visitbuild
mv winnipeg_$dist.tar.gz winnipeg/visitbuild/$dist.tar.gz
cd winnipeg/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/misc/gapps/visit/thirdparty_shared/2.13.0/cmake/3.8.1/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 4 >> ../../buildlog 2>&1
make package >> ../../buildlog 2>&1
mv visit\$ver2.linux-x86_64.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on winnipeg"   > 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 [ $winnipeg = true ]
then
   if [ $test = no ]
   then
      echo "Building on winnipeg"
      scp -P 22 winnipeg winnipeg:winnipeg_buildit
      scp -P 22 $dist.tar.gz winnipeg:winnipeg_$dist.tar.gz
      ssh -p 22 winnipeg "chmod 750 winnipeg_buildit;./winnipeg_buildit" &
   fi
fi

#
# Build on zin.
#
rm -f zin
cat <<EOF > zin
#!/bin/sh
XLOCALEDIR=/usr/lib/X11/locale
PATH=/usr/bin/X11:\$PATH
export PATH=/opt/rh/devtoolset-3/root/usr/bin:\$PATH
export GNU_INCLUDES=/opt/rh/devtoolset-3/root/usr/include/c++/4.9.2
export GNU_LIBS=/opt/rh/devtoolset-3/root/usr/lib64:/opt/rh/devtoolset-3/root/usr/lib/gcc/x86_64-redhat-linux/4.9.2
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/opt/rh/devtoolset-3/root/usr/lib64:/opt/rh/devtoolset-3/root/usr/lib/gcc/x86_64-redhat-linux/4.9.2
export _LMFILES_=/opt/modules/modulefiles/gnu/4.9.2
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/zin ; then
   mkdir /usr/tmp/$user/zin
fi
rm -rf /usr/tmp/$user/zin/visitbuild
mkdir /usr/tmp/$user/zin/visitbuild
mv zin_$dist.tar.gz /usr/tmp/$user/zin/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/zin/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/usr/workspace/ws1/visit/visit/thirdparty_shared/2.13.0/chaos5/cmake/3.8.1/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 6 >> ../../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 zin"          > 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 [ $zin = true ]
then
   if [ $test = no ]
   then
      echo "Building on zin"
      scp zin zin497:zin_buildit
      scp $dist.tar.gz zin497:zin_$dist.tar.gz
      ssh zin497 "chmod 750 zin_buildit;./zin_buildit" &
   fi
fi

#
# Build on jade.
#
rm -f jade
cat <<EOF > jade
#!/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/jade ; then
   mkdir /usr/tmp/$user/jade
fi
rm -rf /usr/tmp/$user/jade/visitbuild
mkdir /usr/tmp/$user/jade/visitbuild
mv jade_$dist.tar.gz /usr/tmp/$user/jade/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/jade/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/usr/workspace/ws1/visit/visit/thirdparty_shared/2.13.0/toss3/cmake/3.8.1/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 6 >> ../../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 jade"         > 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 [ $jade = true ]
then
   if [ $test = no ]
   then
      echo "Building on jade"
      scp jade jade962:jade_buildit
      scp $dist.tar.gz jade962:jade_$dist.tar.gz
      ssh jade962 "chmod 750 jade_buildit;./jade_buildit" &
   fi
fi

#
# Build on shark.
#
rm -f shark
cat <<EOF > shark
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/shark ; then
   mkdir /usr/tmp/$user/shark
fi
rm -rf /usr/tmp/$user/shark/visitbuild
mkdir /usr/tmp/$user/shark/visitbuild
mv shark_$dist.tar.gz /usr/tmp/$user/shark/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/shark/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/usr/workspace/ws1/visit/visit/thirdparty_shared/2.13.3/blueos3/cmake/3.8.1/linux-ppc64le_gcc-4.9/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=ON >> ../../buildlog 2>&1
make -j 6 >> ../../buildlog 2>&1
make -j 6 package >> ../../buildlog 2>&1
mv visit\$ver2.linux-intel.tar.gz ../..
cd ../..
rm -f resultlog
echo "        build of visit on shark"        > 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 [ $shark = true ]
then
   if [ $test = no ]
   then
      echo "Building on shark"
      scp shark shark23:shark_buildit
      scp $dist.tar.gz shark23:shark_$dist.tar.gz
      ssh shark23 "chmod 750 shark_buildit;./shark_buildit" &
   fi
fi

#
# Build on trinity.
#
rm -f trinity
cat <<EOF > trinity
#!/bin/sh
if test ! -d /tmp/$user ; then
   mkdir /tmp/$user
fi
if test ! -d /tmp/$user/trinity ; then
   mkdir /tmp/$user/trinity
fi
rm -rf /tmp/$user/trinity/visitbuild
mkdir /tmp/$user/trinity/visitbuild
mv trinity_$dist.tar.gz /tmp/$user/trinity/visitbuild/$dist.tar.gz
cd /tmp/$user/trinity/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist/src
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
/usr/projects/views/visit/thirdparty_shared/2.13.0/cmake/3.8.1/linux-x86_64_gcc-7.1/bin/cmake . -DCMAKE_BUILD_TYPE:STRING=Release -DVISIT_INSTALL_THIRD_PARTY:BOOL=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 ../..
cd ../..
rm -f resultlog
echo "        build of visit on trinity"      > 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 [ $trinity = true ]
then
   if [ $test = no ]
   then
      echo "Building on trinity"
      cp trinity trinity_buildit
      cp $dist.tar.gz trinity_$dist.tar.gz
      chmod 750 trinity_buildit;./trinity_buildit &
   fi
fi

#
# Clean up.
#
if [ $test = no ]
then
   rm -f winnipeg zin jade shark trinity
fi
