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

_realname=gtkmm3
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.24.10
pkgrel=3
pkgdesc="C++ bindings for gtk3 (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.gtkmm.org/"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-atkmm"
         "${MINGW_PACKAGE_PREFIX}-cairomm"
         "${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-glibmm"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libsigc++"
         "${MINGW_PACKAGE_PREFIX}-pangomm")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-libxslt"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=("https://download.gnome.org/sources/gtkmm/${pkgver%.*}/gtkmm-${pkgver}.tar.xz")
sha256sums=('7ab7e2266808716e26c39924ace1fb46da86c17ef39d989624c42314b32b5a76')

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

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

  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 setup \
    --prefix="${MINGW_PREFIX}" \
    "${extra_config[@]}" \
    --wrap-mode=nodownload \
    --default-library=both \
    --auto-features=enabled \
    -Dmaintainer-mode=false \
    -Dbuild-documentation=false \
    -Dbuild-demos=false \
    -Dbuild-tests=true \
    "../gtkmm-${pkgver}"

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

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

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

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

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