#!/bin/bash
set -e

NAME=eclipse-linuxtools
VERSION=1.2.1
DEB_VERSION=${VERSION}+dfsg

ECLIPSE_GIT_WEB=http://git.eclipse.org/c

rm -rf ${NAME}-${DEB_VERSION}

VERSION_UNDERSCORE=$(echo $VERSION | sed "s/\./_/g")
REPO_NAME=org.eclipse.linuxtools

TARBALL=${REPO_NAME}-${VERSION}.tar.bz2

wget "$ECLIPSE_GIT_WEB/linuxtools/$REPO_NAME.git/snapshot/$TARBALL"
tar xf $TARBALL
rm -f $TARBALL

mv ${REPO_NAME}-${VERSION} ${NAME}-${DEB_VERSION}
cd ${NAME}-${DEB_VERSION}

find -type f -name .gitignore -delete

# binaries
find -type f -name a.out -delete
find -type f -name *.libhover -delete

# GFDL invariant section - not DFSG compliant
rm -f libhover/org.eclipse.linuxtools.cdt.libhover.glibc/data/glibc-*.xml

# generated files
rm -f lttng/org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/CTFLexer.java
rm -f lttng/org.eclipse.linuxtools.ctf.parser/src/org/eclipse/linuxtools/ctf/parser/CTFParser.java

# remove empty directories
find . -depth -type d -empty -delete

cd ..

echo "Creating tarball '${NAME}_${DEB_VERSION}.orig.tar.xz'..."
tar -cJf ../${NAME}_${DEB_VERSION}.orig.tar.xz $NAME-$DEB_VERSION

rm -rf ${NAME}-${DEB_VERSION}
