#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://www.yamipod.com/main/modules/home/
# Packager Salbutamolo (alessandro_ranieri@alice.it)

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-yamipod
NAME=yamipod
VERSION=1.7
ARCH=noarch
BUILD=2sal

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

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

cd $TMP
tar xzvf $CWD/yam-linux.tar.gz
cd yam-linux
chown -R root:root .
mkdir -p $PKG/usr/bin
mkdir -p $PKG/usr/lib
mkdir -p $PKG/usr/share/pixmaps
mkdir -p $PKG/usr/share/applications
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a YamiPod $PKG/usr/bin
cp -a libfmodex.so.4.02.05 $PKG/usr/lib
cp -a $CWD/yamipod.png $PKG/usr/share/pixmaps
cp -a $CWD/yamipod.desktop $PKG/usr/share/applications
cp -a Readme.txt $PKG/usr/doc/$NAME-$VERSION
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
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
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
