#! /bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://linux.bytesex.org/fbida/

CWD=`pwd`
if ["$TMP" = ""]; then
TMP=/tmp
fi

PKG=$TMP/fbida
NAME=fbida
VERSION=2.07
ARCH=i486
BUILD=1ld

if [ ! -d $TMP ]; then
mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
mkdir -p $PKG
fi

echo "+--------------+"
echo "|  $NAME-$VERSION  |"
echo "+--------------+"
cd $TMP
tar zxf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION || exit 1
chown -R root:root .
CFLAGS="-O2 -march=i486 -mtune=i686"
prefix="/usr"
export prefix CFLAGS
make
make DESTDIR=$PKG install
strip $PKG/usr/bin/exiftran
strip $PKG/usr/bin/fbi
strip $PKG/usr/bin/ida
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a COPYING Change* INSTALL* README* TODO VERSION \
$PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/usr/man/man1/
cp -a $PKG/usr/share/man/man1/* $PKG/usr/man/man1/
gzip -9 $PKG/usr/man/man1/*
rm -rf $PKG/usr/share
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild
requiredbuilder -v -y -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
