# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

pkgname=pandoc-crossref
pkgver=0.3.12.0
pkgrel=1
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-mtl' 'haskell-microlens-th' 'haskell-open-browser'
         'haskell-optparse-applicative' 'pandoc' 'haskell-pandoc-types' 'haskell-roman-numerals'
         'haskell-syb' 'haskell-utility-ht')
makedepends=('ghc' 'haskell-hspec')
conflicts=('haskell-pandoc-crossref')
replaces=('haskell-pandoc-crossref')
source=("$pkgname-$pkgver.tar.gz::https://github.com/lierdakil/pandoc-crossref/archive/v$pkgver.tar.gz")
sha512sums=('5e2dbd5d63d0a6b295da9efc97273d3d2c9a08f50ddda3df3f1df31b112be082233011e632c551be34043d50114f7d2373219ef68ffa1fa59a9fb4d31b9351d5')

build() {
    cd $pkgname-$pkgver
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir="/usr/share/doc/${pkgname}" --enable-tests --datasubdir="$pkgname" \
        --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
}

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
}
