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

pkgname=flex
pkgver=2.6.4
pkgrel=4
pkgdesc="A tool for generating text-scanning programs"
arch=('i686' 'x86_64')
url="https://github.com/westes/flex"
msys2_references=(
  "anitya: 819"
  "cpe: cpe:2.3:a: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)
sha256sums=('e87aae032bf07c26f85ac0ed3250998c37621d95f8bd748b31f15b33c45ee995')

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

  ./autogen.sh
}

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

  local CYGWIN_CHOST="${CHOST/-msys/-cygwin}"
  ./configure \
    --build=${CYGWIN_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
}
