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

_hkgname=hadrian
pkgname=haskell-hadrian
_ghcver=9.4.8
pkgver=0.1.0.0+$_ghcver
pkgrel=17
pkgdesc="GHC build system"
url="https://gitlab.haskell.org/ghc/ghc"
license=("BSD")
arch=('x86_64' 'aarch64')
depends=('ghc-libs' 'haskell-quickcheck' 'haskell-extra' 'haskell-shake'
         'haskell-unordered-containers')
makedepends=('ghc')
source=("https://downloads.haskell.org/~ghc/$_ghcver/ghc-${_ghcver}-src.tar.xz")
sha256sums=('0bf407eb67fe3e3c24b0f4c8dea8cb63e07f63ca0f76cf2058565143507ab85e')

build() {
  cd ghc-$_ghcver/hadrian

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --datasubdir=haskell-hadrian --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie' \
    -fthreaded

  runhaskell Setup build $MAKEFLAGS
}

package() {
  cd ghc-$_ghcver/hadrian

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