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

pkgname=jami-daemon
pkgver=20210308
pkgrel=1
_pjprojectver=2.10
pkgdesc="Free and universal communication platform which preserves the users’ privacy and freedoms (daemon component)"
arch=(x86_64)
url="https://jami.net"
license=(GPL3)
groups=(jami)
depends=(opendht yaml-cpp alsa-lib libpulse jack jsoncpp dbus-c++ ffmpeg gnutls
         expat libupnp libnatpmp libva libvdpau libsecp256k1 util-linux opus
         openssl asio fmt http-parser libarchive)
makedepends=(git msgpack-c restinio autoconf-archive)
#checkdepends=(cppunit)
_commit=8d428f44847399d9e858ff0090934db095ba8ee3
source=(git+https://git.jami.net/savoirfairelinux/ring-daemon.git#commit=${_commit}
        https://github.com/pjsip/pjproject/archive/${_pjprojectver}/pjproject-${_pjprojectver}.tar.gz)
noextract=(pjproject-${_pjprojectver}.tar.gz)
sha512sums=(SKIP a67f083df175b536b4e6a7b7fe39e07d3ee805d6917ec64a50694542a7455c33a100889191044ab3fa679b6656774a6be045621aa53510b5f04cdde9ddd59893)

prepare() {
  cd ring-daemon
  cp ../pjproject-${_pjprojectver}.tar.gz contrib/tarballs
  mkdir contrib/native
  autoreconf -fvi
}

build() {
  cd ring-daemon/contrib/native
  ../bootstrap \
      --disable-downloads \
      --disable-all \
      --enable-pjproject
  make DEPS_pjproject=

  cd ../..
  ./configure \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --libexecdir=/usr/lib \
    --sysconfdir=/etc
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

# Disabled because some tests (TURN) use the network.
#check() {
#  cd ring-daemon
#  make -k check
#}

package() {
  cd ring-daemon
  make DESTDIR="${pkgdir}" install
}
