#!/bin/sh
##########################################################
#
# makesrcdist	2.22
#
# Makes source distribution
#
# $1 - distribution name
#
##########################################################

echo "MakeSrcDist 2.22"
echo 

#### Make the source distribution for distributing the package

TAR=$1
echo "Making Source Distribution for $TAR"
if [ "$TAR" = "" ];then 
  echo "set variable TAR in Makefile.def first."
  exit
fi

#### Check wether the lsm entry exists

if [ ! -r Makefile.lsm ]; then
  echo "You must make an lsm entry - Makefile.lsm"
  exit
fi

#### Now make the distribution

VERSION=`pwd | sed -e s%.*/%%`

echo "  creating $TAR-$VERSION.lsm"
echo "  creating $TAR-$VERSION.tar.gz"

rm -f $TAR-$VERSION.lsm $TAR-$VERSION.tar.gz

DATE=`date +%Y-%m-%d`
cd ..
mkdir $TAR
tar cf $TAR.tar $VERSION
(cd $TAR; tar xf ../$TAR.tar)
rm -f $TAR.tar
tar cf $TAR-$VERSION.tar $TAR
rm -rf $TAR
gzip $TAR-$VERSION.tar

cp $VERSION/Makefile.lsm ./$TAR-$VERSION.lsm
LSMSIZE=`ls -l $TAR-$VERSION.lsm | awk '/.*/ { print $5 }'`
TARSIZE=`ls -l $TAR-$VERSION.tar.gz | awk '/.*/ { print $5 }'`
TARSIZE=`echo "scale=1;$TARSIZE/1024" | bc`

sed -e s/@VERSION@/$VERSION/g <$VERSION/Makefile.lsm | \
  sed -e s/@DATE@/$DATE/g | \
  sed -e s/@LSMSIZE@/$LSMSIZE/g | \
  sed -e s/@TARSIZE@/$TARSIZE/g | \
  sed -e s/@TAR@/$TAR/g \
  > $TAR-$VERSION.lsm

LSMSIZE=`ls -l $TAR-$VERSION.lsm | awk '/.*/ { print $5 }'`

sed -e s/@VERSION@/$VERSION/g <$VERSION/Makefile.lsm | \
  sed -e s/@DATE@/$DATE/g | \
  sed -e s/@LSMSIZE@/$LSMSIZE/g | \
  sed -e s/@TARSIZE@/$TARSIZE/g | \
  sed -e s/@TAR@/$TAR/g \
  > $TAR-$VERSION.lsm


echo "Putting the distribution in working directory"

mv $TAR-$VERSION.lsm $VERSION
mv $TAR-$VERSION.tar.gz $VERSION

echo "done."

