# Maintainer (Arch): Daniel Landau <daniel+aur@landau.fi>
# Contributor (Arch): sekret, mail=$(echo c2VrcmV0QHBvc3Rlby5zZQo= | base64 -d)
# Contributor (Arch): mmm
# Contributor (Arch): bslackr <brendan at vastactive dot com>
# Contributor (Arch): Jan "heftig" Steffens <jan.steffens@gmail.com>
# Contributor (Arch): Thomas Dziedzic < gostrc at gmail >
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>
# Contributor: bill-auger <bill-auger@programmer.net>


pkgname=lightspark
pkgver=0.8.2
pkgrel=2
pkgdesc="An open source flash player implementation"
arch=('armv7h' 'i686' 'x86_64')
url=http://lightspark.github.io/
license=('LGPL3')

depends=('boost-libs' 'cairo' 'curl' 'desktop-file-utils' 'ffmpeg' 'glew' \
         'glibmm' 'llvm' 'pango' 'rtmpdump' 'sdl2_mixer'                  )
optdepends=('gnash-gtk: Gnash fallback support')
makedepends=('cmake' 'nasm' 'boost')
conflicts=('lightspark-git')
install=lightspark.install
source=(https://github.com/lightspark/lightspark/archive/${pkgver}.tar.gz)
sha256sums=('05595a3085bf76ea5c9723f128dcadead5ccf38e177c3a456901ccee3265548a')

# FIXME: FTBS against boost 1.72.0 - see note in prepare()
source+=(include-boostserialization.patch)
sha256sums+=('669b021aebb1bd0f4f8f7c029b963c575eaf3cdee1de194144bc8c9b8b61d2e5')


_version_constraint() # (dep_pkgname)
{
  local dep_pkgname=$1
  local version=$(pacman -S --print-format='%v' ${dep_pkgname} | tail -n 1)
  version=${version%-*}
  local version_inc=${version%.*}.$(( ${version##*.} + 1 ))

  echo -n "${dep_pkgname}>=${version}" "${dep_pkgname}<${version_inc}"
}


prepare()
{
  cd "${srcdir}"/${pkgname}-${pkgver}/

  [ -d build ] && rm -rf build/* || mkdir build

  # FIXME: FTBS against boost 1.72.0 - next upstream release should have this patch applied
  # https://labs.parabola.nu/issues/2568
  # https://github.com/lightspark/lightspark/pull/409
  # i686 still has boost-libs 1.71.0
  [[ "${CARCH}" != 'i686' ]] && patch -Np1 < "${srcdir}"/include-boostserialization.patch
}

build()
{
  cd "${srcdir}"/${pkgname}-${pkgver}/build

  cmake -DCMAKE_INSTALL_PREFIX=/usr         \
        -DCOMPILE_PLUGIN=1                  \
        -DCMAKE_BUILD_TYPE=Release          \
        -DGNASH_EXE_PATH=/usr/bin/gtk-gnash \
        -DAUDIO_BACKEND="pulseaudio sdl"   ..
  make CFLAGS=-Wno-dev
}

package()
{
  depends+=( $(_version_constraint 'boost-libs') )

  cd "${srcdir}"/${pkgname}-${pkgver}/build

  make DESTDIR="${pkgdir}/" install

  local _boost_ver=$(pacman -S --print-format='%v' boost-libs)
  depends+=("boost-libs>=${_boost_ver}" "boost-libs<$((${_boost_ver%%.*} + 1))")
}

