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

_realname=icestorm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.r777.c495861
pkgrel=1
pkgdesc="Simple tools for analyzing and creating bitstream files for Lattice iCE40 FPGAs (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://www.clifford.at/icestorm/"
license=("ISC")
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libftdi")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "flex"
             "git")

_commit="c495861c"
source=("icestorm::git://github.com/YosysHQ/${_realname}.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "icestorm"
  printf "0.0.r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

build() {
  cd "${srcdir}/${_realname}"
  sed -i "s/-ggdb //;" Makefile
  make STATIC=1
}

package() {
  cd "${srcdir}/${_realname}"
  mkdir -p "${pkgdir}${MINGW_PREFIX}"
  make \
    PREFIX=${MINGW_PREFIX} \
    DESTDIR="${pkgdir}" \
    install

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