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

_realname=libbluray
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.4.0
pkgrel=2
pkgdesc="Library to access Blu-Ray disks for video playback (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.videolan.org/developers/libbluray.html'
msys2_repository_url='https://code.videolan.org/videolan/libbluray'
msys2_references=(
  "cpe: cpe:/a:videolan:libbluray"
)
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-freetype")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-meson"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
  "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://download.videolan.org/pub/videolan/libbluray/${pkgver}/${_realname}-${pkgver}.tar.xz
        "https://code.videolan.org/videolan/libbluray/-/commit/8e5ef374c8ff3603a8ed4e1f48d4d5399e2e8044.patch")
sha256sums=('77937baf07eadda4b2b311cf3af4c50269d2ea3165041f5843d96476c4c92777'
            '488f6eee652e7955d2f8ad4d2c77030e457c3b893f76904f3c116bd097181dcd')

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

  patch -Np1 -i "${srcdir}/8e5ef374c8ff3603a8ed4e1f48d4d5399e2e8044.patch"
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson setup \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --buildtype=plain \
    --default-library=static \
    -Dc_args="-DLIBXML_STATIC" \
    -Denable_examples=true \
    -Dbdj_jar=disabled \
    -Dlibxml2=enabled \
    -Dfreetype=enabled \
    "../${_realname}-${pkgver}"

  meson compile

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson setup \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --buildtype=plain \
    --default-library=shared \
    -Denable_examples=true \
    -Dbdj_jar=disabled \
    -Dlibxml2=enabled \
    -Dfreetype=enabled \
    "../${_realname}-${pkgver}"

  meson compile
}

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

  cd "${srcdir}/build-shared-${MSYSTEM}"
  DESTDIR="${pkgdir}" meson install

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