# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=glibmm
pkgbase=mingw-w64-${_realname}-2.68
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-2.68"
pkgver=2.68.1
pkgrel=1
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}268")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}268")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}268")
pkgdesc="Glib-- (glibmm) is a C++ interface for glib (V2.68) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.gtkmm.org/"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libsigc++-3.0")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('strip' '!debug' 'staticlibs')
source=("https://download.gnome.org/sources/glibmm/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"
        "glibmm-2.66.1-no-export-deleted-methods.patch")
sha256sums=('6664e27c9a9cca81c29e35687f49f2e0d173a2fc9e98c3428311f707db532f8c'
            'a4ff330529d457b5be05eeab31d0cba5bc073b35b8c05ac5ab1dffb3a79d3751')

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

  # work around error building under clang
  # https://gitlab.gnome.org/GNOME/glibmm/-/issues/92
  patch -Np1 -i "${srcdir}/glibmm-2.66.1-no-export-deleted-methods.patch"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("--buildtype=release")
  else
    _extra_config+=("--buildtype=debug")
  fi

  CFLAGS+=" -Wno-attributes" \
  CXXFLAGS+=" -Wno-attributes" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe \
    --prefix="${MINGW_PREFIX}" \
    "${_extra_config[@]}" \
    --wrap-mode=nodownload \
    --default-library=both \
    --auto-features=enabled \
    -Dmaintainer-mode=false \
    -Dbuild-documentation=false \
    -Dbuild-examples=true \
    "../${_realname}-${pkgver}"

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

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  ${MINGW_PREFIX}/bin/meson.exe test || true
}

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

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson.exe install

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