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

_hkgname=http-api-data
pkgname=haskell-http-api-data
pkgver=0.6.1
pkgrel=36
pkgdesc="Converting to/from HTTP API data like URL pieces, headers and query parameters."
url="https://github.com/fizruk/http-api-data"
license=('BSD-3-Clause')
arch=('x86_64' 'aarch64')
depends=('ghc-libs' 'haskell-cookie' 'haskell-hashable' 'haskell-http-types' 'haskell-tagged'
         'haskell-text-iso8601' 'haskell-time-compat' 'haskell-unordered-containers'
         'haskell-uuid-types')
makedepends=('ghc' 'haskell-hspec' 'haskell-hunit' 'haskell-quickcheck'
             'haskell-quickcheck-instances')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('b4f19d45f82307a3fbf45cab716524f66fe8921945f93e7e951a1b0db0a39308425bfce9ee08c37f64a184bbc3575e68fed40aa0fc7923698ad0742b17573295')

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 \
            -f-use-text-show
    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
}
