# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: Pierre Schmitz <pierre@archlinux.de>
# Contributor: Mikko Seppälä <t-r-a-y@mbnet.fi>

pkgbase=lib32-glib2
pkgname=(
  lib32-glib2
)
pkgver=2.80.0
pkgrel=1
pkgdesc="Low level core library - 32-bit"
url="https://gitlab.gnome.org/GNOME/glib"
license=(LGPL-2.1-or-later)
arch=(x86_64)
depends=(
  glib2
  lib32-libffi
  lib32-pcre2
  lib32-util-linux
  lib32-zlib
)
makedepends=(
  gettext
  git
  lib32-dbus
  lib32-libelf
  meson
  python
  shared-mime-info
  util-linux
)
checkdepends=(
  desktop-file-utils
  lib32-glib2
)
options=(
  debug
)
_commit=763cc3b238398614c20069fd67642730e3a6519b  # tags/2.80.0^0
source=(
  "git+https://gitlab.gnome.org/GNOME/glib.git#commit=$_commit"
  "git+https://gitlab.gnome.org/GNOME/gvdb.git"
  gio-querymodules-32.hook
)
b2sums=('cc3a6a7a14fef1aabc08d3bdfe98f66e3ecf3591ac054d83aa9404c8c9cd72e690a4c26c16934700d067bb2cb3d58730387482032cd9ffa04b041869426165ba'
        'SKIP'
        '678ea2d010fd64b6c55106510096363c54c357d65615c666e9cc3a0e280c0878257a45e646dd88f6bdd0623f7268c4afd2d4f98f82a5489bbfc028c5864252f1')

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

prepare() {
  cd glib

  git submodule init
  git submodule set-url subprojects/gvdb "$srcdir/gvdb"
  git -c protocol.file.allow=always submodule update
}

build() {
  local meson_options=(
    --cross-file lib32
    -D glib_debug=disabled
    -D documentation=false
    -D introspection=disabled
    -D man-pages=disabled
    -D selinux=disabled
    -D sysprof=disabled
  )

  # Produce more debug info: GLib has a lot of useful macros
  CFLAGS+=" -g3"
  CXXFLAGS+=" -g3"

  # Avoid crashing some old binaries
  CFLAGS+=" -mstackrealign"
  CXXFLAGS+=" -mstackrealign"

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

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

package_lib32-glib2() {
  depends+=(
    libffi.so
    libmount.so
  )
  provides+=(libg{lib,io,irepository,module,object,thread}-2.0.so)

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

  rm -r "$pkgdir"/usr/{lib,share,include}
  find "$pkgdir/usr/bin" -type f -not -name gio-querymodules -printf 'Removing %P\n' -delete
  mv "$pkgdir"/usr/bin/gio-querymodules{,-32}

  install -Dt "$pkgdir/usr/share/libalpm/hooks" -m644 *.hook
  touch "$pkgdir/usr/lib32/gio/modules/.keep"
}

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