#!/bin/sh
CWD=`pwd`

VERSION=${VERSION:-1.1}
ARCH=${ARCH:-x86_64}
BUILD=${BUILD:-1}

TMP=/tmp/BitchX
PKG=/tmp/package-bitchx

rm -rf $TMP $PKG

if [ ! -x /sbin/fakedestdir ]; then
	echo This .SlackBuild requires fakedestdir from extra/scripts in
	echo /sbin, and executable.
fi

cd /tmp
tar xzvf $CWD/ircii-pana-${VERSION}-final.tar.gz
cd BitchX
chown -R root.root .
find . -perm 775 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
# These are all fixed in 1.1  :-)
#zcat $CWD/BitchX-$VERSION.diff.gz | patch -p1 --verbose
#zcat $CWD/BitchX.DOS.diff.gz | patch -p1 --verbose
#zcat $CWD/1.0c19-evil-server.patch.gz | patch -p1 --verbose
# really old options we don't use anymore
#./configure --prefix=/usr --enable-sound --enable-cdrom --with-ssl --with-plugins --with-gtk
# Thanks to gentoo for patches
zcat $CWD/BitchX-1.1-gcc34.patch.gz | patch -p0 --verbose
# zcat $CWD/BitchX-64bit.patch.gz | patch -p1 --verbose

CFLAGS="-O2" \
./configure \
  --prefix=/usr \
  --enable-cdrom \
  --with-ssl \
  --with-plugins \
  --enable-ipv6
make -j3
fakedestdir $PKG install

cd $PKG
mkdir -p usr/doc/BitchX-$VERSION
mkdir -p usr/man/man1
(cd $TMP;
cp -a \
  README* COMPILE-PROBLEMS INST* IPv6-support doc/* \
  $PKG/usr/doc/BitchX-$VERSION;
cp doc/BitchX.1 $PKG/usr/man/man1)
gzip -9 usr/man/man1/*
mkdir -p install
cat $CWD/slack-desc > install/slack-desc
makepkg -l y -c n ../bitchx-$VERSION-$ARCH-$BUILD.tgz
