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

_realname=libdvdread
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.1.3
pkgrel=2
pkgdesc="Provides a simple foundation for reading DVD video disks (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.videolan.org/developers/libdvdnav.html"
license=('spdx:GPL-2.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-libdvdcss")
source=("https://download.videolan.org/pub/videolan/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.bz2"{,.asc}
        https://code.videolan.org/videolan/libdvdread/-/commit/ea158e812abe9990c971b095a13d35c9bfae4cc7.patch
        https://code.videolan.org/videolan/libdvdread/-/commit/f3c27767e28452731a6445fdbc183f8d456100b7.patch
        https://code.videolan.org/videolan/libdvdread/-/merge_requests/28.patch
        0001-no-undefined-on.all.patch)
sha256sums=('ce35454997a208cbe50e91232f0e73fb1ac3471965813a13b8730a8f18a15369'
            'SKIP'
            '96dd960e39e7fe2accfac2e8bae00314414380f04e6d7fd4e4ee2e1126ea7e14'
            '50b851688b5716cf1bbe49d3bdc7f7675f3cf1053755d984e82be78aff71e55d'
            'e0c45b669bfac3465e04c8b5203e7b28cee0112f4b6b94586dfd47721389743d'
            'd8930c4167b9f9524b164f3ab918c3e8289acca3d86cd92146fd79453a5e9b58')
validpgpkeys=('65F7C6B4206BD057A7EB73787180713BE58D1ADC') # VideoLAN Release Signing Key

_apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -p1 -i "${srcdir}/${_patch}"
  done
}

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

  _apply_patch_with_msg \
    ea158e812abe9990c971b095a13d35c9bfae4cc7.patch \
    f3c27767e28452731a6445fdbc183f8d456100b7.patch \
    28.patch \
    0001-no-undefined-on.all.patch

  autoreconf -fi
}

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

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

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