#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://ri-li.sourceforge.net/index.html
# Ri-li package.

NAME=ri-li
VERSION=2.0.1
ARCH=i486
BUILD=2fr

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

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

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

if [ "$1" = "--cleanup" ]; then
 echo "+---------------------------------+"
 echo "| Start cleaning |"
 echo "+---------------------------------+"
 rm -rf $TMP/Ri-li-$VERSION
 rm -rf $PKG
 exit 0
fi

echo "+---------------------------------+"
echo "| Start SlackBuild $NAME-$VERSION |"
echo "+---------------------------------+"

cd $TMP
tar xjfv $CWD/Ri-li-$VERSION.tar.bz2
cd Ri-li-$VERSION
chown -R root:root .

find . -perm 775 -exec chmod 755 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 771 -exec chmod 755 {} \;
find . -perm 611 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;

CFLAGS="-O2 -march=i486 -mtune=i686"
CXXFLAGS="-O2 -march=i486 -mtune=i686"
./configure --prefix=/usr \
--disable-debug \
--enable-color \
--program-prefix= \
--program-suffix=

aclocal
automake

make || exit 1

make install DESTDIR=$PKG || exit 1

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS COPYING COPYING.Music ChangeLog INSTALL NEWS README $PKG/usr/doc/$NAME-$VERSION
rm $PKG/usr/share/Ri-li/{Ri-li-2.0.1-r1.ebuild,COPYING.Music}

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

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/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
