# Set initial variables:
CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-xine-ui
rm -rf $PKG
mkdir -p $PKG/usr

VERSION=0.99.5
# I would use "-march=i486 -mcpu=i686" here as usual, but with XINE it's all or nothing.
# I'd rather have it work well for the i686/Athlon crowd than suck for everyone.
ARCH=${ARCH:-i686}
TARGET=${TARGET:-$ARCH-pc-linux-gnu}
BUILD=${BUILD:-1}

cd $TMP
rm -rf xine-ui-$VERSION
tar xjvf $CWD/xine-ui-$VERSION.tar.bz2 || exit 1
cd xine-ui-$VERSION || exit 1

chown -R root:root .
find . -perm 664 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;

XINE_BUILD=$TARGET \
./configure \
  --prefix=/usr \
  --with-aalib \
  --with-caca \
  --build=$TARGET

make -j4 || exit 1
make install DESTDIR=$PKG

mkdir -p $PKG/usr/share/applications
zcat $CWD/xine.desktop.gz > $PKG/usr/share/applications/xine.desktop
( cd $PKG
  find . | xargs file | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded
)
( cd $PKG/usr/man
  find . -name "*.?" | xargs gzip -9
)
mkdir -p $PKG/usr/doc/xine-ui-$VERSION
cp -a \
  ABOUT-NLS AUTHORS COPYING NEWS README \
  doc/README* \
  $PKG/usr/doc/xine-ui-$VERSION
cp -a \
  src/xitk/xine-toolkit/README
  $PKG/usr/doc/xine-ui-$VERSION/README.xitk
# redundant
rm -rf $PKG/usr/share/doc
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
makepkg -l y -c n $TMP/xine-ui-$VERSION-$ARCH-$BUILD.tgz