#!/bin/bash

# kdebindings.SlackBuild
# Heavily based on the original Slackware build scripts,
# Modified by Stuart Winter <mozes@slackware.com>
# 08-Aug-2005

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

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

# 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

# Avoid a version number in .la files:
if [ -d /usr/lib${LIBDIRSUFFIX}/qt ]; then
  QTDIR=/usr/lib${LIBDIRSUFFIX}/qt
fi
     
# Temporary build locations:
export TMPBUILD=$TMP/build-$PKGNAM
export PKG=$TMP/package-$PKGNAM
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

# Extract source:
tar xvf $CWD/../src/kdebindings-$VERSION.tar.?z* 
cd $PKGNAM-$VERSION || exit 1
slackhousekeeping

# ARM build fixes from Debian:
zcat $PORTCWD/sources/kdebindings*diff*gz | patch -p1
for i in \
  support_armel_in_generator.diff \
  fix_segfault_in_generator_on_armel.diff \
  01_python_modules_dont_link_against_libpython.diff \
  02_include_default_settings_in_python_cmakelist.diff \
  04_fix_ruby_requires.diff \
  05_rbqtapi_ruby1.8.diff \
  07_fix_kpythonpluginfactory_build.diff \
  08_csharp_plasma_examples.diff \
  10_fix_kimono_dllimports.diff \
  11_make_pykde4_respect_sip_flags.diff \
  12_pythonpluginfactory_use_versioned_python_lib.diff \
  version_cppparser_library.diff \
  optional_install_sip_files.diff ; do
    auto_apply_patch debian/patches/$i || exit 1   
done

# Taken from upstream svn commit:
# We *are* eabi:
#auto_apply_patch $PORTCWD/sources/eabi.fix || exit 1

# Slackware patches:
zcat $CWD/kdebindings-len-ptr-rfloat.diff.gz | patch -p1 --verbose || exit 1
zcat $CWD/kdebindings-ruby-env.h.diff.gz | patch -p1 --verbose || exit 1
zcat $CWD/kdebindings-rubyconfig.h.diff.gz | patch -p1 --verbose || exit 1

# Configure:
# The break in the config lines is where the stuff that makes the
# build work on ARM.
mkdir -p build
cd build
cmake \
   $KDE_OPT_ARGS \
    -DCMAKE_C_FLAGS:STRING="$SLKCFLAGS" \
    -DCMAKE_CXX_FLAGS:STRING="$SLKCFLAGS" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DMAN_INSTALL_DIR=/usr/man \
    -DSYSCONF_INSTALL_DIR=/etc/kde \
    -DLIB_SUFFIX=${LIBDIRSUFFIX} \
    -DENABLE_QYOTO:BOOL=OFF \
    -DENABLE_QSCINTILLA_SHARP:BOOL=OFF \
    -DENABLE_KIMONO:BOOL=OFF \
    -DBUILD_csharp:BOOL=OFF \
    \
    \
    -DCMAKE_USE_RELATIVE_PATHS=ON \
    -DCMAKE_VERBOSE_MAKEFILE=ON \
    -DKDE4_BUILD_TESTS=false \
    -DKDE4_USE_ALWAYS_FULL_RPATH=false \
    -DCMAKE_EXE_LINKER_FLAGS="-Wl,--as-needed" \
    -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--as-needed" \
    -DCMAKE_MODULE_LINKER_FLAGS="-Wl,--as-needed" \
    -DENABLE_PYKDE4=OFF \
    -DENABLE_SOPRANO_SMOKE=ON \
    -DENABLE_NEPOMUK_SMOKE=ON \
    -DENABLE_NEPOMUK_RUBY=ON \
    -DENABLE_PHONON_RUBY=ON \
    -DENABLE_KHTML_SHARP=ON \
    .. || exit 1

    # Build:
    make $NUMJOBS || make || exit 1

    # Install into package:
    make install DESTDIR=$PKG
    cd -
mkdir -p $PKG/usr/doc/kdebindings-$VERSION
cp -a AUTHORS COPYING* INSTALL NEWS README \
  $PKG/usr/doc/kdebindings-$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
slackmp         # run makepkg -l y -c n

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