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

_hkgname=cborg
pkgname=haskell-cborg
pkgver=0.2.10.0
pkgrel=76
pkgdesc="Concise Binary Object Representation (CBOR)"
url="https://github.com/well-typed/cborg"
license=('BSD-3-Clause')
arch=('x86_64' 'aarch64')
depends=('ghc-libs' 'haskell-half' 'haskell-primitive')
makedepends=('ghc' 'uusi' 'haskell-aeson' 'haskell-base-orphans' 'haskell-base16-bytestring'
             'haskell-base64-bytestring' 'haskell-quickcheck' 'haskell-scientific' 'haskell-tasty'
             'haskell-tasty-hunit' 'haskell-tasty-quickcheck' 'haskell-vector')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('57c375123e36b662d65b9c477a84a8f55bfa8dce0018410ee023080890a107e0b0ba854f89cd64333eeb93d508ab35e5da9f6fb77bd129bb2d0fcc5f27bce0b0')

prepare() {
    cd $_hkgname-$pkgver
    uusi -u QuickCheck -u tasty-quickcheck
}

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