# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>

pkgname=pandoc-plot
pkgver=1.9.1
pkgrel=243
pkgdesc="A Pandoc filter to include figures generated from code blocks using your plotting toolkit of choice."
url="https://github.com/LaurentRDC/pandoc-plot#readme"
license=("GPL")
arch=('x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-data-default' 'haskell-gitrev' 'haskell-hashable'
         'haskell-lifted-async' 'haskell-lifted-base' 'haskell-optparse-applicative'
         'haskell-pandoc' 'haskell-pandoc-types' 'haskell-shakespeare' 'haskell-tagsoup'
         'haskell-typed-process' 'haskell-yaml')
makedepends=('ghc' 'haskell-hspec-expectations' 'haskell-tasty' 'haskell-tasty-hspec'
             'haskell-tasty-hunit')
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('a34a08faf483ed7c9c5e7c439ac275077b9262bb3384d1f551e47d6aa59dd434')

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 \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie' 

  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
}

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"
  install -D -m644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
