#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://albumshaper.sourceforge.net/
# Packagers Gohanz ( gohanz@infinito.ii)
# http://www.slacky.it

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp
fi
PKG=$TMP/package-albumshaper
NAME=albumshaper
VERSION=_2.1
TARGET=i486
ARCH=${ARCH:-i486}
BUILD=1as

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

cd $TMP
tar xvjf $CWD/$NAME$VERSION.tar.bz2
cd $NAME$VERSION'_src'
zcat $CWD/album.diff.gz | patch -p1 -E --backup --verbose
chown -R root:root .

qmake

sed -i "s|-pipe -Wall -W -O2|-O2 -march=i486 -mtune=i686|g" Makefile

make

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a 'install' readme.txt readme_precompiled.txt $PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

mkdir -p $PKG/usr/bin
cp -f $TMP/$NAME$VERSION'_src'/bin/AlbumShaper  $PKG/usr/bin/AlbumShaper
cp -f $TMP/$NAME$VERSION'_src'/bin/AlbumShaper.bin  $PKG/usr/bin/AlbumShaper.bin

mkdir -p $PKG/usr/share/albumshaper
cp -f -r $TMP/$NAME$VERSION'_src'/bin/images         $PKG/usr/share/albumshaper
cp -f -r $TMP/$NAME$VERSION'_src'/bin/text           $PKG/usr/share/albumshaper
cp -f -r $TMP/$NAME$VERSION'_src'/bin/themes         $PKG/usr/share/albumshaper
cp -f -r $TMP/$NAME$VERSION'_src'/bin/translations  $PKG/usr/share/albumshaper
cp -f -r $TMP/$NAME$VERSION'_src'/bin/xmlConversion  $PKG/usr/share/albumshaper

cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/../albumshaper-2.1-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/albumshaper_2.1_src
 rm -rf $PKG
fi
