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

pkgname=libphonenumber
pkgver=8.13.52
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
  'java-environment>=11'
  'java-environment<=17'
)
source=(
  "git+$url#tag=v$pkgver"
  0001-Use-find_package-for-protobuf.patch
)
b2sums=('e156a9038b9272f845d8eabbc466b67893b9f28de8fbd131a17bff8250dec5a639d9bffdafa27c3324bd9a955e49077254c1a90a112c4dd26378e38fdbe56372'
        '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=(
    -D CMAKE_INSTALL_PREFIX=/usr
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_CXX_STANDARD=17
    -D USE_BOOST=OFF
    -D USE_STDMUTEX=ON
  )

  case "${CARCH}" in
    riscv64) export CFLAGS+=' -Wno-error' ;;
  esac

  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:
