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

_realname=scopehal-apps
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.0.r1213.g5855e49
pkgrel=1
pkgdesc="scopehal-apps: applications for libscopehal (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url="https://github.com/azonenberg/scopehal-apps"
license=('BSD-3-Clause')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=(
  "${MINGW_PACKAGE_PREFIX}-glm"
  "${MINGW_PACKAGE_PREFIX}-libsigc++"
  "${MINGW_PACKAGE_PREFIX}-gtkmm3"
  "${MINGW_PACKAGE_PREFIX}-yaml-cpp"
  "${MINGW_PACKAGE_PREFIX}-glew"
  "${MINGW_PACKAGE_PREFIX}-ffts"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-gcc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "make"
)

source=("${_realname}::git://github.com/azonenberg/scopehal-apps.git#commit=5855e493")
sha256sums=('SKIP')

pkgver() {
  cd "${_realname}"
  echo '0.0.0.r'"$(git rev-list --count HEAD)"'.g'"$(git describe --all --long | sed 's/^.*-g\(.*\)/\1/')"
}

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

  git remote set-url origin git://github.com/azonenberg/scopehal-apps
  git submodule update --init --recursive

  mkdir build
  cd build
  MSYS2_ARG_CONV_EXCL=-DCMAKE_INSTALL_PREFIX= cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DBUILD_TESTING=OFF \
    ../
  cmake --build .
}

check() {
  "${srcdir}/${_realname}"/build/src/glscopeclient/glscopeclient.exe --help
}

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

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