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

_hkgname=hledger-lib
pkgname=haskell-hledger-lib
pkgver=1.15.2
pkgrel=1
pkgdesc="Core data types, parsers and functionality for the hledger accounting tools"
url="http://hledger.org"
license=("GPL")
arch=('x86_64')
depends=('ghc-libs' 'haskell-ansi-terminal' 'haskell-base-compat-batteries' 'haskell-blaze-markup'
         'haskell-call-stack' 'haskell-cassava' 'haskell-cassava-megaparsec' 'haskell-cmdargs'
         'haskell-data-default' 'haskell-decimal' 'haskell-easytest' 'haskell-extra' 'haskell-fgl'
         'haskell-file-embed' 'haskell-glob' 'haskell-hashtables' 'haskell-megaparsec'
         'haskell-old-time' 'haskell-parser-combinators' 'haskell-pretty-show' 'haskell-regex-tdfa'
         'haskell-safe' 'haskell-split' 'haskell-tabular' 'haskell-timeit' 'haskell-uglymemo'
         'haskell-utf8-string')
makedepends=('ghc' 'haskell-doctest')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('b5d5a8f12210732d0e65fe7f7c6dd78318d3ab552b8574d1e6dc07e765199c5e68a9589a630565d30ca7d6185dac79f4fcaa2b209d196771135a07c84977770e')

prepare() {
    # It does nothing
    sed -e '/mtl-compat/d' \
        -i ${_hkgname}-${pkgver}/${_hkgname}.cabal
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid
    runhaskell Setup build
    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
}

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"
    rm -f "${pkgdir}/usr/share/doc/${pkgname}/LICENSE"
}
