#!/bin/sh
# upad - A program for debugging, and uploading code to embedded devices.
# Copyright (C) 2016, 2019 John Darrington

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

git clean -dfx
./bootstrap
vers=`awk -F = '/PACKAGE_VERSION/{print $2}' configure | grep -v '^ *$' | sed -e "s/'//g"`
release=upad-$vers
temp=$(mktemp -d)
ln -s $(pwd) $temp/$release
files=$(git ls-files)

(cd $temp ;
 tar -cf $release.tar $release/COPYING;
 for f in $files; do
     tar -uf $release.tar $release/$f;
 done
 tar -uf $release.tar $release/configure;
 tar -uf $release.tar $release/config.h.in;
 tar -uf $release.tar $release/config.sub;
 tar -uf $release.tar $release/config.guess;
 tar -uf $release.tar $release/install-sh;
 tar -uf $release.tar $release/lib;
)

# Remove unwanted files
tar -tf $temp/$release.tar | while read f ; do
    case $f in
	*.gitignore)
	    tar --delete -f $temp/$release.tar $f ;;
    esac
done

gzip $temp/$release.tar
cp $temp/$release.tar.gz .
rm -rf $temp
