# Contributor: David Runge <dave@sleepmap.de>
# Contributor: speps <speps at aur dot archlinux dot org>
# Contributor: Alexander Fehr <pizzapunk gmail com>
# Contributor: dorphell <dorphell@archlinux.org>
# Contributor: Andreas Grapentin <andreas@grapentin.org>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Contributor: Aditya Som <icarious@hacari.org>
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>
# Contributor: bill-auger <bill-auger@programmer.net>


pkgname=sylpheed
pkgver=3.7.0_3.8.0beta1
# _libnsl_ver=3 # WIP - pin to coupled dependency versions
pkgrel=1
pkgdesc="Lightweight and user-friendly e-mail client"
arch=(armv7h i686 x86_64)
url=https://sylpheed.sraoss.jp/en/
license=(GPL)
depends=(compface gpgme gtkspell libnsl)
# WIP - pin to coupled dependency versions
# depends=( ${depends[*]/libnsl/libnsl>=${_libnsl_ver}} ) # pin to coupled dependency versions
# depends+=( ${depends[*]/libnsl/libnsl.so} ) # pin to coupled dependency versions
depends+=( libnsl.so ) # pin to coupled dependency versions
makedepends=(openssl)
_BETA_RELEASE=1
if (( ! _BETA_RELEASE ))
then # stable release versions like: N.N.N (eg: 3.7.0)
  source=(https://sylpheed.sraoss.jp/${pkgname}/v${pkgver%.*}/${pkgname}-${pkgver}.tar.bz2{,.asc})
  sha256sums=(eb23e6bda2c02095dfb0130668cf7c75d1f256904e3a7337815b4da5cb72eb04 SKIP)
else # beta release versions like: prevver-betaver (eg: 3.7.0-3.8.0beta1)
  _beta_prev_ver=${pkgver/_*/}                                                          # eg: 3.7.0
  _beta_ver=${pkgver/*_/}                                                               # eg: 3.8.0beta1
  _beta_dir=$(sed 's|.*_\([0-9]\+\.[0-9]\+\)\.[0-9]\+beta[0-9]\+|\1beta|' <<<${pkgver}) # eg: 3.8beta
  source=(https://sylpheed.sraoss.jp/${pkgname}/v${_beta_prev_ver%.*}/${pkgname}-${_beta_prev_ver}.tar.bz2{,.asc} # prev release
          https://sylpheed.sraoss.jp/${pkgname}/v${_beta_dir}/${pkgname}-${pkgver/_/-}.patch.bz2{,.asc})          # beta patches
  sha256sums=(eb23e6bda2c02095dfb0130668cf7c75d1f256904e3a7337815b4da5cb72eb04 SKIP
              d7c23c1f765c6e815fdf2e8c318bfc8eee8590a75fd3c61569296da67fdf5c91 SKIP)
fi
validpgpkeys=(8CF3A5AC417ADE72B0AA4A835024337CC00C2E26) # Hiroyuki Yamamoto


prepare() {
  (( ! _BETA_RELEASE )) && cd "${srcdir}"/${pkgname}-${pkgver}         ||
                           cd "${srcdir}"/${pkgname}-${_beta_prev_ver}

  # patch for enchant >= 2.1.3
  # https://www.archlinux.org/todo/enchant-221-rebuild/
  sed -i 's,enchant/,enchant-2/,g' src/compose.c
  sed -i 's/ enchant/ enchant-2/g' configure
}

build()
{
  (( ! _BETA_RELEASE )) && cd "${srcdir}"/${pkgname}-${pkgver}         ||
                           cd "${srcdir}"/${pkgname}-${_beta_prev_ver}

  ./configure --prefix=/usr            \
              --enable-maintainer-mode \
              --enable-ldap
  make

  # Build Attachment-Tool Plug-in
  cd plugin/attachment_tool && make
}

package()
{
  (( ! _BETA_RELEASE )) && cd "${srcdir}"/${pkgname}-${pkgver}         ||
                           cd "${srcdir}"/${pkgname}-${_beta_prev_ver}

  make DESTDIR="$pkgdir/" LDFLAGS+="/usr/lib/enchant-2" install

  # Install Attachment-Tool Plug-in
  cd plugin/attachment_tool
  make DESTDIR="$pkgdir/" install-plugin
}
