# $Id: PKGBUILD 125926 2015-01-14 18:24:18Z arcanis $
# Maintainer: Evgeniy Alekseev <arcanis at archlinux dot org>
# Maintainer: Ilya87 <yast4ik at yahoo dot com>

pkgbase=qscintilla-qt5
pkgname=('qscintilla-qt5' 'python-qscintilla-qt5' 'python2-qscintilla-qt5'
         'python-qscintilla-qt5-common')
pkgver=2.8.4
pkgrel=2
license=('GPL')
arch=('i686' 'x86_64')
url="http://www.riverbankcomputing.co.uk/software/qscintilla/intro"
makedepends=('python2-pyqt5' 'python-pyqt5' 'qt5-tools' 'chrpath')
options=('!buildflags')
source=("http://downloads.sourceforge.net/pyqt/QScintilla-gpl-${pkgver}.tar.gz"
        'configure.py.patch'
        'libname.patch')
changelog=ChangeLog
md5sums=('28aec903ff48ae541295a4fb9c96f8ea'
         'ea1d11d0a87341d2e55ebef6beeb5663'
         '1ac0fea53f72b0146e0820912ae8c48c')

prepare() {
  cd "QScintilla-gpl-${pkgver}"

  patch -Np1 -i "${srcdir}/configure.py.patch"
  patch -Np1 -i "${srcdir}/libname.patch"

  cp -r Python{,2}
  find "Python2" -name '*.py' -type f -exec \
       sed -i 's|env python|env python2|' {} \;
}

build() {
  cd "QScintilla-gpl-${pkgver}/Qt4Qt5"
  qmake qscintilla.pro
  make

  cd "../designer-Qt4Qt5"
  qmake designer.pro INCLUDEPATH+=../Qt4Qt5 QMAKE_LIBDIR+=../Qt4Qt5
  make

  cd "../Python"
  python3 configure.py -n ../Qt4Qt5/ -o ../Qt4Qt5/ -c --pyqt=PyQt5 --pyqt-sipdir=/usr/share/sip/PyQt5 --qsci-sipdir=/usr/share/sip/PyQt5  --qmake /usr/bin/qmake
  make

  cd "../Python2"
  python2 configure.py -n ../Qt4Qt5/ -o ../Qt4Qt5/ -c --pyqt=PyQt5 --pyqt-sipdir=/usr/share/sip/PyQt5 --qsci-sipdir=/usr/share/sip/PyQt5 --qmake /usr/bin/qmake
  make
}

package_qscintilla-qt5() {
  pkgdesc="A port to Qt5 of Neil Hodgson's Scintilla C++ editor class"
  depends=('qt5-base')

  cd "QScintilla-gpl-${pkgver}/Qt4Qt5"
  make DESTDIR="${pkgdir}" INSTALL_ROOT="${pkgdir}" install

  cd "../designer-Qt4Qt5"
  make DESTDIR="${pkgdir}" INSTALL_ROOT="${pkgdir}" install
}

package_python-qscintilla-qt5-common() {
  pkgdesc="Common python qscintilla bindings files shared between python-qscintilla-qt5 and python2-qscintilla-qt5"
  depends=('qscintilla-qt5')

  cd "QScintilla-gpl-${pkgver}/Python"
  make DESTDIR="${pkgdir}" INSTALL_ROOT="${pkgdir}" install

  # provided by python-qscintilla
  rm -r "${pkgdir}/usr/lib/python3.4/site-packages/PyQt5/"
}

package_python-qscintilla-qt5() {
  pkgdesc="Python 3.x bindings for QScintilla2"
  depends=('python-qscintilla-qt5-common' 'python-pyqt5')

  cd "QScintilla-gpl-${pkgver}/Python"
  install -Dm755 Qsci.so "${pkgdir}/usr/lib/python3.4/site-packages/PyQt5/Qsci.so"
}

package_python2-qscintilla-qt5() {
  pkgdesc="Python 2.x bindings for QScintilla2"
  depends=('python-qscintilla-qt5-common' 'python2-pyqt5')

  cd "QScintilla-gpl-${pkgver}/Python2"
  install -Dm755 Qsci.so "${pkgdir}/usr/lib/python2.7/site-packages/PyQt5/Qsci.so"
}
