#!/bin/bash
# Heavily based on the Slackware 13.0 SlackBuild
# http://www.beastwithin.org/users/wwwwolf/code/xmms/infopipe.html
# SlackBuild by gall0ws ~at~ tiscali ~dot~ it

NAME=xmms-infopipe
VERSION=1.3
test -z "$ARCH" && ARCH=i486
test -z "$TMP" && TMP=/tmp
BUILD=4gal
PKG=$TMP/package-$NAME
CWD=`pwd`

TARBALL=$NAME-$VERSION.tar.gz
PACK=$NAME-$VERSION-$ARCH-$BUILD.txz

if [ $ARCH == "i486" ]; then
 OPTFLAGS="-O2 -march=i486 -mtune=i686"
elif [ $ARCH == "athlon-xp" ]; then
 OPTFLAGS="-O2 -march=athlon-xp -fomit-frame-pointer -pipe"
elif [ $ARCH == "pentium4" ]; then
 OPTFLAGS="-O2 -march=pentium4 -fomit-frame-pointer -pipe"
elif [ $ARCH == "pentiumm" ]; then
 OPTFLAGS="-O2 -march=pentium-m -fomit-frame-pointer -pipe"
fi

function get_sources() 
{
  wget http://www.beastwithin.org/users/wwwwolf/code/xmms/$TARBALL || exit 1
}

TARGET=i486

test -e $PKG && rm -rf $PKG
test -e $TMP/$NAME-$VERSION && rm -rf $TMP/$NAME-$VERSION

test ! -e $TARBALL && get_sources

tar xvzf $TARBALL -C $TMP 
cd $TMP/$NAME-$VERSION

CFLAGS=${OPTFLAGS} \
sh configure --prefix=/usr \
             --program-prefix= \
	     --program-suffix= \
	     --build=$TARGET-slackware-linux
 
make || exit 1
make install DESTDIR=$PKG

mkdir -p -m 755 $PKG/usr/doc/$NAME-$VERSION

cp -a   COPYING \
        AUTHORS \
        INSTALL \
        README \
	NEWS \
$PKG/usr/doc/$NAME-$VERSION

cd $PKG

chmod 644 $PKG/usr/doc/$NAME-$VERSION/*

cp -a $CWD/slack-desc $CWD/$NAME.SlackBuild $PKG/usr/doc/$NAME-$VERSION

chown -R root:root .

find . -exec file {} \; | grep "shared object" | cut -d : -f1 | xargs strip --strip-unneeded 2> /dev/null

mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

echo -ne "\nmaking $NAME package.. "
cd $PKG
requiredbuilder -v -y -s $CWD $PKG
makepkg -c n -l y $CWD/$PACK &>/dev/null
echo "done"

[ "$1" = "--cleanup" ] && {
  echo -ne "cleaning up.. "
  rm -rf $TMP/$NAME-$VERSION
  rm -rf $PKG
  echo "done"
}

## EOF ##
