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

_realname=ffms2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.40
pkgrel=1
pkgdesc="A cross-platform wrapper library around libav/FFmpeg (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/FFMS/ffms2/"
license=('MIT')
options=('staticlibs' 'strip')
depends=("${MINGW_PACKAGE_PREFIX}-ffmpeg")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/FFMS/ffms2/archive/${pkgver}.tar.gz"
        "0001-ffmsindex-add-municode-ldflag.patch")
sha256sums=('82e95662946f3d6e1b529eadbd72bed196adfbc41368b2d50493efce6e716320'
            '59e2150127dbdf2645bab6cbbd8842cc58dd33ce12238e76d1b2916d9d051f56')

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

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

  mkdir -p src/config
  autoreconf -fiv
}

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

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

  make
}

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

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