#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# Url: http://wolfpack.twu.net/IV/
# http://www.slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-iv

NAME=iv
VERSION=2.2.1
TARGET=i486
ARCH=${ARCH:-i486}
BUILD=2bj
SOURCE=http://wolfpack.twu.net/users/wolfpack/$NAME-$VERSION.tar.bz2

if [ ! -e $NAME-$VERSION.tar.bz2 ]; then
wget -c $SOURCE
fi

cd $TMP
rm -rf $NAME-$VERSION
rm -rf $PKG
mkdir -p $PKG 
tar xjvf $CWD/$NAME-$VERSION.tar.bz2 || exit 1
cd $NAME-$VERSION
chown -R root:root .
./configure Linux -v --prefix=/usr --CFLAGS="-O2 -march=i486 -mtune=i686"
make || exit 1
make install PREFIX=$PKG/usr || exit 1
strip $PKG/usr/bin/*

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a INSTALL LICENSE README $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/usr/{share/applications,share/pixmaps}
cat > $PKG/usr/share/applications/$NAME.desktop <<END
[Desktop Entry]
Type=Application
Comment=image viewer
Encoding=UTF-8
Exec=iv %F
GenericName=Picture Viewer
Icon=/usr/share/pixmaps/iv.xpm
MimeType=
Name=IV
Name[en_US]=Iv
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
Categories=Qt;KDE;Graphics;
END
mv $PKG/usr/share/icons/iv.xpm $PKG/usr/share/pixmaps
rm -rf $PKG/usr/share/icons

cd $PKG
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
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP
fi
