# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Baptiste Jonglez <baptiste--aur at jonglez dot org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - set -DOPENDHT_LTO=OFF
#  - move cppunit to makedepends from checkdepends

pkgname=opendht
epoch=1
pkgver=3.2.0
pkgrel=1
pkgdesc="C++17 Distributed Hash Table (DHT) implementation"
arch=(x86_64)
url="https://github.com/savoirfairelinux/opendht"
license=(GPL3)
depends=(glibc gnutls nettle readline argon2 jsoncpp libjsoncpp.so fmt openssl llhttp)
makedepends=(git cmake msgpack-cxx restinio asio cython python-setuptools cppunit)
optdepends=('python: to use the Python bindings'
            'msgpack-cxx: linking against opendht')
source=(git+${url}#tag=v$pkgver
        llhttp.patch)
sha256sums=('12f71503ba7253ca5545676ffed7a6fea9497e0227c9e2112d1901b7c8a63412'
            '0f0b394656f719508ea83dd3ea87b08245fa1413a91e50a144dede20b2e3ca22')

prepare() {
  patch -d $pkgname -p1 < llhttp.patch # Fix llhttp lib name
}

build() {
  cmake -B build -S ${pkgname} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DOPENDHT_DOCUMENTATION=OFF \
    -DOPENDHT_TESTS=ON \
    -DOPENDHT_SYSTEMD=ON \
    -DOPENDHT_SYSTEMD_UNIT_FILE_LOCATION=/usr/lib/systemd/system/ \
    -DOPENDHT_INDEX=ON \
    -DOPENDHT_PYTHON=ON \
    -DOPENDHT_HTTP=ON \
    -DOPENDHT_PROXY_SERVER=ON \
    -DOPENDHT_PROXY_CLIENT=ON \
    -DOPENDHT_PUSH_NOTIFICATIONS=ON \
    -DOPENDHT_LTO=OFF
  make -C build
}

check() {
  # https://github.com/savoirfairelinux/opendht/issues/568
  make -C build test || echo "Tests failed"
}

package() {
  make -C build DESTDIR="${pkgdir}" install
}