# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: judd <jvinet@zeroflux.org>

pkgname=flex
pkgver=2.6.4
pkgrel=3
pkgdesc="A tool for generating text-scanning programs"
arch=('x86_64')
url="https://github.com/westes/flex"
license=('custom')
groups=('base-devel')
depends=('glibc' 'm4' 'sh')
makedepends=('help2man')
source=("https://github.com/westes/flex/releases/download/v$pkgver/flex-$pkgver.tar.gz"{,.sig}
        "flex-pie.patch")
md5sums=('2882e3179748cc9f9c23ec593d6adc8d'
         'SKIP'
         '0a8e8242b37c57b0bc0c6f673bceb5b7')
validpgpkeys=('56C67868E93390AA1039AD1CE4B29C8D64885307') # Will Estes

prepare() {
  cd "$pkgname-$pkgver"
  patch -p1 -i "$srcdir"/flex-pie.patch
  autoreconf
}

build() {
  cd "$pkgname-$pkgver"
  ./configure --prefix=/usr
  make
}

check() {
  cd "$pkgname-$pkgver"

  # cxx_restart fails - https://github.com/westes/flex/issues/98
  make -k check || true
}

package() {
  cd "$pkgname-$pkgver"

  make DESTDIR="$pkgdir" install
  ln -s flex "${pkgdir}/usr/bin/lex"

  install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/license.txt"
}
