#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://qbittorrent.sourceforge.net/
# based on the slackbuilds of Slacky repository --> www.slacky.eu
# svn package 
# Required: Boost >= 1.37, libtorrent-rastebar >= 0.14  Qt >= 4.4.3

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package/qbittorrent
NAME=qbittorrent
VERSION=1.3.0_r2096
ARCH=${ARCH:-i486}
BUILD=1lg

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

cd $TMP

svn co https://qbittorrent.svn.sourceforge.net/svnroot/qbittorrent/trunk qbittorrent

echo -e "\E[0;32m+-------------------------------------------+\E[0;0m"
echo -e "\E[0;36m| Start SlackBuild $NAME-$VERSION |\E[0;0m"
echo -e "\E[0;32m+-------------------------------------------+\E[0;0m"

cd qbittorrent

find . \( -perm 777 -o -perm 775 -o -perm 711 \) -exec chmod 755 {} \;
find . \( -perm 700 -o -perm 555 -o -perm 511 \) -exec chmod 755 {} \;
find . \( -perm 666 -o -perm 664 -o -perm 600 \) -exec chmod 644 {} \;
find . \( -perm 444 -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

chown -R root:root .
./configure --prefix=$PKG/usr \
--qtdir=/opt/qt4 \
--with-libtorrent-inc=/usr/include \
--with-libtorrent-lib=/usr/lib

make || exit 1
make install  || exit 1

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
  AUTHORS COPYING Changelog INSTALL NEWS README TODO \
  $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
mv $PKG/usr/share/man $PKG/usr/man
find $PKG/usr/man -type f -exec gzip -9 {} \;

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

requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP
fi
