#!/bin/sh
# Heavily based on the Slackware 13.0 SlackBuild
# Url: http://www.triptico.com/software/mp.html
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it

set -e

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-mp
rm -rf $PKG
mkdir -p $PKG{/usr/bin,/install,/usr/share/applications,/usr/share/pixmaps}

NAME=mp
VERSION=5.1.3
ARCH=${ARCH:-i486}
BUILD=1bj
SOURCE=http://triptico.com/download/$NAME-$VERSION.tar.gz

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

cd $TMP
rm -rf $NAME-$VERSION
tar xzf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
./config.sh \
        --prefix=/usr \
	--without-gtk1
make CFLAGS="-O2 -march=i486 -mtune=i686"
make install DESTDIR=$PKG
strip $PKG/usr/bin/*
cp -a *.xpm $PKG/usr/share/pixmaps
cp -a $CWD/*.desktop $PKG/usr/share/applications
chmod -R 755 $PKG/usr/share/*
find $PKG/usr/share -type f -exec chmod 644 {} \;
mv $PKG/usr/share/{doc,man} $PKG/usr
mv $PKG/usr/doc/$NAME-5 $PKG/usr/doc/$NAME-$VERSION
gzip -9 $PKG/usr/man/man?/*.?
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
chown -R root:root .
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.txz
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP
fi
