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

_realname=gtkglext
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.0
pkgrel=6
pkgdesc="opengl extensions for gtk2 (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://gtkglext.sourceforge.io/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-gtk2"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2")
source=("https://downloads.sourceforge.net/sourceforge/gtkglext/gtkglext-${pkgver}.tar.bz2"
        "001-gtk2.20.patch"
        "002-gtkglext-1.0.6-pangox.patch"
        "003-aarch64-config.patch")
sha256sums=('16bd736074f6b14180f206b7e91263fc721b49912ea3258ab5f094cfa5497f51'
            '864c6963c4a2f4f69f1f028ecee6c821a4f4d5aba142f2e07898aede825ce9ea'
            '064f61783e86c622f6f725b0586d5d75b5b8b67d20cc606fb4234a6df8da97ad'
            'cf765c7bb95f60c5ae16bbcac46a3b70a81aa569591364011fef9616526c5283')

prepare() {
  cd "${srcdir}/gtkglext-${pkgver}"
  patch -Np1 -i "${srcdir}/001-gtk2.20.patch"
  patch -p1 -R -i "${srcdir}/002-gtkglext-1.0.6-pangox.patch"
  patch -Np1 -i "${srcdir}/003-aarch64-config.patch"
  autoconf --force
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  cp -r "${srcdir}/gtkglext-${pkgver}" "${srcdir}/build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  CFLAGS+=" -fcommon -Wno-incompatible-pointer-types -Wno-implicit-function-declaration"  # work around gcc 10 being stricter here

  # an argument passed to glib-mkenums starts with a c++ comment
  export MSYS2_ARG_CONV_EXCL="/*"

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --with-gdktarget=win32 \
    --without-x \
    --disable-glibtest \
    --disable-gtktest \
    --disable-debug

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
