#!/bin/sh
# ACL:license
#  ----------------------------------------------------------------------
#  This software and ancillary information (herein called "SOFTWARE")
#  called PETE (Portable Expression Template Engine) is
#  made available under the terms described here.  The SOFTWARE has been
#  approved for release with associated LA-CC Number LA-CC-99-5.
#  
#  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 PETE, send e-mail to pete@acl.lanl.gov,
#  or visit the PETE web page at http://www.acl.lanl.gov/pete/.
#  ----------------------------------------------------------------------
# ACL:license

##########################################################################
# PETE script to install PETE
#
# 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 'pete-2.0'
#
# NOTE: This must be invoked from the top-level of the PETE 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 PETE tree."
  exit 1
fi


### Make sure we have the right arguments

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

distrib=pete-2.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 INSTALL.mac INSTALL.unix INSTALL.windows LICENSE README makefile; do
  if [ -f $f ] ; then
    echo "Copying $f to $tmpdir ..."
    cp $f $tmpdir
  fi
done


### Copy all non-CVS files from subdirectories

for d in bin config examples html ide src ; do
  echo "Copying files from directory '$d' ..."
  flist=`find $d -type f -print | grep -v CVS | grep -v ii_files | grep -v ti_files`
  if [ "$flist" != "" ]; then
    tar cf - $flist | (cd $tmpdir ; tar xvf -)
  else
    if [ ! -d $tmpdir/$d ]; then
      mkdir $tmpdir/$d
    fi
  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.9 $   $Date: 1999/02/04 15:52:11 $
#  ----------------------------------------------------------------------
# ACL:rcsinfo
