# Maintainer: Ignacio Casal Quinteiro <icq@gnome.org>

_realname=libepoxy
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.5.10
pkgrel=7
pkgdesc="A library for handling OpenGL function pointer management for you (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/anholt/libepoxy"
license=("spdx:MIT")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-egl-headers"
         "${MINGW_PACKAGE_PREFIX}-gles-headers")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-python")
source=("https://github.com/anholt/libepoxy/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-egl-missing-prototype.patch"
        "https://github.com/anholt/libepoxy/pull/285.patch"
        "https://github.com/anholt/libepoxy/pull/294.patch"
        "0001-Ensure-dispatch-table-initialization.patch")
sha256sums=('a7ced37f4102b745ac86d6a70a9da399cc139ff168ba6b8002b4d8d43c900c15'
            '5fb6b63e93cb92052f25c0ac230f3b4d89054a28e02dc37a42eb9f866cd0cbc1'
            'e86994609738190e9fb84ea96184639a1282ee4eee5a5ae0272d9a2d83a802ce'
            '3ef53c2126e3a27bc090f40bbc423ae70e08edbc6291a74f22a0bebcd00da8a8'
            'd035fc71735ce8364cb2e8c4783c9e0396bc84bff29221de48f152bd36e60b9f')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-egl-missing-prototype.patch
  patch -p1 -i ${srcdir}/285.patch
  patch -p1 -i ${srcdir}/294.patch
  patch -p1 -i ${srcdir}/0001-Ensure-dispatch-table-initialization.patch
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype plain \
    -Ddefault_library=both \
    -Degl=yes \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson.exe install

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