# Maintainer: umarcor <unai.martinezcorral@ehu.eus>

_realname=verilator
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.210
pkgrel=1
pkgdesc="The fastest free Verilog HDL simulator (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.veripool.org/projects/verilator/wiki/Intro"
license=("LGPL")
groups=("${MINGW_PACKAGE_PREFIX}-eda")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "flex")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")

source=(
  "${_realname}::https://codeload.github.com/${_realname}/${_realname}/tar.gz/v${pkgver}"
)
sha256sums=(
  '3a2e6f27a5d80116a268ba054a3be61aca924bc54c5556ea25e75ee974201abb'
)

prepare() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  sh autoconf
}

build() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  cp /usr/include/FlexLexer.h src/

  export MSYS2_ARG_CONV_EXCL="-DDEFENV"

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
