# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=jp2-pixbuf-loader
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.2
pkgrel=3
pkgdesc="JPEG2000 GDK Pixbuf Loader library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://notabug.org/necklace/jp2-pixbuf-loader"
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-openjpeg2")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-meson")
source=("${_realname}-${pkgver}.tar.gz::https://notabug.org/necklace/jp2-pixbuf-loader/archive/${pkgver}.tar.gz"
        "0001-meson-support-installing-to-a-different-prefix.patch")
sha256sums=('c5f33352fdd96309d747205deef7071c44093f4720f17674b60afe2fd3c37b88'
            '8f2084bc6e41743f8afb955c276f8793de1ae1485e749c767bd5c1a5869a123f')

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

  # https://notabug.org/necklace/jp2-pixbuf-loader/pulls/4
  patch -p1 -i "${srcdir}"/0001-meson-support-installing-to-a-different-prefix.patch
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson \
      --prefix=${MINGW_PREFIX} \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      "../${_realname}"

  meson compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" meson install

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