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

pkgname=('xz' 'liblzma' 'liblzma-devel')
pkgver=5.2.5
pkgrel=1
pkgdesc='Library and command line tools for XZ and LZMA compressed files'
arch=('i686' 'x86_64')
url='https://tukaani.org/xz/'
license=('GPL' 'LGPL' 'custom')
depends=('sh' 'libiconv' 'gettext')
makedepends=('libiconv-devel' 'gettext-devel')
options=('staticlibs')
source=("https://tukaani.org/${pkgname}/${pkgname}-${pkgver}.tar.gz"{,.sig}
        xz-5.0.5-msys2.patch)
sha256sums=('f6f4910fd033078738bd82bfba4f49219d03b17eb0794eb91efbae419f4aba10'
            'SKIP'
            'dcdc78794cbab03c2f88a4d52dee9e2606774e443e5ba1e4836426488410dd45')
validpgpkeys=('3690C240CE51B4670D30AD1C38EE757D69184620')  # Lasse Collin <lasse.collin@tukaani.org>

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

  patch -p1 -i ${srcdir}/xz-5.0.5-msys2.patch
  autoreconf -ivf
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  cd ${srcdir}/${pkgname}-${pkgver}

  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --enable-static
  make
  make DESTDIR="${srcdir}/dest" install
}

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

package_xz() {
  groups=('compression')
  depends=("liblzma=${pkgver}" 'libiconv' 'libintl')

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -f ${pkgdir}/usr/bin/*.dll
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/

  #install -d -m755 ${pkgdir}/usr/share/licenses/xz/
  #ln -sf /usr/share/doc/xz/COPYING ${pkgdir}/usr/share/licenses/xz/
  #ln -sf /usr/share/licenses/common/GPL2/license.txt ${pkgdir}/usr/share/doc/xz/COPYING.GPLv2
}

package_liblzma() {
  pkgdesc="Library for XZ and LZMA compressed files"
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_liblzma-devel() {
  pkgdesc="Liblzma headers and libraries"
  groups=('development')
  depends=("liblzma=${pkgver}" 'libiconv-devel' 'gettext-devel')
  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
