# Maintainer: Artem Konoplin <konoplin@gmail.com>
# Contributor: Ray Donnelly <mingwandroid@gmail.com>

_realname=mlt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.24.0
pkgrel=3
pkgdesc="An open source multimedia framework (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.mltframework.org"
license=('GPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-dlfcn"
             "${MINGW_PACKAGE_PREFIX}-SDL2"
             "${MINGW_PACKAGE_PREFIX}-fftw"
             "${MINGW_PACKAGE_PREFIX}-ffmpeg"
             "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-swig")
depends=("${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-fftw"
         "${MINGW_PACKAGE_PREFIX}-ffmpeg"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2")
source=("https://github.com/mltframework/mlt/archive/v$pkgver.tar.gz"
        "001-disable-broken-modules.patch"
        "002-fix-python-linking.patch")
sha256sums=('3b977c5632329fca7634d0034162df6d5b79cde3256bac43e7ba8353acced61e'
            '51630a01dd9a73aa398c7e0d4b83ac32b0419324ef04abc1245552a0eef3afb5'
            '2b24362b06a13c018f34244e88e1a777406465ef7e2dfbfe2378f77bd834c385')

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

  # opencv disabled because of https://github.com/mltframework/mlt/issues/636
  patch -p1 -i "${srcdir}/001-disable-broken-modules.patch"
  patch -p1 -i "${srcdir}/002-fix-python-linking.patch"
}

build() {
  build_dir=${srcdir}/build-${MINGW_CHOST}
  [[ -d ${build_dir} ]] && rm -rf ${build_dir}
  mkdir -p ${build_dir}
  cd ${build_dir}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX="  \
    ${MINGW_PREFIX}/bin/cmake -G"MSYS Makefiles"  \
    -DARCH=${MSYSTEM_CARCH}  \
    -DPython3_EXECUTABLE=${MINGW_PREFIX}/bin/python \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX}  \
    "${srcdir}/${_realname}-${pkgver}"

  make
}

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