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

pkgname=itstool
pkgver=2.0.7
pkgrel=1
pkgdesc="XML to PO and back again"
arch=('i686' 'x86_64')
url="https://itstool.org/"
license=("GPL3")
depends=("python" "libxml2" "libxml2-python")
makedepends=('autotools' 'gcc')
source=(https://files.itstool.org/itstool/${pkgname}-${pkgver}.tar.bz2
        fix-segfault.patch
        itstool-2.0.5-fix-crash-wrong-encoding.patch)
sha256sums=('6b9a7cd29a12bb95598f5750e8763cee78836a1a207f85b74d8b3275b27e87ca'
            'ccdf85ae9bdfd0259728a79b6b9806d8b9bcb27ed1f974ac49c551587cb4e6c6'
            'cb57e3694ab3d7c62b063629b2e9edc6327260c0797d0f33c8dc97fe37c40ebb')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/itstool-2.0.5-fix-crash-wrong-encoding.patch
  patch -p1 -i ${srcdir}/fix-segfault.patch

  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${CHOST}"
  cd "${srcdir}/build-${CHOST}"
    PYTHON=/usr/bin/python \
    ../${pkgname}-${pkgver}/configure \
    --prefix=/usr \
    --build=${CHOST} \
    --host=${CHOST} \
    --target=${CHOST}
    make
}

check() {
  cd build-${CHOST}
  make -k check
}

package() {
  cd "${srcdir}/build-${CHOST}"
  make DESTDIR="${pkgdir}" install
}
