#!/bin/bash

# kdemultimedia.SlackBuild
# Heavily based on the original Slackware build scripts,
# Modified by Stuart Winter <stuart@armedslack.org>
# 10-Aug-2005

# Record toolchain & other info for the build log:
slackbuildinfo

# 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

# Paths to skeleton port's source & real Slackware source tree:
export CWD=$SLACKSOURCE/$PKGSERIES/$PACKAGE
export PORTCWD=$PWD

# Temporary build locations:
export TMPBUILD=$TMP/build-$PACKAGE
export PKG=$TMP/package-$PACKAGE
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

# Create some package framework:
mkdir -p $PKG/opt/kde
mkdir -p $PKG/usr/doc/$PACKAGE-$VERSION

# Avoid a version number in .la files:
if [ -d /usr/lib/qt ]; then
   QTDIR=/usr/lib/qt
fi

# I hear from Debian that the kernel is actually correct here, and that it's
# KDE that has the bug.  All I know is that this kludges it, and nothing else
# seems to run into this.  It's not enough to get me to patch the kernel in
# a permanent way, that's for sure.
#
# If you can figure out who's officially responsible and what the fix really
# is, please tell them.  If that's me, I'm waiting for the clue-stick.
if [ "$ARCH" = "i386" \
  -o "$ARCH" = "i486" \
  -o "$ARCH" = "i586" \
  -o "$ARCH" = "i686" ]; then
  if ! grep -q "ifndef __STRICT_ANSI__" /usr/include/asm/byteorder.h ; then
    ( cd /usr/include/asm
      zcat $CWD/ugly-kernel-patch.diff.gz | patch -p1 --verbose --backup --suffix=.orig || failpatch
    )
  fi
fi

# Extract source:
tar jxvvf $CWD/$PACKAGE-$VERSION.tar.bz2
cd $PACKAGE-$VERSION
slackhousekeeping

# Configure:
CFLAGS=$CPUOPT \
CXXFLAGS=$CPUOPT \
./configure \
  --prefix=/opt/kde \
  --with-xinerama \
  --disable-debug \
  --program-prefix="" \
  --program-suffix="" \
  $TARGET-slackware-linux || failconfig

# Build:
make $NUMJOBS || failmake

# Install into package:
make install DESTDIR=$PKG

# Install docs:
cp -a AUTHORS COPYING INSTALL README \
      $PKG/usr/doc/$PACKAGE-$VERSION

# If necessary, start the fakeroot server so we can set file/dir ownerships:
start_fakeroot

# Apply generic Slackware packaging policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, slackchown, slack644docs
slackdesc       # install slack-desc and doinst.sh

# Build the package:
if [ $PORTARCH = arm ]; then
   slackmp # run makepkg
  else
   makepkg -l y -c n $PKGSTORE/$PKGSERIES/$PACKAGE-$VERSION-$ARCH-$BUILD.tgz
fi

# Perform any final checks on the package:
cd $PKG
slackhlinks     # search for any hard links
