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

pkgname=('xz' 'liblzma' 'liblzma-devel')
pkgver=5.8.1
pkgrel=1
pkgdesc='Library and command line tools for XZ and LZMA compressed files'
arch=('i686' 'x86_64')
url='https://tukaani.org/xz/'
msys2_repository_url="https://github.com/tukaani-project/xz/"
msys2_references=(
  "anitya: 5277"
  "cpe: cpe:/a:tukaani:xz"
)
license=('GPL' 'LGPL' 'custom')
depends=('sh' 'libiconv' 'gettext')
makedepends=('libiconv-devel' 'gettext-devel' 'autotools' 'gcc' 'po4a' 'doxygen')
options=('staticlibs')
source=("https://github.com/tukaani-project/xz/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('bdbc23fbf9098843357e71e49685724fda2c320c29cb1b25fd90505f14bb0b3d')
validpgpkeys=('3690C240CE51B4670D30AD1C38EE757D69184620') # Lasse Collin <lasse.collin@tukaani.org>

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

  ./autogen.sh
}

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

  export lt_cv_deplibs_check_method='pass_all'
  export MSYSTEM=CYGWIN
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --enable-static \
    --enable-doxygen
  make
  make DESTDIR="${srcdir}/dest" install
}

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

package_xz() {
  groups=('compression')
  depends=("liblzma" '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/
}

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

  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" 'libiconv-devel' 'gettext-devel')

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
