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

_realname=iverilog
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=12.0
pkgrel=1
epoch=1
pkgdesc="Icarus Verilog, is a Verilog simulation and synthesis tool (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/steveicarus/iverilog"
msys2_references=(
  'archlinux: iverilog'
)
license=('spdx:GPL-2.0-or-later')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=(
  "${MINGW_PACKAGE_PREFIX}-readline"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-ghostscript"
  "${MINGW_PACKAGE_PREFIX}-gperf"
  "${MINGW_PACKAGE_PREFIX}-bzip2"
  "${MINGW_PACKAGE_PREFIX}-zlib"
)
source=("https://github.com/steveicarus/iverilog/archive/v${pkgver/./_}/${_realname}-${pkgver}.tar.gz"
        001-fix-string-literal.patch::https://github.com/steveicarus/iverilog/commit/23e51ef7.patch)
sha256sums=('a68cb1ef7c017ef090ebedb2bc3e39ef90ecc70a3400afb4aa94303bc3beaa7d'
            '836108d5f5977b25d873c2521f7ae3ad274feb3f3ec40efb0cb194d28213e3d2')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver/./_}"
  patch -p1 -i "${srcdir}"/001-fix-string-literal.patch

  ./autoconf.sh
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver/./_}/configure \
    --prefix=${MINGW_PREFIX}

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check
#  git clone https://github.com/steveicarus/ivtest.git
#  cd ivtest
#  ./regress
}

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

  install -Dm644 "${srcdir}/${_realname}-${pkgver/./_}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
