#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://kwave.sf.net/
# Packager Gohanz ( gohanz@infinito.it )
# http://www.slacky.it
# Depends from:
# Recode, id3lib, gsl

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-kwave
NAME=kwave
VERSION=0.7.11
ARCH=${ARCH:-i686}
BUILD=1as

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

cd $TMP
tar xvzf $CWD/$NAME-0.7.11-1.tar.gz
cd $NAME-$VERSION
export QTDIR=/usr/lib/qt
export KDEDIRS=/usr
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
mkdir kwave-build
cd kwave-build
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr
make
make install DESTDIR=$PKG
cd ..
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS CHANGES GNU-LICENSE LICENSES README TODO VERSION $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
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION

cd $PKG
chown -R root:root .
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
