CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-xine-lib
rm -rf $PKG
mkdir -p $PKG/usr

# Version on the tarball
VERSION=1.1.3
# Version used in the source directory to cd into
DIRVER=1.1.3
# Version used for the Slackware package
PKGVER=1.1.3

# 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=1_slack9.1

cd $TMP
rm -rf xine-lib-$VERSION
tar xjvf $CWD/xine-lib-$VERSION.tar.bz2
cd xine-lib-$DIRVER

chown -R root:root .
find . -perm 664 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
XINE_BUILD=$TARGET \
./configure \
  --prefix=/usr \
  --mandir=/usr/man \
  --with-w32-path=/usr/lib/codecs
make -j3 || exit 1
make install DESTDIR=$PKG
mkdir -p $PKG/usr/lib/codecs
( cd $PKG
  find . | xargs file | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded
)
for manpagedir in $PKG/usr/man/man? ; do
  if [ -d $manpagedir ]; then
    ( cd $manpagedir ; gzip -9 *.? )
  fi
done
mkdir -p $PKG/usr/doc/xine-lib-$VERSION
cp -a \
  ABOUT-NLS AUTHORS COPYING CREDITS NEWS README TODO \
  doc \
  $PKG/usr/doc/xine-lib-$VERSION
# redundant
rm -rf $PKG/usr/share/doc
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $TMP/package-xine-lib
makepkg -l y -c n ../xine-lib-$PKGVER-$ARCH-$BUILD.tgz