# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Lex Black <autumn-wind at web dot de>
# Contributor: TingPing <tingping@tingping.se>
# Contributor: Guillaume Horel <guillaume.horel@gmail.com>

pkgbase=brotli06
pkgname=(brotli06 brotli06-testdata)
pkgver=0.6.0
pkgrel=2
pkgdesc='Brotli compression library - legacy 0.6.x version'
arch=(x86_64 powerpc64le)
license=('MIT')
url='https://github.com/google/brotli'
depends=('gcc-libs')
makedepends=('cmake' 'python' 'python2')
source=("brotli-$pkgver.tar.gz::https://github.com/google/brotli/archive/v$pkgver.tar.gz")
sha512sums=('36caa277790efeb5bff0fdc090cdcf00fd9995c4e81a60ed31d36af2e13848ec1afe5d84e6926eebbee013525191e9404e112cb7fbede16097221c5bc3dfb5d5')

prepare() {
  mkdir -p build
}

build() {
  cd build
  cmake ../brotli-$pkgver -DCMAKE_INSTALL_PREFIX="/usr" -DCMAKE_INSTALL_LIBDIR="/usr/lib/brotli06"
  make
}

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

package_brotli06() {
  cd build
  make DESTDIR="$pkgdir" install
  install -D -m644 "$srcdir"/brotli-$pkgver/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

  install -dm755 "$pkgdir"/usr/include/brotli06
  mv "$pkgdir"/usr/include/brotli "$pkgdir"/usr/include/brotli06/

  for _so in libbrotlicommon libbrotlidec libbrotlienc; do
    mv "$pkgdir"/usr/lib/brotli06/$_so.so.$pkgver "$pkgdir"/usr/lib/
    ln -sf ../$_so.so.$pkgver "$pkgdir"/usr/lib/brotli06/$_so.so
  done

  mv "$pkgdir"/usr/bin/bro{,-0.6}

  sed -e 's|/include$|/include/brotli06|' -i "$pkgdir"/usr/lib/brotli06/pkgconfig/*.pc
}

package_brotli06-testdata() {
  depends=()

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