#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# Url: http://klibido.sourceforge.net/
# Requirements: uudeview
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-klibido
rm -rf $PKG
mkdir -p $PKG

NAME=klibido
VERSION=0.2.5
ARCH=${ARCH:-i486}
BUILD=2bj

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
fi

cd $TMP
rm -rf $NAME-$VERSION
tar xvzf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
cat $CWD/klibido-cvs-gcc41.patch | patch -p1 -E --backup --verbose
chown -R root:root .
find . -perm 775 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
FLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure --prefix=/usr --without-arts \
            --enable-cxx --enable-final \
	    --disable-nls --disable-rpath \
            --program-prefix= --program-suffix= \
            --build=$ARCH-slackware-linux-gnu
make
make install DESTDIR=$PKG
strip $PKG/usr/bin/*
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS COPYING ChangeLog INSTALL NEWS README TODO \
$PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild

cd $PKG
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/$NAME-$VERSION
 rm -rf $PKG
fi
