#!/bin/bash

#
# This script is used for preparing the tarballs.
# Do not use it, please.
#

#
# DeMorgan rules applied :-) I like math...
#

if [ "x`whoami`" != xpavel -a "x`whoami`" != xhugh -a "x`whoami`" != xpkot -a "x`whoami`" != xbozo ]
then
   echo "No way to test this :-)"
fi

VERSION=`cat ../VERSION`

PWD=`pwd`
SRC_DIR=`dirname ${PWD}`

rm -rf /tmp/gnokii-${VERSION}
cp -r ${SRC_DIR} /tmp/gnokii-${VERSION}

(
   cd /tmp/gnokii-${VERSION}
   ./autogen.sh
#   for patch in `ls patches/`; do
#	cat $patch | patch -p0
#   done
   make -C common gnvcal.c
   mv common/gnvcal.c common/gnvcal2.c
   # RedHat thing
   cp packaging/RedHat/gnokii.spec .
   # and Debian one
   cp -r packaging/Debian debian
   # and for Slack as well
   cp packaging/Slackware/SlackBuild packaging/Slackware/SlackBuild-save
   cp packaging/Slackware/SlackBuild-xgnokii packaging/Slackware/SlackBuild-xgnokii-save
   # and there's Gentoo
   cp packaging/Gentoo/gnokii.ebuild packaging/Gentoo/gnokii-${VERSION}.ebuild
   # get recent version of gnapplet.sis
   wget -q -O utils/gnapplet.sis http://users.szivarvanynet.hu/bozo/gnokii/gnapplet.sis
   make distclean
   mv common/gnvcal2.c common/gnvcal.c
   # and again for Slack
   mv packaging/Slackware/SlackBuild-save packaging/Slackware/SlackBuild
   mv packaging/Slackware/SlackBuild-xgnokii-save packaging/Slackware/SlackBuild-xgnokii
   # prepare configure for dku-2 module
   # for 2.4 kernel
   cd patches/kernel_2.4
   autoconf
   cd ../..
   # and for 2.6 kernel
   cd patches/kernel_2.6
   autoconf
   cd ../..
   # prepare the tarballs
   cd ..
   tar -cz --exclude CVS -f /tmp/gnokii-${VERSION}.tar.gz gnokii-${VERSION}
   echo "Distribution generated in /tmp/gnokii-${VERSION}.tar.gz"
   tar -cj --exclude CVS -f /tmp/gnokii-${VERSION}.tar.bz2 gnokii-${VERSION}
   echo "Distribution generated in /tmp/gnokii-${VERSION}.tar.bz2"
)

rm -rf /tmp/gnokii-${VERSION}

