errmsg () {
  echo Error: $*
  exit 1
}

currdir=${PWD##*/}

if test -z "$version"
then packdir=$currdir
else packdir=$currdir-$version
fi


test -f manifest || errmsg manifest not found

test -f localinstall && localinstall

cd ..

if test ! -z "$version"
then
ln -s $currdir $packdir
fi

rm -fr $packdir.tar{,.gz}

tar cf $packdir.tar $packdir/manifest

for f in $(grep "^[^;]" $packdir/manifest | sed -e 's/^/'$packdir'\//')
do
if test -f $f
then
echo adding $f
tar uf $packdir.tar $f
else
echo ignoring $f
fi
done

gzip $packdir.tar

if test ! -z "$version"
then
rm $packdir
fi

mv $packdir.tar.gz $currdir
