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

_realname=glibmm
pkgbase=mingw-w64-${_realname}-2.68
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-2.68"
pkgver=2.86.0
pkgrel=2
pkgdesc="Glib-- (glibmm) is a C++ interface for glib (V2.68) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gnome.pages.gitlab.gnome.org/glibmm/'
msys2_repository_url='https://gitlab.gnome.org/GNOME/glibmm'
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libsigc++-3.0")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://download.gnome.org/sources/glibmm/${pkgver%.*}/${_realname}-${pkgver}.tar.xz")
sha256sums=('39c0e9f6da046d679390774efdb9ad564436236736dc2f7825e614b2d4087826')

build() {
  local -a _static_flags=(
    -DGIO_STATIC_COMPILATION
    -DGLIB_STATIC_COMPILATION
    -DGMODULE_STATIC_COMPILATION
    -DGOBJECT_STATIC_COMPILATION
  )

  local -a _meson_options=(
    --prefix=${MINGW_PREFIX}
    --buildtype=plain
    --wrap-mode=nodownload
    --auto-features=enabled
    -Dmaintainer-mode=false
    -Dbuild-documentation=false
    -Dbuild-examples=true
  )

  CFLAGS+=" ${_static_flags[@]} -Wno-attributes" \
  CXXFLAGS+=" ${_static_flags[@]} -Wno-attributes" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson setup \
    "${_meson_options[@]}" \
    --default-library=static \
    "${_realname}-${pkgver}" \
    "build-${MSYSTEM}-static"

  meson compile -C "build-${MSYSTEM}-static"

  CFLAGS+=" -Wno-attributes" \
  CXXFLAGS+=" -Wno-attributes" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson setup \
    "${_meson_options[@]}" \
    --default-library=shared \
    "${_realname}-${pkgver}" \
    "build-${MSYSTEM}-shared"

  meson compile -C "build-${MSYSTEM}-shared"
}

check() {
  meson test -C "build-${MSYSTEM}-static" || warning "Tests failed"
  meson test -C "build-${MSYSTEM}-shared" || warning "Tests failed"
}

package() {
  meson install -C "build-${MSYSTEM}-static" --destdir "${pkgdir}"
  meson install -C "build-${MSYSTEM}-shared" --destdir "${pkgdir}"

  sed -s "s|$(cygpath -wm /usr/bin)|/usr/bin|g" -i "${pkgdir}${MINGW_PREFIX}"/lib/glibmm-2.68/proc/gmmproc
  sed -s 's|#!.*|#! /usr/bin/perl|g' -i "${pkgdir}${MINGW_PREFIX}"/lib/glibmm-2.68/proc/gmmproc

  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"
}
