#!/bin/sh

if test "x$1" = "x" ; then
  TARFILE=`ls -t Pike-* | head -1`
else
  TARFILE=$1
fi

DIR=`pwd`

case x$TARFILE in
  x/*) FULL_TARFILE=$TARFILE ;;
  *) FULL_TARFILE=$DIR/$TARFILE ;;
esac

BASE_TARFILE=`echo $TARFILE | sed 's@.*/@@' | sed 's@\.tar\.gz$@@'`

TMPDIR=/tmp/makedists$$

mkdir $TMPDIR
cd $TMPDIR

trap 'cd / ; rm -rf $TMPDIR ; exit 1' 1 2 3 15

gzip -cd $FULL_TARFILE | tar xvf -

PIKEDIR=`echo *`

( cd $PIKEDIR/src/modules ; rm -rf  Odbc Oracle )

echo building $DIR/$BASE_TARFILE-sweden.tar.gz
tar cf - $PIKEDIR | gzip -c9 >$DIR/$BASE_TARFILE-sweden.tar.gz


( cd $PIKEDIR/src/modules/_Crypto ; ./.build_lobotomized_crypto )
rm -rf $PIKEDIR/src/modules/_Crypto
$PIKEDIR/src/run_autoconfig 

echo building $DIR/$BASE_TARFILE-export.tar.gz
tar cf - $PIKEDIR | gzip -c9 >$DIR/$BASE_TARFILE-export.tar.gz


cd /
rm -rf $TMPDIR
