# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgname=libphonenumber
pkgver=8.13.45
pkgrel=2
epoch=1
pkgdesc="Google's common library for parsing, formatting, and validating international phone numbers"
url="https://github.com/googlei18n/libphonenumber"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=('Apache-2.0 AND BSD-3-Clause')
depends=(
  abseil-cpp
  gcc-libs
  glibc
  icu
  protobuf
)
makedepends=(
  cmake
  git
  gtest
  jre-openjdk-headless
)
source=(
  "git+$url#tag=v$pkgver"
  0001-Use-find_package-for-protobuf.patch
)
b2sums=('db600668e2d14975e9450185831a920ae72677dbc2bf68c02b5846d57e0264d844aba62f79d51b15b7dc0479a9320e0e6af7f2c84d95b1befa33352222c7cea0'
        '8fc1c65d863051052bb1cb3759a252a3b36a9dffa1335eae4d043821797651e57ca8902cced0672d3c47192b50b9b54436a1551ce65b2e9a4bd82351a58ef1ac')

prepare() {
  cd $pkgname

  # Use official protobuf cmake target instead of
  # custom one, fixes build with protobuf 23
  git apply -3 ../0001-Use-find_package-for-protobuf.patch
}

build() {
  local cmake_options=(
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_CXX_STANDARD=17
    -DUSE_BOOST=OFF
    -DUSE_STDMUTEX=ON
  )

  cmake -S $pkgname/cpp -B build "${cmake_options[@]}"
  cmake --build build
}

check() {
  cmake --build build --target tests
}

package() {
  depends+=(
    libicu{uc,i18n}.so
    libprotobuf.so
  )
  provides+=(
    libgeocoding.so
    libphonenumber.so
  )

  DESTDIR="$pkgdir" cmake --install build

  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 $pkgname/LICENSE.Chromium
}

# vim:set sw=2 sts=-1 et:
