# Maintainer: Sergej Pupykin <arch+pub@sergej.pp.ru>
# Previous maintainer: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>

pkgbase='swift'
pkgname=('swift-im' 'swiften')
pkgver=4.0.2
pkgrel=6
arch=('x86_64')
pkgdesc='XMPP client written in C++ with Qt and Swiften'
url="http://swift.im/"
license=('GPL3')
makedepends=('python2' 'openssl' 'boost' 'qt5-base' 'qt5-multimedia'
             'qt5-webkit' 'qt5-x11extras' 'qt5-tools' 'qt5-svg')
source=("http://swift.im/downloads/releases/$pkgbase-$pkgver/$pkgbase-$pkgver.tar.gz"
        'swift-4.0.2-boost-1.69-compatibility.patch'
        'swift-4.0.2-qt-5.11-compatibility.patch'
        'swift-4.0.2-qt-5.15-compatibility.patch'
        repro-builds.patch)
sha256sums=('1c7c9fb981ecb9b589890c36523dbbabde2f0a708f71a66eb71e9526bf8e0a70'
            'd166362c146f859ec89c535f8676ac12c6e51e281e6c88c5e36b25e4ea5655d1'
            '7970844d39c38ff6d36c2d1e26c145495ff8f5a5a31a399467eca66854dc3e67'
            '18feef21870b0f441a6fb0faf7b35a826cfec4fe4a1d717bbb1c373a8c1ccb95'
            '90c586cc67dc9831a0e8ce75c12478f674b5d429dd46dae4c47f241d7902beb1')

# Those options need to be consistent between each scons invocation.
_scons_options=(max_jobs=1 optimize=1 debug=0 swiften_dll=1 cflags="${CPPFLAGS} ${CFLAGS}" cxxflags="${CPPFLAGS} ${CFLAGS}" linkflags="${LDFLAGS}")

prepare() {
  cd $pkgbase-$pkgver
  patch -p1 -i ../swift-4.0.2-boost-1.69-compatibility.patch
  patch -p1 -i ../swift-4.0.2-qt-5.11-compatibility.patch
  patch -p1 -i ../swift-4.0.2-qt-5.15-compatibility.patch
  # https://github.com/swift/swift/pull/129
  patch -p1 -i ../repro-builds.patch
}

build() {
  cd $pkgbase-$pkgver
  ./scons "${_scons_options[@]}" Swift Swiften
}

package_swift-im() {
  pkgdesc='XMPP client written in C++ with Qt and Swiften'
  depends=("swiften=$pkgver" 'qt5-base' 'qt5-multimedia' 'qt5-webkit'
           'qt5-x11extras' 'qt5-svg' 'libxss' 'hicolor-icon-theme')

  cd $pkgbase-$pkgver
  ./scons "${_scons_options[@]}" SWIFT_INSTALLDIR="$pkgdir"/usr/ "$pkgdir"/usr/
}

package_swiften() {
  pkgdesc='XMPP library written in C++ with Boost'
  depends=('boost-libs' 'libxml2' 'libidn' 'avahi' 'openssl')

  cd $pkgbase-$pkgver
  ./scons "${_scons_options[@]}" SWIFTEN_INSTALLDIR="$pkgdir"/usr/ "$pkgdir"/usr/
}
