#!/bin/sh
# ./debian/repack
# Repackage the DS9 source files, with unnecessary files removed. 

ver=$2
orig_tar=$3
tardir=$(dirname $orig_tar)
wd=$(mktemp -d)
echo $ver $orig_tar $tardir $wd

tar xf $orig_tar -C $wd 
srcdir=$wd/*

for subdir in funtools\* tcl8.\* tcllib-\* tk8.\* tkimg\* signal_ext\* \
              tktable\* tkcon-\* tclxml-\* wcssubs-\* xpa-\* tkblt\* win \
              zip-\* zlib-\* compilers ast-\* zvfs tkmacosx\* ; do
    rm -rf $srcdir/$subdir
done

find $srcdir/ -name config.status |xargs rm -f
find $srcdir/ -name conf.h |xargs rm -f

dfsg_tar=$tardir/saods9_$ver+repack.orig.tar.xz
tar cJf $dfsg_tar -C $wd .
rm -rf $wd

exec uupdate --no-symlink --upstream-version $ver+repack $dfsg_tar
