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

pkgname=flex
pkgver=2.6.4
pkgrel=3
pkgdesc="A tool for generating text-scanning programs"
arch=('i686' 'x86_64')
url="https://github.com/westes/flex"
license=('custom')
depends=('m4' 'sh' 'libiconv' 'libintl')
makedepends=('libiconv-devel' 'gettext-devel' 'autotools' 'gcc')
options=('staticlibs')
source=(https://github.com/westes/flex/releases/download/v${pkgver}/${pkgname}-${pkgver}.tar.gz
        flex-2.5.38-msys2.patch)
sha256sums=('e87aae032bf07c26f85ac0ed3250998c37621d95f8bd748b31f15b33c45ee995'
            '6ffcb831faa9c29c44b717825744887ea5b3945605153831339e0b8a37cbe5c3')

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

  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}

  make check
}

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

  make DESTDIR=${pkgdir} install
  if [ ! -f ${pkgdir}/usr/bin/flex++.exe ]; then
	cp -f ${pkgdir}/usr/bin/flex.exe ${pkgdir}/usr/bin/flex++.exe
  fi
  if [ ! -f ${pkgdir}/usr/bin/lex.exe ]; then
	cp -f ${pkgdir}/usr/bin/flex.exe ${pkgdir}/usr/bin/lex.exe
  fi

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