#!/bin/bash

# Build an original tar-ball for a debian package free of a debian directory and
# .git.

version=`head -1 debian/changelog | sed 's/.*(//
     s/-.*//'`
sed -i "s/LIB_TAG=.*/LIB_TAG=$version/" Makefile
if [ "`basename $PWD`" != "sonic-$version" ]; then
    echo "Directory name should be sonic-$version"
    exit 1
fi
make clean
make -f debian/rules clean
echo "sonic_${version} (git: `git log -1 --oneline | sed 's/ .*//'`)" > version
git2cl > ChangeLog
cd ..
if ! tar -cvzf sonic_$version.orig.tar.gz --exclude-vcs --exclude=debian sonic-$version; then 
    echo "Could not create sonic_$version.orig.tar.gz"
    exit 1
fi
echo "Successfully created sonic_$version.orig.tar.gz"