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

_hkgname=microlens-aeson
pkgname=haskell-microlens-aeson
pkgver=2.5.2
pkgrel=142
pkgdesc="Law-abiding lenses for Aeson, using microlens"
url="https://github.com/fosskers/microlens-aeson/"
license=('MIT')
arch=('x86_64' 'aarch64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-attoparsec' 'haskell-hashable' 'haskell-microlens'
         'haskell-scientific' 'haskell-vector')
makedepends=('ghc' 'uusi' 'haskell-tasty' 'haskell-tasty-hunit')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('b2d159e30b96655e2403bc09db8854e2b59e663b7a9ddfe352f99f14466e1643ca3dcfb04c266f36dccf3288a22ffde9b886f3f3373edf68a49fb1cdfefc209f')

prepare() {
    cd $_hkgname-$pkgver
    gen-setup
}

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
}
