# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=flex
pkgver=2.5.39
pkgrel=4
pkgdesc="A tool for generating text-scanning programs"
arch=('i686' 'x86_64')
url="http://flex.sourceforge.net"
license=('custom')
groups=('base' 'base-devel')
depends=('m4' 'sh' 'libiconv' 'libintl')
makedepends=('libiconv-devel' 'gettext-devel')
options=('staticlibs')
install=flex.install
source=(http://downloads.sourceforge.net/sourceforge/flex/flex-$pkgver.tar.bz2
        2.5.37-vpath.patch
        flex-2.5.38-msys2.patch)
md5sums=('77d44c6bb8c0705e0017ab9a84a1502b'
         '68f74b4a02893b4382e4fd42e1f0176a'
         '78baff4c3bb33a255bf678fb8a4b54b0')

prepare() {
  cd $srcdir/$pkgname-$pkgver

  patch -p2 -i $srcdir/2.5.37-vpath.patch
  patch -p1 -i $srcdir/flex-2.5.38-msys2.patch

  ./autogen.sh
}

build() {
  cd $srcdir/$pkgname-$pkgver
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --without-libiconv-prefix \
    --without-libintl-prefix \
    --enable-static \
    --disable-shared
  make
}

check() {
  cd $srcdir/$pkgname-$pkgver

  # these tests used features removed in bison-2.6
  sed -i -e '/test-bison-yylloc/d' -e '/test-bison-yylval/d' tests/Makefile.in

  make check
}

package() {
  cd $srcdir/$pkgname-$pkgver

  make DESTDIR=$pkgdir install
  cp -f $pkgdir/usr/bin/flex.exe $pkgdir/usr/bin/flex++.exe
  cp -f $pkgdir/usr/bin/flex.exe $pkgdir/usr/bin/lex.exe

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