#!/bin/sh
# SlackBuild for KMyMoney.
# Author: Artur Kedzierski

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp/pkg
fi

NAME=libofx
PKG=$TMP/package-$NAME
VERSION=0.8.0
ARCH=${ARCH:-i686}
BUILD=1ak

SLKLIBDIR="/usr/lib/"
if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686 -m32"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mcpu=i686 -m32"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -m64"
  SLKLIBDIR="/usr/lib64/"
fi

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

cd $TMP
rm -rf $NAME-$VERSION
tar zxvf $CWD/$NAME-$VERSION.tar.gz || exit 1
cd $NAME-$VERSION
chown -R root.root .
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure $SLKCONFIGFLAGS \
    --prefix=/usr \
    --with-opensp-libs=$SLKLIBDIR \
    --libdir=$SLKLIBDIR \
|| exit 1
make || exit 1
make install DESTDIR=$PKG || exit 1

chown -R root.bin $PKG/usr/bin
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
CHANGELOG COPYING INSTALL README TODO AUTHORS \
 $PKG/usr/doc/$NAME-$VERSION
gzip -9 $PKG/usr/man/*/*
gzip -9 $PKG/usr/info/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

( 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
  find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

# Added SlackBuild files
mkdir -p $PKG/usr/src/slackbuilds/$NAME
cp -a $CWD/$0 $CWD/slack-desc $PKG/usr/src/slackbuilds/$NAME
chown -R root.root $PKG/usr/doc/$NAME-$VERSION
cd $PKG

requiredbuilder -v -y $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/$NAME-$VERSION
 rm -rf $PKG
fi
