# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

pkgname=pandoc-crossref
pkgver=0.3.19
pkgrel=235
pkgdesc="Pandoc filter for cross-references"
url="https://hackage.haskell.org/package/${pkgname}"
license=("GPL2")
arch=('x86_64')
depends=('ghc-libs' 'haskell-data-default' 'haskell-gitrev' 'haskell-microlens'
         'haskell-microlens-ghc' 'haskell-microlens-mtl' 'haskell-microlens-th' 'haskell-open-browser'
         'haskell-optparse-applicative' 'haskell-pandoc' 'haskell-pandoc-types' 'haskell-syb'
         'haskell-utility-ht')
makedepends=('ghc' 'haskell-hspec' 'pandoc-cli')
conflicts=('haskell-pandoc-crossref')
replaces=('haskell-pandoc-crossref')
source=("https://hackage.haskell.org/packages/archive/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('c8d3d61f78a6da084906207fe44ae6179ed6710c390f5c1364ffa76bef864fe2f7d96375e099161939a80bf9d454ae4ae5ac7fa0eea86f08db6b517e1c43d3aa')

build() {
  cd $pkgname-$pkgver
  runhaskell Setup configure -O --enable-shared --enable-debug-info --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid \
    -f-enable_flaky_tests
  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd $pkgname-$pkgver
  runhaskell Setup test --show-details=direct || echo "Tests failed"
}

package() {
  cd $pkgname-$pkgver

  install -D -m744 register.sh   "${pkgdir}/usr/share/haskell/register/${pkgname}.sh"
  install -D -m744 unregister.sh "${pkgdir}/usr/share/haskell/unregister/${pkgname}.sh"
  runhaskell Setup copy --destdir="${pkgdir}"
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
