# $Id: PKGBUILD 237799 2015-04-20 18:55:17Z arojas $
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Pierre Schmitz <pierre@archlinux.de>

pkgbase=kdebase-runtime
pkgname=('kdebase-runtime' 'khelpcenter4' 'kdebase-runtime-doc' 'kdesu4')
pkgver=15.04.0
pkgrel=4
pkgdesc="Plugins and applications necessary for the running of KDE applications"
arch=('i686' 'x86_64')
url='https://projects.kde.org/projects/kde/kde-runtime'
license=('GPL' 'LGPL')
makedepends=('kdelibs' 'libkactivities4' 'smbclient' 'libssh' 'libcanberra' 'libwebp'
	'pkg-config' 'cmake' 'automoc4' 'kdepimlibs' 'openslp' 'doxygen' 'networkmanager' 'boost')
source=("http://download.kde.org/stable/applications/${pkgver}/src/kde-runtime-${pkgver}.tar.xz")
sha1sums=('5cbfec48ead85a1cd3dab675b98623dd4a831d91')

prepare() {
  mkdir build
}

build() {
  cd build
  cmake ../kde-runtime-${pkgver} \
    -DCMAKE_BUILD_TYPE=Release \
    -DKDE4_BUILD_TESTS=OFF \
    -DCMAKE_SKIP_RPATH=ON \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DWITH_QNtrack=OFF \
    -DSAMBA_INCLUDE_DIR=/usr/include/samba-4.0 \
    -DWITH_NepomukCore=OFF
  make
}

package_khelpcenter4() {
  pkgdesc=("Application to show KDE Applications' documentation")
  depends=('kdebase-runtime' 'htdig' 'rarian' 'kdebase-runtime-doc')
  provides=("khelpcenter=$pkgver")
  conflicts=('khelpcenter')

  cd build/khelpcenter
  make DESTDIR="$pkgdir" install
}

package_kdebase-runtime() {
  depends=('kdelibs' 'kactivities' 'libkactivities4' 'smbclient' 'libssh' 'libcanberra'
         'oxygen-icons' 'xorg-xauth' 'libwebp')
  optdepends=('kdepimlibs: for kwalletd, and is needed by DrKonqi to send crash reports to KDE.org' 'kdebase-runtime-doc: KDE4 documentation'
            'gdb: needed by DrKonqi to generate backtrace' 'khelpcenter: to display applications documentation')
  provides=('notification-daemon')
  install=$pkgname.install

  cd build
  make DESTDIR="$pkgdir" install

  rm "${pkgdir}"/usr/share/icons/hicolor/index.theme

# Remove khelpcenter
  cd "$pkgdir"
  find -name '*khelpcenter*' | xargs rm -fr
  find -name 'khc*' | xargs rm -fr
  rm usr/share/applications/kde4/Help.desktop

# Remove docs
  rm -r "$pkgdir"/usr/share/{doc,man}

# Remove kdesu
  rm "$pkgdir"/usr/lib/kde4/libexec/kdesu*
}

package_kdebase-runtime-doc() {
  pkgdesc=("KDE4 documentation")
  conflicts=('khelpcenter<15' 'plasma-desktop' 'kio-extras')

  cd build/doc
  make DESTDIR="$pkgdir" install

# Remove kdesu docs
  rm -r "$pkgdir"/usr/share/doc/HTML/en/kdesu/
  rm "$pkgdir"/usr/share/man/man1/kdesu.1
}

package_kdesu4() {
  pkgdesc=("Run KDE applications as root")
  depends=('kdebase-runtime')
  conflicts=('kde-cli-tools')

  cd build/kdesu
  make DESTDIR="$pkgdir" install

  cd ../doc/kdesu
  make DESTDIR="$pkgdir" install

  mkdir -p "$pkgdir"/usr/bin
  ln -sf /usr/lib/kde4/libexec/kdesu "$pkgdir"/usr/bin/

  # FS#36668
  chown :nobody "${pkgdir}"/usr/lib/kde4/libexec/kdesud
  chmod g+s "${pkgdir}"/usr/lib/kde4/libexec/kdesud
}
