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

_hkgname=resolv
pkgname=haskell-resolv
pkgver=0.2.0.2
pkgrel=201
pkgdesc="Domain Name Service (DNS) lookup via the libresolv standard library routines"
url="https://github.com/hvr/resolv"
license=('GPL')
arch=('x86_64')
depends=('ghc-libs' 'haskell-base16-bytestring')
makedepends=('ghc' 'haskell-tasty' 'haskell-tasty-hunit')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('df61ab0e3d1c2faa525271416fca3976378ac6fcbaf9f729c7ed3f07454625a03f6aafcd2fd56f2001bc61d365ccb2b4c4f2bd693696576450df20a20e7102df')

build() {
    cd $_hkgname-$pkgver
    
    LDFLAGS="${LDFLAGS/-Wl,-z,pack-relative-relocs/}" \
    runhaskell Setup configure -O --enable-shared --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"
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
