#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-amarok

# Set the config option variables if they are not already set:
if [ -r ../KDE.options ]; then
  . ../KDE.options
fi

# The global options may be overridden here (if needed):
if [ -r ./local.options ]; then
  . ./local.options
fi

rm -rf $PKG
mkdir -p $PKG/usr

# Avoid a version number in .la files:
if [ -d /usr/lib64/qt ]; then
  QTDIR=/usr/lib64/qt
fi
cd $TMP
echo "Building amarok-$VERSION.tar.bz2..."
tar xjvf $CWD/amarok-$VERSION.tar.bz2

# I *hate* it when an "a" release blows off updating the directory name.  Grrrrrrrrrrrrrrrr.
# Commented out post 1.4.0a...
#cd amarok-1.4.0 || exit 1
cd amarok-$VERSION
chown -R root:root .
CFLAGS=$CPUOPT \
CXXFLAGS=$CPUOPT \
./configure \
  --prefix=/usr \
  --sysconfdir=/etc/kde \
  --with-xinerama \
  --with-libnjb \
  --with-libmtp \
  --with-libgpod \
  --with-libkarma \
  --disable-debug \
  --program-prefix="" \
  --program-suffix="" \
  --build=$TARGET-$DISTRO-linux
make $NUMJOBS || exit 1
make install DESTDIR=$PKG
mkdir -p $PKG/usr/doc/amarok-$VERSION
cp -a \
  AUTHORS COPYING INSTALL README TODO \
  $PKG/usr/doc/amarok-$VERSION
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
)
if [ -d $PKG/usr/man ]; then
  gzip -9 $PKG/usr/man/man?/*
fi

cd $PKG
makepkg -l y -c n ../amarok-$VERSION-${ARCH}_slamd64-$BUILD.tgz