#!/bin/sh
# Heavily based on the Slackware 13.0 SlackBuild
# http://gpodder.berlios.de/
# Packager: harakei - "harakei84 AT gmail DOT com"

CWD=`pwd`
TMP=${TMP:-/tmp/txz}
PKG=$TMP/package-gpodder
NAME=gpodder
VERSION=2.3
CHOST=i486
ARCH=${ARCH:-i486}
BUILD=1hrk
SOURCE1=http://download.berlios.de/gpodder/$NAME-$VERSION.tar.gz
SOURCE2=http://download2.berlios.de/gpodder/$NAME-$VERSION.tar.gz

if [ ! -e $CWD/$NAME-$VERSION.tar.gz ]; then
   wget $SOURCE1 || wget $SOURCE2 || exit 1 
fi

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

cd $TMP
tar xzvf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
chown -R root:root .
sed -i "s|DESTDIR ?= /|DESTDIR ?= /$PKG|g" Makefile
make install
#mkdir $PKG/usr
#python setup.py build || exit 1

#cd data/po/
#make || exit 1

#cd ../../

#python setup.py install --root=$PKG || exit 1

mkdir -p $PKG/usr/man/man1
cp -a $PKG/usr/share/man/man1/* $PKG/usr/man/man1
rm -rf $PKG/usr/share/man
find $PKG/usr/man -type f -exec gzip -9 {} \;

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a COPYING INSTALL PKG-INFO README $PKG/usr/doc/$NAME-$VERSION

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/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild

ADD=$(ls /var/log/packages/ | sed -ne 's/\(feedparser\)-\([^-]\+-[^-]\+-[^-]\+\)/\1 >= \2,/p' \
-e 's/\(mygpoclient\)-\([^-]\+-[^-]\+-[^-]\+\)/\1 >= \2/p') \
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.txz

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