# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=shotcut
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=24.06.26
pkgrel=1
pkgdesc='Cross-platform Qt based Video Editor (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.shotcut.org/'
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-ffmpeg"
         "${MINGW_PACKAGE_PREFIX}-fftw"
         "${MINGW_PACKAGE_PREFIX}-mlt"
         "${MINGW_PACKAGE_PREFIX}-qt6-base"
         "${MINGW_PACKAGE_PREFIX}-qt6-charts"
         "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
         "${MINGW_PACKAGE_PREFIX}-qt6-multimedia"
         "${MINGW_PACKAGE_PREFIX}-qt6-websockets"
         "${MINGW_PACKAGE_PREFIX}-qt6-translations")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-qt6-tools")
source=("https://github.com/mltframework/shotcut/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        0001-fix-translation-on-msys2.patch)
sha256sums=('cd7a90228df954ad1e706940795abf9aff657c7686ce82092f009f9befec7e0b'
            '28becf4b8a4e0fac1221b3b372881a76a95f27af0a28e3d7599efefd0158aae3')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

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

  apply_patch_with_msg \
    0001-fix-translation-on-msys2.patch
}

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

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  # https://github.com/mltframework/shotcut/issues/1275
  export CXXFLAGS+=" -DSHOTCUT_NOUPGRADE"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DSHOTCUT_VERSION=${pkgver} \
      -DWINDOWS_DEPLOY=OFF \
      ../${_realname}-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
