# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - re-add makedepend on java

pkgname=libphonenumber
pkgver=8.12.50
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)
license=(Apache)
depends=(icu protobuf boost-libs abseil-cpp)
makedepends=(boost cmake gtest git 'java-environment>=9')
options=(debug)
_commit=e1c6752b358569810fb33bcc9f5c75050e9533fe  # tags/v8.12.50^0
source=("git+$url#commit=$_commit" absl.diff)
sha256sums=('SKIP'
            'f6bceb2409ff7cba1e6947e6fdce3fe82b511b04fefcd1f597eceb13af67a8a4')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^libphonenumber-\|^v//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd $pkgname

  # Use our abseil-cpp
  git apply -3 ../absl.diff
}

build() {
  CXXFLAGS+=" -Wno-error=deprecated-declarations"  # readdir_r deprecation
  CXXFLAGS+=" -Wno-error=unused-variable"          # this is nuts
  cmake -S $pkgname/cpp -B build \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib
  cmake --build build
}

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

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

  DESTDIR="$pkgdir" cmake --install build
}