#!/bin/sh
#   Copyright (C) 1998, 1999, 2000, 2002  Los Alamos National Laboratory,
#   Copyright (C) 1998, 1999, 2000, 2002  CodeSourcery, LLC
#
#   This file is part of FreePOOMA.
#
#   FreePOOMA is free software; you can redistribute it and/or modify it
#   under the terms of the Expat license.
#
#   This program is distributed in the hope that it will be useful, but
#   WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Expat
#   license for more details.
#
#   You should have received a copy of the Expat license along with
#   FreePOOMA; see the file LICENSE.

##########################################################################
# FreePOOMA script to make a distribution tarball.
#
# 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>/.
#
# NOTE: This must be invoked from the top-level of a clean FreePOOMA 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 FreePOOMA tree."
  exit 1
fi

if [ -d $topdir/CVS ]; then
  echo "Error: Use  cvs export -r HEAD freepooma  to start from a clean tree."
  exit 1
fi


### Make sure we have the right arguments

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


### Create a temporary directory to work with

if [ "$TMPDIR" != "" ]; then
  tmpdirbase=$TMPDIR/distrib.$$
else
  tmpdirbase=/tmp/distrib.$$
fi
tmpdir=$tmpdirbase/$distrib
if [ -e $tmpdir ]; then
  echo Temporary directory $tmpdir exists.  Exiting.
  exit 1
fi
mkdir -p $tmpdir


### Copy all extra files to the distribution dir

echo "Copying files specified in bin/DISTRIBFILES ..."
tar c -T bin/DISTRIBFILES -f - | (cd $tmpdir ; tar xf -)

### Copy all non-CVS files from subdirectories

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

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

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


### 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 cf - $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: richi $
#  $Revision: 1.19 $   $Date: 2004/12/01 11:25:45 $
#  ----------------------------------------------------------------------
# ACL:rcsinfo
