pkgname=gtk
pkgver=4.18.6
pkgdesc="GTK is a multi-platform toolkit for creating graphical user interfaces"
homepage="https://www.gtk.org/ https://gitlab.gnome.org/GNOME/gtk/"
license=("LGPL-2+")
depends=(
  at-spi2-core
  cairo
  desktop-file-utils
  fontconfig
  fribidi
  gcc-libs
  gdk-pixbuf2
  glib2
  glibc
  graphene
  gtk-update-icon-cache
  harfbuzz
  iso-codes
  libegl
  libpng
  librsvg
  libxkbcommon
  pango
  shared-mime-info
  vulkan-loader
  wayland
)
makedepends=(
  docbook-xsl
  gobject-introspection
  meson
  python-gobject
  sassc
  shaderc
  vulkan-headers
  wayland-protocols
)
_hook="gtk4-querymodules.HOOK"
_hook_sum="0faeb757f9c9bde8a295c8312c512e9519d6007ad5ee72ac6e65f79d4aec8bc426ece530744e0c36e46df41a2769ff0bcf8ae3c425d3beacae30ddd04f5414ff"
_patches=("0001-gdk-add-a-poison-macro-to-hide-GDK_WINDOWING_ge_4.18.5.patch")
_patch_sums=("3df25aa8c17f7858febf1e0d3171a078736968d90114729830654c0ebaac53e9cf5ce0ab317065ac7eb0a8572f16ceb5d323755138d9ba7c013232b10e0085ab")
sources=("${pkgname}-${pkgver}.tar.xz"
  "${_hook}"
  "${_patches[@]}"
)
urls=("https://download.gnome.org/sources/${pkgname}/${pkgver%.*}/${sources[0]}"
  "${_hook}"
  "${_patches[@]}"
)
sha512sums=("636bc3adf01f444dfbf10a3fdce82cdd7b2914b9ff251e98e006a987c3216ef22f5ae8759aa5f2385d1e82813ab8bf2c8adc4f8d6db230e9f507b44fac10e359"
  "${_hook_sum}"
  "${_patch_sums[@]}"
)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  for _patch in ${_patches[@]}; do
    patch -p1 -i ${filedir}/${_patch}
  done

  # Nothing should use gtk4-update-icon-cache and an unversioned one is shipped by dev-util/gtk-update-icon-cache
  sed -i \
      -e '/gtk4-update-icon-cache/d' \
      docs/reference/gtk/meson.build \
      tools/meson.build
}

src_build() {
  local meson_args=(
    --prefix=/usr
    --buildtype=release
    --wrap-mode=nodownload
    -D python.bytecompile=1
    -D x11-backend=false
    -D wayland-backend=true
    -D broadway-backend=false
    -D win32-backend=false
    -D android-backend=false
    -D macos-backend=false
    -D media-gstreamer=disabled
    -D print-cpdb=disabled
    -D print-cups=disabled
    -D vulkan=enabled
    -D cloudproviders=disabled
    -D sysprof=disabled
    -D tracker=disabled
    -D colord=disabled
    -D f16c=enabled
    -D introspection=enabled
    -D documentation=false
    -D screenshots=false
    -D man-pages=true
    -D profile=default
    -D build-demos=false
    -D build-testsuite=false
    -D build-examples=false
    -D build-tests=false
  )
  meson setup build "${meson_args[@]}"
}

src_install() {
  meson install -C build --destdir "$pkgdir"
  leaf_install_hook "${filedir}/${_hook}"
}

# vim:ft=sh syn=sh et sw=2:
