# Maintainer: Jelle van der Waa <jelle@vdwaa.nl>

_hkgname=old-time
pkgname=haskell-old-time
pkgver=1.1.1.0
pkgrel=8
pkgdesc="This package provides the ability to adapt to locale conventions such as date and time formats."
url="https://hackage.haskell.org/package/${_hkgname}"
license=('BSD-3-Clause')
arch=('x86_64' 'aarch64')
depends=('ghc-libs' 'haskell-old-locale')
makedepends=('ghc')
checkdepends=('haskell-tasty' 'haskell-tasty-hunit')
source=(https://hackage.haskell.org/package/${_hkgname}-${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('0b302b9ed45060ecca69f72533e2407b2c5609f206ba3c36f0fd8718f04adc892f6b4f9e67b19d2c32d207ce462df23bd13edbd0e38be05ee1a6ef0abde549d4')

build() {
    cd $_hkgname-$pkgver

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

    LDFLAGS="${LDFLAGS/-Wl,-z,pack-relative-relocs/}" \
    runhaskell Setup configure -O --enable-shared --enable-debug-info --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname "${_opts[@]}" \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid \
            -f-debug
    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
}
