# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=kvazaar
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.3.2
pkgrel=1
pkgdesc="An open-source HEVC encoder (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://ultravideo.fi/kvazaar.html"
msys2_repository_url="https://github.com/ultravideo/kvazaar"
license=("spdx:BSD-3-Clause")
depends=("${MINGW_PACKAGE_PREFIX}-crypto++"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/ultravideo/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-clang-pthread-fix.patch")
sha256sums=('ddd0038696631ca5368d8e40efee36d2bbb805854b9b1dda8b12ea9b397ea951'
            '465a75a3b28e921b60e6558da744d62eb073fe774745d33a8f8de1a6da2a0015')

prepare(){
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-clang-pthread-fix.patch

  autoreconf -fiv
}

build() {
  [[ -d build-${MSYSTEM} ]] && rm -rf build-${MSYSTEM}
  cp -r ${_realname}-${pkgver} build-${MSYSTEM} && cd build-${MSYSTEM}

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-largefile \
    --with-cryptopp

  make
}

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

  # fix .pc file
  sed -s "s|$(cygpath -m ${MINGW_PREFIX})|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/${_realname}.pc"

  install -Dm644 LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
