# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=markdown-unlit
pkgname=haskell-markdown-unlit
pkgver=0.6.0
pkgrel=69
pkgdesc="Literate Haskell support for Markdown"
url="https://github.com/sol/markdown-unlit"
license=('MIT')
arch=('x86_64' 'aarch64')
depends=('ghc-libs' 'haskell-base-compat')
makedepends=('ghc' 'haskell-hspec' 'haskell-hspec-discover' 'haskell-silently'
             'haskell-stringbuilder' 'haskell-temporary')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('a1d7179ee82635c5fc07a39fd47b8ec288b260844ac3a90038ea97c7a22c170f2e9db0c72ad538242cbe1ae23b75fd27319650142d0f5bf47793954c3b45639a')

build() {
    cd $_hkgname-$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
    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 $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$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 "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
