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

_realname=prjtrellis
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.r1002.0e6a320
pkgrel=1
pkgdesc="Documenting the Lattice ECP5 bit-stream format (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/YosysHQ/prjtrellis"
license=('MIT')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-clang"
             "git")

_commit="0e6a3204"
source=("${_realname}::git://github.com/YosysHQ/${_realname}.git#commit=${_commit}"
        "prjtrellis-db::git://github.com/YosysHQ/prjtrellis-db")
sha256sums=('SKIP'
            'SKIP')

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

prepare () {
  cd "${_realname}"
  git submodule init
  git config submodule.database.url $srcdir/prjtrellis-db
  git submodule update
}

build() {
  cd "${srcdir}/${_realname}"/libtrellis

  MSYS2_ARG_CONV_EXCL='-DCMAKE_INSTALL_PREFIX=' cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_C_COMPILER=clang \
    -DCMAKE_CXX_COMPILER=clang++ \
    -DCMAKE_PREFIX_PATH=${MINGW_PREFIX} \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    .
  make
}

check() {
  cd "${srcdir}/${_realname}"/libtrellis
  for item in ecpbram ecpmulti ecppack ecppll ecpunpack; do
    echo "> Check $item"
    ./"$item" --help
  done
}

package() {
  cd "${srcdir}/${_realname}"/libtrellis
  make DESTDIR="${pkgdir}" install

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