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

pkgname=uusi
pkgver=0.4.4.0
pkgrel=13
pkgdesc="Tweak .cabal files"
url="https://github.com/berberman/uusi"
license=("MIT")
arch=('x86_64' 'aarch64')
depends=('ghc-libs')
makedepends=('ghc')
checkdepends=('haskell-hunit')
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('eebb4512640f3c19b39e52f490f4929538f9c6ca198f9b09516bb59b78d0ac8043359b65e007b4a44162f793ca6d1b528496b98333196c96ed848b7b0ce48fb2')

build() {
  cd $pkgname-$pkgver

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

  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 \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie'

  runhaskell Setup build $MAKEFLAGS
}

check() {
  cd $pkgname-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $pkgname-$pkgver

  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
