#!/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>
#
#-----------------------------------------------------------------------

test=no

user=`whoami`

#
# Parse the execute line, providing default values for error checking.
#
hitit=true
sunset=true
warp=false
sc=true
tidalwave=true
white=true
emperor=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)
         hitit=false
         sunset=false
         warp=false
         sc=false
         tidalwave=false
         white=false
         emperor=false
         shift
         ;;
      -hitit)
         hitit=false
         shift
         ;;
      +hitit)
         hitit=true
         shift
         ;;
      -sunset)
         sunset=false
         shift
         ;;
      +sunset)
         sunset=true
         shift
         ;;
      -warp)
         warp=false
         shift
         ;;
      +warp)
         warp=true
         shift
         ;;
      -sc)
         sc=false
         shift
         ;;
      +sc)
         sc=true
         shift
         ;;
      -tidalwave)
         tidalwave=false
         shift
         ;;
      +tidalwave)
         tidalwave=true
         shift
         ;;
      -white)
         white=false
         shift
         ;;
      +white)
         white=true
         shift
         ;;
      -emperor)
         emperor=false
         shift
         ;;
      +emperor)
         emperor=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>"
   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 hitit.
#
rm -f hitit
cat <<EOF > hitit
#!/bin/sh
if test ! -e /gscratch/$user ; then
   mkdir /gscratch/$user
fi
if test ! -e /gscratch/$user/hitit ; then
   mkdir /gscratch/$user/hitit
fi
rm -rf /gscratch/$user/hitit/visitbuild
mkdir /gscratch/$user/hitit/visitbuild
mv hitit_$dist.tar.gz /gscratch/$user/hitit/visitbuild/$dist.tar.gz
cd /gscratch/$user/hitit/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 ./configure >> ../buildlog 2>&1
make -j 4 >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.linux.tar.gz ..
cd ..
rm -f resultlog
echo "        build of visit on hitit"        > 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/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
EOF
 
if [ $hitit = true ]
then
   if [ $test = no ]
   then
      scp -P 22 hitit hitit:hitit_buildit
      scp -P 22 $dist.tar.gz hitit:hitit_$dist.tar.gz
      ssh -p 22 hitit "chmod 750 hitit_buildit;./hitit_buildit &"
   fi
fi

#
# Build on sunset.
#
rm -f sunset
cat <<EOF > sunset
#!/bin/sh
if test ! -d /export/scratch/$user ; then
   mkdir /export/scratch/$user
fi
if test ! -d /export/scratch/$user/sunset ; then
   mkdir /export/scratch/$user/sunset
fi
rm -rf /export/scratch/$user/sunset/visitbuild
mkdir /export/scratch/$user/sunset/visitbuild
mv sunset_$dist.tar.gz /export/scratch/$user/sunset/visitbuild/$dist.tar.gz
cd /export/scratch/$user/sunset/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 ./configure >> ../buildlog 2>&1
make -j 4 >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.sunos5.tar.gz ..
cd ..
echo "        build of visit on sunset"       > 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/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
EOF

if [ $sunset = true ]
then
   if [ $test = no ]
   then
      scp -P 22 sunset sunset:sunset_buildit
      scp -P 22 $dist.tar.gz sunset:sunset_$dist.tar.gz
      ssh -p 22 sunset "chmod 750 sunset_buildit;./sunset_buildit &"
   fi
fi

#
# Build on warp.
#
rm -f warp
cat <<EOF > warp
#!/bin/sh
if test ! -d /scratch/$user ; then
   mkdir /scratch/$user
fi
if test ! -d /scratch/$user/warp ; then
   mkdir /scratch/$user/warp
fi
rm -rf /scratch/$user/warp/visitbuild
mkdir /scratch/$user/warp/visitbuild
mv warp_$dist.tar.gz /scratch/$user/warp/visitbuild/$dist.tar.gz
cd /scratch/$user/warp/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 ./configure >> ../buildlog 2>&1
make -j 4 >> ../buildlog 2>&1
env PARALLEL=4 make -P >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.irix6.tar.gz ..
cd ..
echo "        build of visit on warp"         > 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/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
EOF

if [ $warp = true ]
then
   if [ $test = no ]
   then
      scp -P 22 warp warp:warp_buildit
      scp -P 22 $dist.tar.gz warp:warp_$dist.tar.gz
      ssh -p 22 warp "chmod 750 warp_buildit;./warp_buildit &"
   fi
fi

#
# Build on sc.
#
rm -f sc
cat <<EOF > sc
#!/bin/sh
if test ! -d /nfs/tmp3/$user ; then
   mkdir /nfs/tmp3/$user
fi
if test ! -d /nfs/tmp3/$user/sc ; then
   mkdir /nfs/tmp3/$user/sc
fi
rm -rf /nfs/tmp3/$user/sc/visitbuild
mkdir /nfs/tmp3/$user/sc/visitbuild
mv sc_$dist.tar.gz /nfs/tmp3/$user/sc/visitbuild/$dist.tar.gz
cd /nfs/tmp3/$user/sc/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 MAKE=gmake ./configure --enable-parallel >> ../buildlog 2>&1
gmake -j 3 >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.osf1.tar.gz ..
cd ..
echo "        build of visit on sc"           > 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/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
EOF

if [ $sc = true ]
then
   if [ $test = no ]
   then
      scp sc sc1:sc_buildit
      scp $dist.tar.gz sc1:sc_$dist.tar.gz
      ssh sc1 "chmod 750 sc_buildit;./sc_buildit" &
   fi
fi

#
# Build on tidalwave, both serial and parallel versions.
#
rm -f tidalwave
cat <<EOF > tidalwave
#!/bin/sh
if test ! -d /fc/san1/$user ; then
   mkdir /fc/san1/$user
fi
if test ! -d /fc/san1/$user/tidalwave ; then
   mkdir /fc/san1/$user/tidalwave
fi
rm -rf /fc/san1/$user/tidalwave/visitbuild
mkdir /fc/san1/$user/tidalwave/visitbuild
mv tidalwave_$dist.tar.gz /fc/san1/$user/tidalwave/visitbuild/$dist.tar.gz
cd /fc/san1/$user/tidalwave/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 ./configure --enable-parallel >> ../buildlog 2>&1
env PARALLEL=20 make -P >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.irix6.tar.gz ..
cd ..
echo "        build of visit on tidalwave"    > 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/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
EOF

if [ $tidalwave = true ]
then
   if [ $test = no ]
   then
      scp tidalwave tidalwave:tidalwave_buildit
      scp $dist.tar.gz tidalwave:tidalwave_$dist.tar.gz
      ssh tidalwave "chmod 750 tidalwave_buildit;./tidalwave_buildit &"
   fi
fi

#
# Build on white, both serial and parallel versions.
#
rm -f white
cat <<EOF > white
#!/bin/sh
PATH=/usr/local/bin:$PATH
if test ! -d /p/gw1/$user ; then
   mkdir /p/gw1/$user
fi
if test ! -d /p/gw1/$user/white ; then
   mkdir /p/gw1/$user/white
fi
rm -rf /p/gw1/$user/white/visitbuild
mkdir /p/gw1/$user/white/visitbuild
mv white_$dist.tar.gz /p/gw1/$user/white/visitbuild/$dist.tar.gz
cd /p/gw1/$user/white/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 MAKE=gmake ./configure --enable-parallel >> ../buildlog 2>&1
gmake -j 6 >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.aix.tar.gz ..
cd ..
echo "        build of visit on white"        > 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/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
EOF

if [ $white = true ]
then
   if [ $test = no ]
   then
      scp white white:white_buildit
      scp $dist.tar.gz white:white_$dist.tar.gz
      ssh white "chmod 750 white_buildit;./white_buildit" &
   fi
fi

#
# Build on emperor, both serial and parallel versions.
#
rm -f emperor
cat <<EOF > emperor
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/emperor ; then
   mkdir /usr/tmp/$user/emperor
fi
rm -rf /usr/tmp/$user/emperor/visitbuild
mkdir /usr/tmp/$user/emperor/visitbuild
mv emperor_$dist.tar.gz /usr/tmp/$user/emperor/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/emperor/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 ./configure --enable-parallel >> ../buildlog 2>&1
make -j 3 >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.linux.tar.gz ..
cd ..
echo "        build of visit on emperor"      > 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/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
EOF

if [ $emperor = true ]
then
   if [ $test = no ]
   then
      scp emperor emperor0:emperor_buildit
      scp $dist.tar.gz emperor0:emperor_$dist.tar.gz
      ssh emperor0 "chmod 750 emperor_buildit;./emperor_buildit &"
   fi
fi

#
# Clean up.
#
if [ $test = no ]
then
   rm -f hitit sunset warp sc tidalwave white emperor
fi
