# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('libxslt' 'libxslt-devel')
pkgver=1.1.34
pkgrel=4
pkgdesc="XML stylesheet transformation library"
arch=('i686' 'x86_64')
url="http://xmlsoft.org/XSLT/"
license=('custom')
makedepends=('gcc' 'libxml2-devel' 'libgcrypt-devel')
checkdepends=('docbook-xml')
options=('!libtool')
source=(http://xmlsoft.org/sources/${pkgname}-${pkgver}.tar.gz
        libxslt-1.1.32-msys2.patch
        libxslt.m4-libxslt-1.1.26.patch
        libxslt-cygwin-reentrant.patch)
sha256sums=('98b1bd46d6792925ad2dfe9a87452ea2adebf69dcb9919ffd55bf926a7f93f7f'
            '0f17e189adf57b2ff4085049555b91ac4fd0a9b11dc1e8100cfb1e1f7938e877'
            'c02cd8437064db0921c08e63245c403dad12410d2997715aa7aa36600bfaa895'
            'f57629d5f2ce0ab441dc548fa023aee09780eb2940986a44b4423ba253e190bb')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  patch -p1 -i ${srcdir}/libxslt.m4-libxslt-1.1.26.patch
  patch -p1 -i ${srcdir}/libxslt-cygwin-reentrant.patch
  patch -p1 -i ${srcdir}/libxslt-1.1.32-msys2.patch

  autoreconf -fi
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  CFLAGS+=" -fcommon"
  export lt_cv_deplibs_check_method='pass_all'
  ./configure --build=${CHOST} --host=${CHOST} --target=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --enable-shared \
    --enable-static \
    --with-crypto \
    --with-debugger \
    --with-html-dir=/usr/share/doc \
    --with-html-subdir=libxslt/html \
    --with-python=no

  make
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make check
}

package_libxslt() {
  depends=('libxml2' 'libgcrypt')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -f ${pkgdir}/usr/bin/*-config
  cp -rf ${srcdir}/dest/usr/share/man ${pkgdir}/usr/share/
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}

package_libxslt-devel() {
  pkgdesc="Libxslt headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=("libxslt=${pkgver}" 'libxml2-devel' 'libgcrypt-devel')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share/aclocal ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/doc ${pkgdir}/usr/share/
  rm -rf ${pkgdir}/usr/share/doc/libxslt-python-${pkgver}
}