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

pkgname=hledger
pkgver=1.21
pkgrel=30
pkgdesc="Command-line interface for the hledger accounting system"
url="http://hledger.org"
license=("GPL")
arch=('x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-ansi-terminal' 'haskell-base-compat-batteries'
         'haskell-cmdargs' 'haskell-data-default' 'haskell-decimal' 'haskell-diff'
         'haskell-hashable' 'haskell-hledger-lib' 'haskell-lucid' 'haskell-math-functions'
         'haskell-megaparsec' 'haskell-old-time' 'haskell-regex-tdfa'
         'haskell-safe' 'haskell-shakespeare' 'haskell-split' 'haskell-tabular' 'haskell-tasty'
         'haskell-temporary' 'haskell-unordered-containers' 'haskell-utf8-string'
         'haskell-utility-ht' 'haskell-wizards')
makedepends=('ghc' 'haskell-extra' 'haskell-timeit')
source=("https://hackage.haskell.org/packages/archive/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('4ae5e9dc0160759f85b5c9d9ae4d4faeb2a63a41dd5376e658ac6fa13ff2b72b5e808ed0d52ed50d83e9bade3ce8839c23aabbbf6baccf236b579b07898dd3ba')

build() {
    cd $pkgname-$pkgver
    runhaskell Setup configure -O --enable-shared --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 \
            -fterminfo -fthreaded --ghc-option='-pie'
    LC_CTYPE=en_US.UTF-8 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

    install -Dm644 hledger.1 -t "$pkgdir"/usr/share/man/man1/
}
