#!/bin/sh
# get source for snappy-java to enable stripping binaries without source

set -e
NAME=`dpkg-parsechangelog | awk '/^Source/ { print $2 }'`

if ! echo $@ | grep -q upstream-version ; then
    VERSION=`dpkg-parsechangelog | awk '/^Version:/ { print $2 }' | sed 's/\([0-9\.]\+\)-[0-9]\+$/\1/'`
else
    VERSION=`echo $@ | sed "s?^.*--upstream-version \([0-9.]\+\) .*${NAME}.*?\1?"`
    if echo "$VERSION" | grep -q "upstream-version" ; then
        echo "Unable to parse version number"
        exit
    fi
fi

mkdir -p ../tarballs
cd ../tarballs
mv ../${NAME}-${VERSION}.tar.gz .

tar -xzf ${NAME}-${VERSION}.tar.gz

# Remove native libraries for different OSes which are not needed because we link
# against Debian packaged libraries
rm -rf ${NAME}-${VERSION}/src/main/resources/org/xerial/snappy/native

# Remove lib/ directory which was also stripped by Charles Plessy before and seems to be unneeded
rm -rf ${NAME}-${VERSION}/lib

GZIP="--best --no-name" tar --owner=root --group=root --mode=a+rX -czf "$NAME"_"$VERSION"~dfsg.orig.tar.gz "${NAME}-${VERSION}"
rm -rf "${NAME}-$VERSION"
