# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=ffms2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.0
pkgrel=3
pkgdesc="A cross-platform wrapper library around libav/FFmpeg (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/FFMS/ffms2/"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-ffmpeg")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/FFMS/ffms2/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-ffmsindex-add-municode-ldflag.patch")
sha256sums=('7770af0bbc0063f9580a6a5c8e7c51f1788f171d7da0b352e48a1e60943a8c3c'
            '956550396e90107bb173cc820ab666998287ce84c264a9da25313488ca727e4b')

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

  patch -Np1 -i "${srcdir}/0001-ffmsindex-add-municode-ldflag.patch"

  mkdir -p src/config
  autoreconf -fiv
}

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

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --disable-debug \
    --disable-static \
    --enable-shared

  make
}

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

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