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

pkgbase=lzo2
pkgname=('liblzo2' 'liblzo2-devel')
pkgver=2.10
pkgrel=2
pkgdesc="Portable lossless data compression library"
arch=('i686' 'x86_64')
url="https://www.oberhumer.com/opensource/lzo"
license=('GPL')
makedepends=('gcc' 'make' 'patch')
groups=('libraries' 'compression')
source=(https://www.oberhumer.com/opensource/lzo/download/lzo-${pkgver}.tar.gz
        lzo-2.07-msys2.patch)
options=(!libtool)
sha256sums=('c0f892943208266f9b6543b3ae308fab6284c5c90e627931446fb49b4221a072'
            'bc144d5cc547dd0a7c0923130ef4de268a622f6eab6ebfc705d7b0ea87bfa401')

prepare() {
  cd "${srcdir}/lzo-${pkgver}"
  patch -p1 -i ${srcdir}/lzo-2.07-msys2.patch

  autoreconf -fi
}

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

  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared

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

check() {
  cd "${srcdir}/lzo-${pkgver}"
  make test # Larger test
  make check
}

package_liblzo2() {
  depends=('gcc-libs')

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_liblzo2-devel() {
  pkgdesc="Liblzo2 headers and libraries"
  options=('staticlibs')
  groups=('development')
  depends=("liblzo2=${pkgver}")

  mkdir -p ${pkgdir}/usr

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