# Packager = Tuxcore <dev@tuxcore.org> 
pkgbase=sysprof
pkgname=(
  sysprof
  libsysprof-capture
)
pkgver=46.0
pkgrel=3
pkgdesc="Kernel based performance profiler"
url="https://wiki.gnome.org/Apps/Sysprof"
license=(GPL-3.0-or-later)
arch=(x86_64)
depends=(
  cairo
  gcc-libs
  glib2
  glibc
  graphene
  gtk4
  hicolor-icon-theme
  json-glib
  libadwaita
  libdex
  libpanel
  libunwind
  pango
  polkit
  systemd-libs
)
makedepends=(
  git
  meson
  python-packaging
  yelp-tools
)
source=(
  "git+https://gitlab.gnome.org/GNOME/sysprof.git#tag=${pkgver/[a-z]/.&}"
)
b2sums=('d32a2a9f129a121c814b46377b6d0fee306e3d0f87dac73e7fd4ce9de85888e5e980f309faa17ce366006f0a0390475dc83739b92d4e460c2da7293ab97dcd03')

prepare() {
  cd sysprof
}

build() {
  # Ensure static library is non-LTO compatible
  CFLAGS+=" -ffat-lto-objects"

  arch-meson sysprof build
  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_sysprof() {
  depends+=(libsysprof-capture)
  groups=(gnome-extra)

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

  cd "$pkgdir"

  _pick capture usr/lib/libsysprof-capture-*
  _pick capture usr/lib/pkgconfig/sysprof-capture-*
  _pick capture usr/include/sysprof-*/sysprof-{address,capture,clock,collector,macros}.h
  _pick capture usr/include/sysprof-*/sysprof-{platform,version,version-macros}.h
  _pick capture usr/include/sysprof-*/sysprof-capture-{condition,cursor,reader,types,writer}.h
}

package_libsysprof-capture() {
  pkgdesc+=" - capture library"
  depends=()
  license=(BSD-2-Clause-Patent)

  mv capture/* "$pkgdir"

  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 \
    sysprof/src/libsysprof-capture/COPYING
}

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