#!/bin/sh
# Heavily based on the Slackware 13.0 SlackBuild
# http://code.google.com/p/wbar
# Packager harakei - "harakei84 AT gmail DOT com"

CWD=`pwd`
TMP=${TMP:-/tmp/txz}
NAME=wbar
PKG=$TMP/package/$NAME
VERSION=1.3.3.patch
ARCH=${ARCH:-i686}
BUILD=7hrk
SOURCE=http://www.smithux.com/docs/wbar-patched/$NAME-$VERSION.tgz

if [ ! -e $CWD/$NAME-$VERSION.tgz ]; then
   wget $SOURCE || exit 1
fi

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

cd $TMP
tar xvzf $CWD/$NAME-$VERSION.tgz
cd $NAME-$VERSION
patch < $CWD/wbar-gcc430_and_warnings.patch
chown -R root:root .

#Patch per nascondere la barra, da usare con parametro -balfa 0
#cat hide.patch | patch -p0

make || exit 1
mkdir -p $PKG/usr/share
make PREFIX=$PKG/usr/share/wbar install
mkdir -p $PKG/usr/share/wbar/iconpack/wbar.osx/font/12/
mkdir -p $PKG/usr/bin
cp wbar $PKG/usr/bin
cp -a $PKG/usr/share/wbar/iconpack/comic.ttf $PKG/usr/share/wbar/iconpack/wbar.osx/font/12/

# dot.wbar Fix
sed -i 's/\/tmp\/txz\/package\/wbar//g' $PKG/usr/share/wbar/dot.wbar

mkdir -p $PKG/usr/doc/$NAME-$VERSION/SlackBuild
cp -a AUTHORS COPYING NEWS README $PKG/usr/doc/$NAME-$VERSION
make uninstall
cd $PKG
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/doinst.sh > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/SlackBuild/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/SlackBuild/$NAME.SlackBuild
requiredbuilder -v -y -s $CWD $PKG
makepkg -l n -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.txz

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