pkgname=libxml2
_basever=2.14
_patchver=5
if (( _patchver == 0 )); then
  pkgver=$_basever
else
  pkgver=$_basever.$_patchver
fi
pkgdesc="XML C parser and toolkit"
homepage="https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home"
arch=(x86_64)
license=(MIT)
sources=("${pkgname}-${pkgver}.tar.xz"
  "xmlts20130923.tar.gz"
)
urls=("https://download.gnome.org/sources/${pkgname}/${_basever}/${sources[0]}"
  "https://www.w3.org/XML/Test/${sources[1]}"
)
md5sums=("59aac4e5d1d350ba2c4bddf1f7bc5098"
  "ef8fbe0c92efd9a60d7f320e211d10b2"
)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  tar -xf ${distdir}/${sources[1]}
}

src_build() {
  ./configure --prefix=/usr     \
              --sysconfdir=/etc \
              --disable-static  \
              --with-history    \
              --with-icu        \
              PYTHON=/usr/bin/python3 \
              --docdir=/usr/share/doc/libxml2-${pkgver} &&
  make
}

src_check() {
  leaf_record_message "run grep -E '^Total|expected|Ran' ${srcdir}/check.log to see check result."
  make check > check.log
}

src_install() {
  make DESTDIR="${pkgdir}" install
  rm -vf ${pkgdir}/usr/lib/libxml2.la &&
  sed '/libs=/s/xml2.*/xml2"/' -i ${pkgdir}/usr/bin/xml2-config
  install -Dm644 Copyright -t "$pkgdir/usr/share/licenses/$pkgname"
}
