# Maintainer (Arch:glib2) Jan de Groot <jgc@archlinux.org>
# Maintainer: Luke Shumaker <lukeshu@parabola.nu>
# Contributor: Márcio Silva <coadde@hyperbola.info>

pkgname=glib2-static
pkgver=2.58.3
pkgrel=1
pkgrel+=.static2
pkgdesc="Low level core library"
pkgdesc+=" (static libraries)"
url="https://wiki.gnome.org/Projects/GLib"
license=(LGPL2.1)
arch=(x86_64)
arch+=(i686 armv7h)
depends=(pcre libffi)
makedepends=(libffi zlib shared-mime-info python libelf git util-linux meson dbus libxslt docbook-xsl)
checkdepends=(desktop-file-utils dbus)
optdepends=('python: gdbus-codegen, glib-genmarshal, glib-mkenums, gtester-report'
            'libelf: gresource inspection tool')
options=('!docs' '!libtool' '!emptydirs' '!strip' 'staticlibs')
_commit=f2d1128ffae0de87680e411fb62ccfccafed6b1c  # tags/2.58.3^0
source=("git+https://gitlab.gnome.org/GNOME/glib.git#commit=$_commit"
        noisy-glib-compile-schemas.diff
        fix-static-build-589.diff)
sha256sums=('SKIP'
            '81a4df0b638730cffb7fa263c04841f7ca6b9c9578ee5045db6f30ff0c3fc531'
            'f4790fc845f2b4811ce5df5ef3a7dfcc23a1593ec4e19ae9173bb799a045d00f')

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

prepare() {
  cd glib

  # Suppress noise from glib-compile-schemas.hook
  patch -Np1 -i ../noisy-glib-compile-schemas.diff
  patch -Np1 -i ../fix-static-build-589.diff
}

build() {
  if [[ $CARCH = i686 ]]; then
    # GTimer has trouble with x87 math, force SSE2 (which is implied
    # on x86_64).
    CFLAGS+=' -msse2 -mfpmath=sse'
  fi

  arch-meson glib build \
    --default-library static \
    -D selinux=false \
    -D man=true \
    -D gtk_doc=false \
    -D internal_pcre=false \
    -D fam=false
  ninja -C build
}

check() {
  meson test -C build
}

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

  # remove conflicting files
  rm -rf "$pkgdir/usr/"{bin,include,share,lib/glib-2.0,lib/pkgconfig} $pkgdir/usr/lib/*.so*
}
