#!/bin/bash
SRC_URL=http://smplayer.sourceforge.net/
#
# script : til <rob DOT til DOT freedman AT googlemail DOT com>
set -e -u -x
#
# smplayer
version=0.6.9
build=64.1
arch=i686
tune=i686

pkgname=smplayer-$version
package=$pkgname-$arch-$build

# the source
PKG_SRC="http://prdownloads.sourceforge.net/sourceforge/smplayer/smplayer-$version.tar.bz2
http://zenwalk.pinguix.com/user-accounts/tilderb/extra/xap/smplayer/build-smplayer.sh"

PKG_DEP="cxxlibs|gcc-g++,expat,fontconfig,freetype,gcc,glib2,libICE,libSM,libX11,libXau,libXdmcp,libXext,libXrender,libpng,libxcb,mplayer,qt,util-linux-ng,zlib"

# check source packages
#for url in $PKG_SRC;do [ ! -e ${url##*/} ] && (echo "download: $url"; wget -N -c $url) done
#
CWD=$(pwd)
TMP=${TMP:-$CWD/tmp}

PKG=$TMP/$package
SRC=$TMP/$pkgname

test -d $SRC && rm -fr $SRC 
test -d $PKG && rm -fr $PKG

# prepare build directory
mkdir -p $SRC $PKG/{install,usr/{src,doc}/$pkgname}

tar xf $CWD/$pkgname.tar.bz2 --strip-components=1 -C $SRC
cd $SRC

export CFLAGS="-O2 -march=$arch -mtune=$tune"
export CXXFLAGS="-O2 -march=$arch -mtune=$tune"
export QTDIR=/usr/lib/qt4
export PATH=$QTDIR/bin:$PATH

sed -i "s:share/man/:man/:g" Makefile
sed -i "s:PREFIX=/usr/local:PREFIX=/usr:g" Makefile
sed -i "s:/share/doc/packages/smplayer:/doc/$pkgname:g" Makefile
sed -i "s:=qmake:=qmake QMAKE_CFLAGS=\"$CFLAGS\" QMAKE_CXXFLAGS=\"$CXXFLAGS\":g" Makefile
#sed -i "s:translations/smplayer_gl.ts::g" src/smplayer.pro

make
make DESTDIR=$PKG install 

cd $PKG
#helperline 
find . -printf "%Y %M %p\n" >$CWD/make.installed

# strip symbols
strip --strip-unneeded usr/bin/smplayer

# slack-desc
#       |-----handy-ruler------------------------------------------------------|
cat <<EOF > install/slack-desc
smplayer: smplayer (a complete front-end for MPlayer)
smplayer:
smplayer: SMPlayer intends to be a complete front-end for MPlayer, 
smplayer: from basic features like playing videos, DVDs, and VCDs to 
smplayer: more advanced features like support for Mplayer filters and more.
smplayer: One of the main features is the ability to remember the state
smplayer: of a played file, so when you play it later it will resume at the
smplayer: same point and with the same settings. 
smplayer: smplayer is developed with the Qt toolkit, so it's multi-platform.
EOF

# fix up
#find usr/share/smplayer/translations/ -iname '*.qm' | grep -v 'en_US' | xargs -r rm -vf
#rm -vfr usr/doc/$pkgname/{ru,de,ro,ja,es,nl,cs}/
mkdir -p usr/share/icons/hicolor/48x48/apps
convert -size 48x48 usr/share/icons/hicolor/64x64/apps/smplayer.png \
	usr/share/icons/hicolor/48x48/apps/smplayer.png

cp $CWD/build-smplayer.sh usr/src/$pkgname
cd $PKG
fakeroot /sbin/makepkg -l y -c n $CWD/$package.txz

cd $CWD
echo $PKG_DEP >$package.dep
echo -e "$PKG_SRC" >$package.src
md5sum $package.txz >$package.md5

