# Maintainer: Oleg Titov <oleg.titov@gmail.com>

pkgbase=brotli
pkgname=('brotli' 'brotli-devel' 'python-brotli' 'brotli-testdata')
pkgver=1.0.9
pkgrel=2
pkgdesc='Brotli compression library'
arch=('i686' 'x86_64')
license=('MIT')
url='https://github.com/google/brotli'
depends=('gcc-libs')
makedepends=('cmake' 'python-devel')
source=("${pkgbase}-${pkgver}.tar.gz::https://github.com/google/$pkgbase/archive/v${pkgver}.tar.gz"
        brotli-rename-static-libs.patch
        09b0992b6acb7faa6fd3b23f9bc036ea117230fc.patch)
sha256sums=('f9e8d81d0405ba66d181529af42a3354f838c939095ff99930da6aa9cdf6fe46'
            '25c2e154e805f6bd2999343a3d38efefa213577e09f5ea932bfa7eb42cf97f35'
            '0b1c8045b4fa745e620b5c1a75377f9cda839fbb07c90bf3358b583866f063ee')

prepare() {
  cd brotli-${pkgver}
  patch -p1 -i ${srcdir}/brotli-rename-static-libs.patch
  patch -p1 -i ${srcdir}/09b0992b6acb7faa6fd3b23f9bc036ea117230fc.patch
  cd ..
  mkdir -p build
}

build() {
  cd "${srcdir}"/brotli-${pkgver}
  python setup.py build

  cd "${srcdir}"/build
  cmake \
    -DCMAKE_INSTALL_PREFIX="/usr" \
    -DCMAKE_INSTALL_LIBDIR="/usr/lib" \
    ../brotli-${pkgver}

  make
}

check() {
  cd brotli-${pkgver}
  make test
}

package_brotli() {
  cd build
  make DESTDIR=${pkgdir} install
  rm -rf ${pkgdir}/usr/{include,lib}
  install -D -m644 "${srcdir}"/brotli-${pkgver}/LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_brotli-devel() {
  depends=('brotli')
  cd build
  make DESTDIR=${pkgdir} install
  rm -rf ${pkgdir}/usr/bin
}

package_python-brotli() {
  depends=('python')

  cd brotli-${pkgver}

  /usr/bin/python setup.py install --skip-build -O1 --root="${pkgdir}"
  install -D -m644 "${srcdir}"/brotli-${pkgver}/LICENSE "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}

package_brotli-testdata() {
  depends=()

  cd brotli-${pkgver}
  install -dm755 "${pkgdir}"/usr/share/brotli
  cp -a tests/testdata "${pkgdir}"/usr/share/brotli/
  install -D -m644 "${srcdir}"/brotli-${pkgver}/LICENSE "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}
