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

_hkgname=lifted-async
pkgname=haskell-lifted-async
pkgver=0.10.2.5
pkgrel=24
pkgdesc="Run lifted IO operations asynchronously and wait for their results"
url="https://github.com/maoe/lifted-async"
license=('BSD')
arch=('x86_64' 'aarch64')
depends=('ghc-libs' 'haskell-async' 'haskell-constraints' 'haskell-lifted-base'
         'haskell-monad-control' 'haskell-transformers-base')
makedepends=('ghc')
checkdepends=('haskell-hunit' 'haskell-tasty' 'haskell-tasty-expected-failure'
              'haskell-tasty-hunit' 'haskell-tasty-th')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('970578cbef4eebd9dd4414d77e7310abc99ea4f6af392d6d19e1a7f3a15cf8c03a4df02882a4294a7defc37240a656abe0c55c3120cdbeaf6323e04e7ff96f60')

build() {
    cd $_hkgname-$pkgver

    if (( CHECKFUNC )); then
        _opts=('--enable-tests')
    else
        _opts=('--disable-tests')
    fi

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname "${_opts[@]}" \
        --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
}
