# $Id: PKGBUILD 144692 2015-10-22 10:48:31Z fyan $
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Håvard Pettersson <mail@haavard.me>
# Contributor: naxuroqa <naxuroqa at gmail.com>
# Contributor: Boohbah <boohbah at gmail.com>
# Contributor: Kevin MacMartin <prurigro at gmail dot com>

pkgname=toxcore
pkgver=3523
_commit=a25cc96b4f2aeaca169df834e39df796ac08f1bd
pkgrel=3
pkgdesc='Secure, configuration-free, P2P Skype replacement backend'
arch=('i686' 'x86_64')
url='https://tox.chat'
license=('GPL3')
depends=('libconfig' 'libsodium' 'libvpx' 'opus')
makedepends=('git' 'check')
conflicts=("tox")
provides=("tox")
backup=('etc/tox-bootstrapd.conf')
install=$pkgname.install
source=("git+https://github.com/irungentoo/toxcore.git#commit=$_commit"
        'toxcore.conf')
sha512sums=('SKIP'
            '71885e69f7b84955f6bdbf27b9e8196349cdd254b02b510433851bd218374d9c47aa7d3946dcc6a5cff6c8e705bc98d8a09de27039f60b8b088784cf8fa9d719')

pkgver() {
  cd $pkgname
  git rev-list --count HEAD
}

prepare() {
  cd $pkgname
  sed -i "s|/usr/local|/usr|" other/bootstrap_daemon/tox-bootstrapd.service
}

build() {
  cd $pkgname
  autoreconf -if
  ./configure \
    --prefix=/usr \
    --enable-daemon \
    --disable-ntox \
    --enable-tests
  make
}

check() {
  cd $pkgname
  make check || warning "Tests failed"
}

package() {
  cd $pkgname
  make DESTDIR="$pkgdir" install
  install -Dm644 "$srcdir/toxcore.conf" "$pkgdir/usr/lib/sysusers.d/toxcore.conf"
  install -Dm644 ./other/bootstrap_daemon/tox-bootstrapd.service "$pkgdir/usr/lib/systemd/system/tox-bootstrapd.service"
  install -Dm644 ./other/bootstrap_daemon/tox-bootstrapd.conf "$pkgdir/etc/tox-bootstrapd.conf"
}
