#!/bin/sh
# Repack an upstream tarball, unpacking waf files inside it.
#
# Meant to be run by uscan(1) as the "command param", after repacking
# (if any) by mk-origtargz. So you shouldn't give "repacksuffix" to
# debian/watch; instead you should set it below; however this should
# still match the dversionmangle in that file.
#
# This file was downloaded from
# https://wiki.debian.org/UnpackWaf?action=AttachFile&do=view&target=repack-waf
# and has been modified.

repacksuffix="+dfsg1"

# You shouldn't need to change anything below here.

USAGE="Usage: $0 --upstream-version version filename"

test "$1" = "--upstream-version" || { echo >&2 "$USAGE"; exit 2; }
upstream="$2"
basedir=$(dirname "$3")
filename=$(basename "$3")

source="$(dpkg-parsechangelog -SSource)"
newups="${upstream}${repacksuffix}"

set -e

tar -xf "$basedir/$filename"
(
	cd "${source}-${upstream}"
	python ./waf --help > /dev/null
	mv .waf-*/* .
	sed -i '/^#==>$/,$d' waf
	rmdir .waf-*
	find waf* -name "*.pyc" -delete
	rm -rf build-win32/
	rm -rf win32/
	rm -rf debian/
)
mv "${source}-${upstream}" "${source}-${newups}"
tar -I 'gzip -9fn' -cf "$basedir/${source}-${newups}.tar.gz" "${source}-${newups}"
rm -rf "${source}-${newups}"

