# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Vesa Kaihlavirta <vegai@iki.fi>
# Contributor: Philip Nilsson <pnilsson@nullref.se>

pkgname=alex
pkgver=3.3.0.0
pkgrel=3
pkgdesc='Lexical analyser generator for Haskell'
arch=(x86_64 aarch64)
url='https://hackage.haskell.org/package/alex'
license=(BSD-3-Clause)
depends=(ghc-libs)
makedepends=(ghc happy)
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('e7755273406d69cd2a30294d055836cd188f6435fdf7b621fad3f5dd6b0f7f37e050985f8768037d55af92a3bcd4a62d512561fd0c4408e85ff07fdc25f3e0ce')

build() {
  cd $pkgname-$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 \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie'
  runhaskell Setup build $MAKEFLAGS
}

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

package() {
  cd $pkgname-$pkgver
  runhaskell Setup copy --destdir="$pkgdir"
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/alex/

  # Doc only contains the license
  rm -rf "$pkgdir/usr/share/doc"
}

# getver: hackage.haskell.org/package/alex/changelog
# vim: ts=2 sw=2 et:
