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

_hkgname=xcffib
pkgname=haskell-xcffib
pkgver=1.6.2
pkgrel=10
pkgdesc="A cffi-based python binding for X"
url="https://github.com/tych0/xcffib"
license=('Apache-2.0')
arch=('x86_64' 'aarch64')
depends=('ghc-libs' 'haskell-attoparsec' 'haskell-either' 'haskell-filemanip'
         'haskell-optparse-applicative' 'haskell-split' 'haskell-xcb-types')
makedepends=('ghc' 'uusi' 'haskell-hunit' 'haskell-test-framework'
             'haskell-test-framework-hunit')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('32243acb9a1793b9a617d0d65fa695b4d3b5a12e6c6d029180893208be0338e1baa9b386a0dff5dad4aea6567227d0e5a4cead0527866db45d818c4e3f04ffd5')

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
}
