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

_realname=zvbi
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.2.44
pkgrel=2
pkgdesc='VBI capture and decoding library (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_repository_url='https://github.com/zapping-vbi/zvbi'
url='http://zapping.sourceforge.net/cgi-bin/view/ZVBI/WebHome'
license=('spdx: GPL-2.0-or-later AND BSD-2-Clause AND LGPL-2.1-or-later AND MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
  "${MINGW_PACKAGE_PREFIX}-libiconv"
  "${MINGW_PACKAGE_PREFIX}-libpng"
  "${MINGW_PACKAGE_PREFIX}-libwinpthread"
)
makedepends=(
  'git'
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-gettext-tools"
)
source=(
  "git+https://github.com/zapping-vbi/zvbi.git#tag=v${pkgver}"
  "0001-zvbi-no-undefined.patch"
)
sha256sums=('632b990f36d283084d51c90d2b23dc1f297725973e75591b3637c9751c1aa90d'
            'c29b9fb68e48dee88b6a881478a51ce6b7277f5b3c2fedbfab71cd0270c66e47')

prepare() {
  cd "${_realname}"
  git apply "${srcdir}/0001-zvbi-no-undefined.patch"
  NOCONFIGURE=1 ./autogen.sh
}

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

  ../"${_realname}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}" \
    --disable-examples \
    --disable-tests \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd "build-${MSYSTEM}"
  make install DESTDIR="${pkgdir}"
  install -Dm644 "${srcdir}/${_realname}/COPYING.md" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.md"
}
