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

pkgbase=brotli
pkgname=('brotli' 'brotli-devel' 'brotli-testdata')
pkgver=1.1.0
pkgrel=2
pkgdesc='Brotli compression library'
arch=('i686' 'x86_64')
license=('MIT')
url='https://github.com/google/brotli'
msys2_references=(
  "cpe: cpe:/a:google:brotli"
)
depends=('gcc-libs')
makedepends=(
  'cmake'
  'gcc'
  'ninja'
)
source=("${pkgbase}-${pkgver}.tar.gz::https://github.com/google/$pkgbase/archive/v${pkgver}.tar.gz")
sha256sums=('e720a6ca29428b803f4ad165371771f5398faba397edf6778837a18599ea13ff')

prepare() {
  cd brotli-${pkgver}

}

build() {
  cd brotli-${pkgver}

  cmake -GNinja -B "build-static" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED_LIBS=OFF
  cmake --build "build-static"

  cmake -GNinja -B "build-shared" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED_LIBS=ON
  cmake --build "build-shared"
}

check() {
  cd brotli-${pkgver}/build-shared

  make test
}

package_brotli() {
  cd brotli-${pkgver}

  cd build-static
  DESTDIR="${pkgdir}" cmake --install .
  rm -rf ${pkgdir}/usr/{include,lib}
  cd -
  cd build-shared
  DESTDIR="${pkgdir}" cmake --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 brotli-${pkgver}

  cd build-static
  DESTDIR="${pkgdir}" cmake --install .
  rm -rf ${pkgdir}/usr/bin
  cd -
  cd build-shared
  DESTDIR="${pkgdir}" cmake --install .
  rm -rf ${pkgdir}/usr/bin
}

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
}
