# $Id$
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Ronald van Haren <ronald.archlinux.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - removed makedepend on vc - not for ARM
#  - patch to remove qreal usage

pkgbase=calligra
pkgname=('calligra-braindump'
         'calligra-devtools'
         'calligra-extras'
         'calligra-filters'
         'calligra-flow'
         'calligra-gemini'
         'calligra-handbook'
         'calligra-karbon'
         'calligra-kexi'
         'calligra-krita'
         'calligra-libs'
         'calligra-plan'
         'calligra-plugins'
         'calligra-sheets'
         'calligra-stage'
         'calligra-words')
pkgver=2.9.8
pkgrel=1
arch=('i686' 'x86_64')
url='http://www.calligra-suite.org/'
license=('FDL1.2' 'GPL2' 'LGPL')
makedepends=('cmake' 'automoc4' 'boost' 'kdepimlibs4' 'eigen' 'libmarble4'
             'lcms2' 'libmariadbclient' 'freetds' 'xbase' 'libwpg' 'opencolorio'
             'libwps' 'gsl' 'glew' 'fftw' 'poppler-qt4' 'libkdcraw' 'libodfgen'
             'openjpeg' 'kdegraphics-okular' 'pstoedit' 'libvisio'
             'libetonyek' 'libpqxx' 'libspnav' 'postgresql') # 'libqgit2'
groups=('calligra')
source=("http://download.kde.org/stable/${pkgbase}-${pkgver}/${pkgbase}-${pkgver}.tar.xz" 'libwps-0.4.patch'
        'qreal.patch')
md5sums=('c731ceb46211aea2a0e1798f646e0bcb'
         '6ea15f8b3938838d89ea0aa08921afd1'
         '266289d4f69f24941d3e94d526a350f2')

prepare() {
  mkdir -p build

# Fix build against libwps 0.4
  cd $pkgbase-$pkgver
  patch -p1 -i "$srcdir"/libwps-0.4.patch

  patch -p1 -i ../qreal.patch

# Fix build against libmarble4
  sed -e 's|PATH_SUFFIXES marble|PATH_SUFFIXES marble4|g' -i CMakeLists.txt
  sed -e 's|#include <marble/|#include <marble4/|g' -e 's|#include "marble/|#include "marble4/|g' \
    -i plugins/reporting/maps/{*.cpp,*.h,marble/*.h} -i kexi/plugins/forms/widgets/mapbrowser/{*.cpp,*.h}
}

build() {
  cd build
  cmake ../${pkgbase}-${pkgver} \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DBUILD_active=OFF \
    -DWITH_Soprano=OFF \
    -DMARBLE_INCLUDE_DIR=/usr/include/marble4 \
    -DMARBLE_GLOBAL_HEADER=/usr/include/marble4/MarbleGlobal.h \
    -DMARBLE_LIBRARIES=/usr/lib/libmarblewidget.so
  make
}

package_calligra-filters() {
  pkgdesc="Filters for the Calligra office suite"
  depends=('libodfgen')
  optdepends=('libwpg: Corel WordPerfect Graphics image importer'
              'libwps: Microsoft Works file word processor format import'
              'libvisio: Microsoft Visio import filter'
              'libetonyek: Apple Keynote import filter')
  install=calligra-filters.install

  cd build/filters
  make DESTDIR="${pkgdir}" install
}

package_calligra-libs() {
  pkgdesc="Libraries for the Calligra office suite"
  depends=('kdepimlibs4' 'libkactivities4')
  conflicts=('calligra-interfaces' 'calligra-pics' 'calligra-servicetypes')
  replaces=('calligra-interfaces' 'calligra-pics' 'calligra-servicetypes')

  for d in interfaces libs pics servicetypes; do
    cd "${srcdir}"/build/${d}
    make DESTDIR="${pkgdir}" install
  done
}

package_calligra-plugins() {
  pkgdesc="Plugins for the Calligra office suite"
  depends=('calligra-libs' 'calligra-filters' 'libspnav')
  optdepends=('libmarble4: map shape for Calligra')
  install=calligra-plugins.install

  cd build/plugins
  make DESTDIR="${pkgdir}" install

  cd ../3rdparty/kdchart
  make DESTDIR="${pkgdir}" install
}

package_calligra-karbon() {
  pkgdesc="Create scalable vector drawings"
  depends=('calligra-libs' 'kdebase-runtime' 'pstoedit')
  optdepends=('calligra-filters: import/export filters'
              'calligra-extras: extra calligra tools')
  install=calligra-karbon.install

  cd build/karbon
  make DESTDIR="${pkgdir}" install
}

package_calligra-kexi() {
  pkgdesc="Develop desktop database applications"
  depends=('calligra-libs' 'glew' 'fftw')
  optdepends=('libmariadbclient: MariaDB driver'
              'libpqxx: PostgreSQL driver'
              'freetds: Sybase & MS SQL driver'
              'xbase: XBase driver'
              'calligra-sheets: Spreadsheet-to-Kexi-table import plugin'
              'libmarble4: map form widget'
              'calligra-plugins: extra calligra plugins')
  install=calligra-kexi.install

  cd build/kexi
  make DESTDIR="${pkgdir}" install
  cd ../doc/kexi
  make DESTDIR="${pkgdir}" install
}

package_calligra-plan() {
  pkgdesc="Calligra Project Management Component"
  depends=('calligra-words')
  install=calligra-plan.install

  cd build/plan
  make DESTDIR="${pkgdir}" install

  cd ../3rdparty/kdgantt
  make DESTDIR="${pkgdir}" install
}

package_calligra-stage() {
  pkgdesc="Write presentation documents"
  depends=('calligra-plugins' 'kdebase-runtime')
  install=calligra-stage.install

  cd build/stage
  make DESTDIR="${pkgdir}" install
  cd ../doc/stage
  make DESTDIR="${pkgdir}" install
}

package_calligra-krita() {
  pkgdesc="Edit and paint images"
  depends=('calligra-plugins' 'kdebase-runtime' 'opencolorio' 'libkdcraw'
           'fftw' 'glew' 'curl' 'gsl')
  install=calligra-krita.install

  cd build/krita
  make DESTDIR="${pkgdir}" install
}

package_calligra-sheets() {
  pkgdesc="Write spreadsheet documents"
  depends=('calligra-libs' 'gsl' 'kdebase-runtime')
  optdepends=('calligra-filters: import/export filters'
              'calligra-plugins: extra calligra plugins'
              'calligra-extras: extra calligra tools')
  install=calligra-sheets.install

  cd build/sheets
  make DESTDIR="${pkgdir}" install
  cd ../doc/sheets
  make DESTDIR="${pkgdir}" install
}

package_calligra-words() {
  pkgdesc="Word Processor"
  depends=('kdebase-runtime' 'calligra-plugins')
  optdepends=('calligra-extras: extra calligra tools')
  install=calligra-words.install

  cd build/words
  make DESTDIR="${pkgdir}" install
}

package_calligra-handbook() {
  pkgdesc="Documentation for Calligra"
  options=('docs')

  cd build/doc/calligra
  make DESTDIR="${pkgdir}" install
}

package_calligra-braindump() {
  pkgdesc="Notes and idea gathering"
  depends=('calligra-libs' 'kdebase-runtime')
  install=calligra-braindump.install

  cd build/braindump
  make DESTDIR="${pkgdir}" install
}

package_calligra-flow() {
  pkgdesc="Flowchart & Diagram Editing"
  depends=('calligra-words')
  optdepends=('calligra-karbon: to export the charts in various formats')
  install=calligra-flow.install

  cd build/flow
  make DESTDIR="${pkgdir}" install
}

package_calligra-extras() {
  pkgdesc="Calligra suite extras"
  depends=('calligra-libs')
  optdepends=('kdegraphics-okular')
  conflicts=('calligra-tools')
  replaces=('calligra-tools')
  install=calligra-extras.install

  cd build/extras
  make DESTDIR="${pkgdir}" install

  cd ../data
  make DESTDIR="${pkgdir}" install
}

package_calligra-devtools() {
  pkgdesc="Calligra developer tools"
  depends=('calligra-libs')

  cd build/devtools
  make DESTDIR="${pkgdir}" install
}

package_calligra-gemini() {
  pkgdesc="QML interface for Calligra Words and Stage"
  depends=('calligra-words' 'calligra-stage')
#  optdepends=('libqgit2: GIT plugin')
  install=calligra-gemini.install

  cd build/qtquick
  make DESTDIR="${pkgdir}" install
  cd "${srcdir}"/build/gemini
  make DESTDIR="${pkgdir}" install
}