# Maintainer: Jonathan Armstrong <jda2158@gmail.com>

_realname=rkdeveloptool
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=r70.21b25fd
pkgrel=1
_commit='21b25fd4a70331819b557fe93015b635b9594543'
pkgdesc="rkdeveloptool is a tool from Rockchip to communicate with Rockusb devices (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='http://opensource.rock-chips.com/wiki_Rkdeveloptool'
license=('spdx:GPL-2.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             git)
depends=(${MINGW_PACKAGE_PREFIX}-'libusb')
source=("rkdeveloptool"::"git+https://github.com/rockchip-linux/rkdeveloptool.git#commit=$_commit")
sha256sums=('SKIP')
install=driver-instructions.install

# updates pkgver variable since we are using git commit
pkgver() {
    cd "${srcdir}/${_realname}"
    printf 'r%s.%s' "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  aclocal
  autoreconf -i
  autoheader
  automake --add-missing
}

build() {
  cd "${srcdir}/${_realname}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"
  
  ../rkdeveloptool/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}"

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}/license.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
