# Contributor: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Jan de Groot <jgc@archlinux.org>
# Contributor: Tom Gundersen <teg@jklm.no>
# Contributor: John Proctor <jproctor@prium.net>

_pkgname=libxml2
pkgname=static-compat-$_pkgname
pkgver=2.14.6
pkgrel=1
pkgdesc='XML C parser and toolkit'
url='https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home'
arch=(x86_64)
license=(MIT)
depends=(static-compat-zlib static-compat-xz)
makedepends=(git static-compat-configure python)
options=(!emptydirs staticlibs)
# using GitHub mirror as https://gitlab.gnome.org/GNOME/libxml2.git seems broken right now
source=(
  "git+https://github.com/GNOME/libxml2.git#tag=v$pkgver"
  https://www.w3.org/XML/Test/xmlts20130923.tar.gz
)
b2sums=('977d9df5c784eaeb062ddf437eb112a4641ba3bde219d6a288965a04bee158560019c6e9987c1dcd8c6c6a664ea717325525294fff4352cfefdb876894fe1d40'
        '63a47bc69278ef510cd0b3779aed729e1b309e30efa0015d28ed051cc03f9dfddb447ab57b07b3393e8f47393d15473b0e199c34cb1f5f746b15ddfaa55670be')

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

prepare() {
  source static-compat-environment
  cd libxml2
  mkdir build

  # Revert bad Python fix
  # https://gitlab.gnome.org/GNOME/libxml2/-/issues/917
  git revert -n 381fb50113660418fb3520bde64084ecf122bf88

  # Use xmlconf from conformance test suite
  ln -s ../xmlconf

  NOCONFIGURE=1 ./autogen.sh
}

build() (
  source static-compat-environment
  export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig  # for Python
  cd libxml2/build

  static-compat-configure \
    --disable-shared \
    --enable-static \
    --with-threads \
    --without-history \
    --without-icu \
    --without-docbook \
    --without-html \
    --without-python
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0 /g' libtool
  make
)

#check() {
#  source static-compat-environment
#  make -C libxml2/build check
#}

package() {
  source static-compat-environment
  make -C libxml2/build DESTDIR="$pkgdir" install
  rm -r "$pkgdir/$static_compat_prefix"/{bin,share/man,share/doc,share/gtk-doc}
  install -Dm644 "$srcdir/libxml2/Copyright" -t "$pkgdir/usr/share/licenses/$pkgname"
}

# vim: ts=2 sw=2 et:
