# Contributor: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>

_pkgname=glib2
pkgname=$_pkgname-static
pkgver=2.66.4
pkgrel=2
pkgdesc="Low level core library"
url="https://wiki.gnome.org/Projects/GLib"
license=(LGPL)
arch=(x86_64)
depends=(pcre-static libffi-static util-linux-static zlib) # regular zlib contains static lib
makedepends=(gettext shared-mime-info python libelf git util-linux
             meson dbus sysprof pcre libffi) # shared libs required at build time for some plugins
checkdepends=(desktop-file-utils)
options=(!strip !emptydirs staticlibs)
_commit=bacbec652d356895ec493f3de2f2f6f4c7dafde0  # tags/2.66.4^0
source=("git+https://gitlab.gnome.org/GNOME/glib.git#commit=$_commit"
        noisy-glib-compile-schemas.diff)
sha256sums=('SKIP'
            '81a4df0b638730cffb7fa263c04841f7ca6b9c9578ee5045db6f30ff0c3fc531')

pkgver() {
  cd glib
  git describe --tags | sed 's/-/+/g'
}

prepare() {
  cd glib

  # Suppress noise from glib-compile-schemas.hook
  git apply -3 ../noisy-glib-compile-schemas.diff
}

build() {
  CFLAGS+=" -DG_DISABLE_CAST_CHECKS"
  arch-meson glib build \
    -D selinux=disabled \
    -D sysprof=enabled \
    -D man=false \
    -D gtk_doc=false \
    -Dinternal_pcre=false \
    --prefix /usr/static \
    --default-library static
  meson compile -C build
}

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

package() {
  DESTDIR="$pkgdir" meson install -C build

  # Strip messes up the LTO-enabled archive's index so strip libs manually and then run ranlib again
  find "$pkgdir" -name '*.a' -exec strip $STRIP_STATIC {} \;
  find "$pkgdir" -name '*.a' -exec ranlib {} \;

  # Avoid a dep on sysprof
  sed -i 's/, sysprof-capture-4//' "$pkgdir"/usr/static/lib/pkgconfig/*.pc

  export PYTHONHASHSEED=0
  python -m compileall -d /usr/static/share/glib-2.0/codegen \
    "$pkgdir/usr/static/share/glib-2.0/codegen"
  python -O -m compileall -d /usr/static/share/glib-2.0/codegen \
    "$pkgdir/usr/static/share/glib-2.0/codegen"
}

# vim:set sw=2 et:
