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

_realname=iverilog
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=11.0.r8897.d8cb29f6
pkgrel=1
epoch=1
pkgdesc="Icarus Verilog, is a Verilog simulation and synthesis tool (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://iverilog.icarus.com/"
license=('GPLv2+')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=("${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-gcc"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-ghostscript"
             'git')

# NOTE: MSYS2 support was improved/fixed in 'master' (2020/12/04).
# When 12.0 is tagged/released, this should be changed to use a tarball instead.
_commit="d8cb29f6"
source=("${_realname}::git://github.com/steveicarus/iverilog.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "11.0.r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

prepare() {
  cd "${srcdir}/${_realname}"
  sh autoconf.sh
}

build() {
  cd "${srcdir}/${_realname}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}
  make
}

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

package() {
  cd "${srcdir}/${_realname}"
  make DESTDIR="${pkgdir}" install
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"
  mv "${pkgdir}${MINGW_PREFIX}"/*.pdf "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"

  _licenses="${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  mkdir -p "${_licenses}"
  install -m 644 COPYING "${_licenses}"
}
