#!/bin/bash
# This is how the Debian source tarball was created:

PACKAGE=prboom-plus
VERSION=2.5.1.5+svn
SVNREV=4539
DFSG=1

pushd ..
svn export -r ${SVNREV} https://svn.prboom.org/repos/branches/${PACKAGE}-24/prboom2/ ${PACKAGE}-${VERSION}${SVNREV}
pushd ${PACKAGE}-${VERSION}${SVNREV}

# Filter out non-free graphics and sound lumps
BADLUMPS="$(sed -n '/^if NONFREE_GRAPHICS/,/^else\|^endif/p' data/Makefile.am | sed -e '/^if\|^else\|^endif\|^SPRITEP/d' | cut -d '=' -f 2)"
for l in ${BADLUMPS}
do
	rm data/$l
done

# Remove embedded library copies and tests
rm -rf src/MUSIC/dll src/MUSIC/include src/MUSIC/lib src/PCRELIB tests

popd
mv ${PACKAGE}-${VERSION}${SVNREV} ${PACKAGE}-${VERSION}${SVNREV}+dfsg${DFSG}

tar cJfv ${PACKAGE}_${VERSION}${SVNREV}+dfsg${DFSG}.orig.tar.xz ${PACKAGE}-${VERSION}${SVNREV}+dfsg${DFSG}
popd
