# Maintainer: Wu Zhenyu <wuzy01@qq.com>

_realname=scrcpy
pkgbase="mingw-w64-${_realname}"
pkgname="$MINGW_PACKAGE_PREFIX-${_realname}"
pkgver=3.3.3
pkgrel=1
pkgdesc='Display and control your Android device (mingw-w64)'
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/Genymobile/scrcpy'
msys2_references=(
  'archlinux: scrcpy'
)
license=('spdx:Apache-2.0')
depends=(
  "$MINGW_PACKAGE_PREFIX-android-tools"
  "$MINGW_PACKAGE_PREFIX-ffmpeg"
  "$MINGW_PACKAGE_PREFIX-SDL2"
  "$MINGW_PACKAGE_PREFIX-libusb"
)
makedepends=(
  "$MINGW_PACKAGE_PREFIX-cc"
  "$MINGW_PACKAGE_PREFIX-meson"
  "$MINGW_PACKAGE_PREFIX-pkgconf"
)
source=("$url/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "$url/releases/download/v${pkgver}/${_realname}-server-v${pkgver}"
        0001-Help-scrcpy-find-the-server-and-icon-file.patch)
sha256sums=('87fcd360a6bb6ca070ffd217bd33b33fb808b0a1572b464da51dde3fd3f6f60e'
            '7e70323ba7f259649dd4acce97ac4fefbae8102b2c6d91e2e7be613fd5354be0'
            'ab91eeea32b026505f51a1cad3c4eb45f28ba1d8a8f8ca92a4f55063ce9a8152')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i "${srcdir}/0001-Help-scrcpy-find-the-server-and-icon-file.patch"
}

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype release \
    -Dprebuilt_server="../${_realname}-server-v${pkgver}" \
    ../"${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

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

  ${MINGW_PREFIX}/bin/meson.exe install --destdir="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}"/LICENSE -t \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
