# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Douglas Soares de Andrade <douglas@archlinux.org>

pkgname=glade
pkgver=3.40.0+r31+g1b15f940
pkgrel=3
pkgdesc="User Interface Builder for GTK 3 applications"
url="https://glade.gnome.org/"
arch=(x86_64)
license=(GPL LGPL)
depends=(gtk3 libxml2)
makedepends=(gtk-doc glib2-devel gobject-introspection itstool docbook-xsl git meson gjs
             python-gobject webkit2gtk-4.1 python-setuptools)
checkdepends=(xorg-server-xvfb)
optdepends=('devhelp: development help'
            'gjs: gjs module'
            'python-gobject: python module'
            'webkit2gtk-4.1: webkit2gtk module')
provides=(libgladeui-2.so)
_commit=1b15f9401e2bc6430e8448b1dfec3e6e874a01a8  # master
source=("git+https://gitlab.gnome.org/GNOME/glade.git#commit=$_commit"
        fix-build.diff
        0001-Fix-default-icon-name.patch
        0001-Raise-existing-window-instead-of-opening-new-one-on-.patch
        0001-Add-D-Bus-service-file.patch)
sha256sums=('8249dfc26d24308cfce97400063a7ecfeab20501889a2661f5a52b05f5d78948'
            '0dd99583c4b7b6327e84a909614f46ec0062dbc9f67be733ea97dc294e40317b'
            '2dff92ec833c1cd55fa8dc6963992185c69f0303f6ecb5f9c883e38cabb65384'
            '8551b481c57ace84df08ead3e72f7f69a8db392802a5a0657a3ff8409007ff87'
            '967112d89a69565827c16db114a77ead80f279624e4c4f8a605520db64833085')

pkgver() {
  cd glade
  git describe --tags | sed 's/^GLADE_//;s/_/./g;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd glade

  # Fix missing dependency on vcs_tag
  git apply -3 ../fix-build.diff

  # build with webkit2gtk-4.1
  sed -i 's/webkit2gtk-4.0/webkit2gtk-4.1/' meson.build

  # Fix window icon name
  git apply -3 ../0001-Fix-default-icon-name.patch

  # Raise existing window instead of opening new one on activation
  git apply -3 ../0001-Raise-existing-window-instead-of-opening-new-one-on-.patch

  # Add D-Bus service file
  git apply -3 ../0001-Add-D-Bus-service-file.patch
}

build() {
  arch-meson glade build -D gtk_doc=true
  meson compile -C build
}

check() {
  # pythonplugin test is broken with python-gobject 3.52
  sed -i '/MyPythonBox/d' glade/tests/modules.c
  rm glade/tests/catalogs/pythonplugin.xml

  dbus-run-session xvfb-run -s '-nolisten local' \
    meson test -C build --print-errorlogs
}

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

# vim:set sw=2 sts=-1 et:
