#!/bin/sh
# ACL:license
#  ----------------------------------------------------------------------
#  This software and ancillary information (herein called "SOFTWARE")
#  called POOMA (Parallel Object-Oriented Methods and Applications) is
#  made available under the terms described here.  The SOFTWARE has been
#  approved for release with associated LA-CC Number LA-CC-98-65.
#  
#  Unless otherwise indicated, this SOFTWARE has been authored by an
#  employee or employees of the University of California, operator of the
#  Los Alamos National Laboratory under Contract No.  W-7405-ENG-36 with
#  the U.S. Department of Energy.  The U.S. Government has rights to use,
#  reproduce, and distribute this SOFTWARE, and to allow others to do so.
#  The public may copy and use this SOFTWARE, FOR NONCOMMERCIAL USE ONLY,
#  without charge, provided that this Notice and any statement of
#  authorship are reproduced on all copies.  Neither the Government nor
#  the University makes any warranty, express or implied, or assumes any
#  liability or responsibility for the use of this SOFTWARE.
#  
#  If SOFTWARE is modified to produce derivative works, such modified
#  SOFTWARE should be clearly marked, so as not to confuse it with the
#  version available from LANL.
#  
#  For more information about POOMA, send e-mail to pooma@acl.lanl.gov,
#  or visit the POOMA web page at http://www.acl.lanl.gov/pooma/.
#  ----------------------------------------------------------------------
# ACL:license

##########################################################################
# POOMA script to install POOMA
#
# Usage:
#
#   makedistrib [<distribbase>]
#
# where
#
#   <distribbase> = base name of distribution file.  The final distribution
#     file will be named <distribbase>.tgz, and will unpack into a directory
#     <distribbase>/. The default is 'pooma-2.1'
#
# NOTE: This must be invoked from the top-level of the POOMA tree.
##########################################################################


### Get our current directory, and make sure it is the top-level dir

topdir=`pwd`

if [ ! -d $topdir/src ]; then
  echo "Error: This script must be run from the top level of the POOMA tree."
  exit 1
fi


### Make sure we have the right arguments

if [ "$#" != "1" -a "$#" != "0" ]; then
  echo "Usage: $0 [<distribbase>]"
  exit 1
fi

distrib=pooma-2.1.0
if [ "$#" != "0" ]; then
  distrib=$1
fi


### Create a temporary directory to work with

if [ "$TMPDIR" != "" ]; then
  tmpdirbase=$TMPDIR/distrib.$$
else
  tmpdirbase=/tmp/distrib.$$
fi
tmpdir=$tmpdirbase/$distrib
if [ ! -d $tmpdir ]; then
  mkdir -p $tmpdir
fi


### Copy all top-level files to the distribution dir

for f in  CREDITS README LICENSE VERSION.LOG INSTALL.mac INSTALL.windows INSTALL.unix configure makefile include.mk subdir.mk; do
  if [ -f $f ] ; then
    echo "Copying $f to $tmpdir ..."
    cp $f $tmpdir
  fi
done


### Put the version number file into the distribution dir

vernumfile=$tmpdir/VERSION.NUM
rm -f $vernumfile
echo $distrib > $vernumfile


### Copy all non-CVS files from subdirectories

for d in benchmarks config examples html ide src scripts ; do
  echo "Copying files from directory '$d' ..."
  tar cf - $d | (cd $tmpdir ; tar xvf -)
done

for d in lib bin ; do
  if [ ! -d $tmpdir/$d ]; then
    mkdir $tmpdir/$d
  fi
  touch $tmpdir/$d/empty
done


### Copy the desired bin files (and ONLY the desired bin files)

binlist=`cat bin/DISTRIBFILES`
for b in $binlist ; do
  bfile="bin/$b"
  echo "Copying over bin file $bfile ..."
  cp $bfile $tmpdir/bin
done


### Remove files we know we don't want out of the previous list

for d in src/FileTemplates ; do
  if [ -d $tmpdir/$d ]; then
    echo "Removing directory $tmpdir/$d from distribution ..."
    rm -rf $tmpdir/$d
  fi
done


### Create a tarred and gzipped verson of the tmp directory

echo "Creating distribution file $distrib.tgz ..."
cd $tmpdir/..
if [ -f $distrib.tgz ]; then
  mv -f $distrib.tgz $distrib.tgz.old
fi
tar cvf - $distrib | gzip -c > $distrib.tgz


### Move the distribution file to our original spot and clean up

echo "Cleaning up ..."
cd $topdir
if [ -f $distrib.tgz ]; then
  mv -f $distrib.tgz $distrib.tgz.old
fi
mv -f $tmpdir/../$distrib.tgz $distrib.tgz

rm -rf $tmpdirbase


# ACL:rcsinfo
#  ----------------------------------------------------------------------
#  $RCSfile: makedistrib,v $   $Author: sa_smith $
#  $Revision: 1.15 $   $Date: 2000/08/18 04:14:29 $
#  ----------------------------------------------------------------------
# ACL:rcsinfo
