# Maintainer: James Ross-Gowan <rossymiles@gmail.com>

pkgbase=protobuf
pkgname=('protobuf' 'protobuf-devel')
pkgver=3.16.0
pkgrel=1
pkgdesc="Protocol Buffers - Google's data interchange format"
arch=('i686' 'x86_64')
url='https://developers.google.com/protocol-buffers/'
groups=('libraries')
license=('BSD')
depends=('gcc-libs' 'zlib')
makedepends=('zlib-devel')
source=(protobuf-${pkgver}.tar.gz::https://github.com/protocolbuffers/protobuf/archive/v${pkgver}.tar.gz)
sha256sums=('7892a35d979304a404400a101c46ce90e85ec9e2a766a86041bb361f626247f5')
noextract=("protobuf-${pkgver}.tar.gz")

prepare() {
  [[ -d ${srcdir}/protobuf-${pkgver} ]] && rm -rf ${srcdir}/protobuf-${pkgver}
  tar -xzf "${srcdir}/protobuf-${pkgver}.tar.gz"

  cd  ${srcdir}/protobuf-${pkgver}
  ./autogen.sh
}

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

  ./configure \
    --host=${CHOST} \
    --prefix=/usr
  make
  make DESTDIR="${srcdir}/dest" install
}

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

package_protobuf() {
  mkdir -p "${pkgdir}/usr/bin"
  cp -f "${srcdir}/dest/usr/bin/"*.dll "${pkgdir}/usr/bin/"
  install -Dm644 "${srcdir}/protobuf-${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_protobuf-devel() {
  pkgdesc="Protobuf headers and libraries"
  groups=('development')
  depends=("protobuf=${pkgver}")

  mkdir -p "${pkgdir}/usr/bin"
  cp -f "${srcdir}/dest/usr/bin/"*.exe "${pkgdir}/usr/bin/"
  cp -rf "${srcdir}/dest/usr/include" "${pkgdir}/usr/"
  cp -rf "${srcdir}/dest/usr/lib" "${pkgdir}/usr/"
}
