#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://beepmp.sourceforge.net/

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

NAME=bmp
VERSION=0.9.7.1
ARCH=i486
BUILD=1all

if [ ! -d $TMP ]; then
mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
mkdir -p $PKG
fi
echo "+-----------------+"
echo "| $NAME-$VERSION|"
echo "+-----------------+"
cd $TMP
tar xzvf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
CFLAGS="-O2 -march=i486 -mtune=i686" ./configure \
--prefix=/usr \
--program-prefix= \
--program-suffix= \
--build=i486-slackware-linux
make
make DESTDIR=$PKG install

( cd $PKG/usr/share/applications
sed -i "s|Icon=bmp.png|Icon=/usr/share/pixmaps/bmp.png|g" bmp.desktop
)

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
ABOUT-NLS AUTHORS COPYING ChangeLog FAQ INSTALL NEWS README \
$PKG/usr/doc/$NAME-$VERSION

gzip $PKG/usr/man/man1/*

chown -R root:root $PKG
chmod -R 644 $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 -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
