#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgbase=vte3
pkgname=(vte-common vte3 vte4)
pkgver=0.70.2
pkgrel=01
pkgdesc="Virtual Terminal Emulator widget w/o systemd"
url="https://wiki.gnome.org/Apps/Terminal/VTE"
arch=(x86_64)
depends=(gtk3 pcre2 gnutls fribidi)
# #  makedepends=(gobject-introspection vala git gtk-doc gperf meson)  ## previous dependencies
makedepends=(fribidi gi-docgen git gnutls gobject-introspection gperf
	gtk3 gtk4 meson pcre2 vala)
## options=(debug !lto)   ##  uncomment this to have the debug pkg produced
options=(!lto)
#_commit=5bf476f1d7283bc805ac8ae6abe94f81ffd7be05  # tags/0.70.1^0
_commit=bfabb63d2f8d0f9846dc0a0a7d768d8bf6da3531  # tags/0.70.2^0
source=("git+https://gitlab.gnome.org/GNOME/vte.git#commit=$_commit")

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

prepare() {
  cd vte
}

build() {
  local meson_options=(
    -D b_lto=false
    -D docs=false
    -D_systemd=false
    -D gtk4=true
  )

  arch-meson vte build "${meson_options[@]}"
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_vte-common() {
  pkgdesc="Files shared by VTE libraries"
  depends=(sh)

  meson install -C build --destdir "$pkgdir"

  cd "$pkgdir"

  _pick gtk3 usr/bin/vte-2.91
  _pick gtk3 usr/include/vte-2.91
  _pick gtk3 usr/lib/libvte-2.91.so*
  _pick gtk3 usr/lib/pkgconfig/vte-2.91.pc
  _pick gtk3 usr/lib/girepository-1.0/Vte-2.91.typelib
  _pick gtk3 usr/share/gir-1.0/Vte-2.91.gir
  _pick gtk3 usr/share/glade
  _pick gtk3 usr/share/vala/vapi/vte-2.91.{deps,vapi}

  _pick gtk4 usr/bin/vte-2.91-gtk4
  _pick gtk4 usr/include/vte-2.91-gtk4
  _pick gtk4 usr/lib/libvte-2.91-gtk4.so*
  _pick gtk4 usr/lib/pkgconfig/vte-2.91-gtk4.pc
  _pick gtk4 usr/lib/girepository-1.0/Vte-3.91.typelib
  _pick gtk4 usr/share/gir-1.0/Vte-3.91.gir
  _pick gtk4 usr/share/vala/vapi/vte-2.91-gtk4.{deps,vapi}

}

package_vte3() {
  pkgdesc+=" (GTK3)"
  depends=(
    fribidi
    gnutls
    gtk3
    pcre2
    vte-common
  )
  provides+=(libvte-2.91.so)

  mv gtk3/* "$pkgdir"
}

package_vte4() {
  pkgdesc+=" (GTK4)"
  depends=(
    fribidi
    gnutls
    gtk4
    pcre2
    vte-common
  )
  provides+=(libvte-2.91-gtk4.so)

  mv gtk4/* "$pkgdir"
}

#---- license gpg-key sha256sums ----

license=(LGPL)

sha256sums=(SKIP)


#  06b5535d770a808ced2cf40ad2b77926ae565e596e421d3ad33b961b3732ada4  vte3-0.70.2-01-x86_64.pkg.tar.xz
#  3da3052213c03217abd074783a9426455ae4e8eab86a8e79d1ecdd05b2caf8b8  vte4-0.70.2-01-x86_64.pkg.tar.xz
#  d69ad75707ed4d683277169dccd55f500ed7eac85822da4bb23ee3c2ea855d09  vte-common-0.70.2-01-x86_64.pkg.tar.xz

