# 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.13.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
  0001-HACK-Don-t-run-fuzzing-tests.patch
)
b2sums=('84fd36291960d78ebef4c373c15c29bf4efd17fe59174cca70bad6fe8ac73dd333cdea6ed6f577db2107991fa6b6d6fb20f7551cb640cbbfe38ff696b9a0b9ba'
        '63a47bc69278ef510cd0b3779aed729e1b309e30efa0015d28ed051cc03f9dfddb447ab57b07b3393e8f47393d15473b0e199c34cb1f5f746b15ddfaa55670be'
        '151e84ee17051eeecfa8c62a7376ff269860f3ff6d33fb92209ff5f8dc9576a5648bbe9ffc96317695c069760ccfecaa3e6f19fb7a7c2e9f039a146d7fc8a516')

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
  # Use xmlconf from conformance test suite
  ln -s ../xmlconf

  # Do not run fuzzing tests
  git apply -3 ../0001-HACK-Don-t-run-fuzzing-tests.patch

  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:
