# Maintainer  (AUR): Caleb Maclennan <caleb@alerque.com>
# Contributor: Xavier Devlamynck <magicrhesus@ouranos.be>
# Contributor: Marti Raudsepp <marti@juffo.org>
# Contributor: Travis Hegner <travis.hegner@gmail.com>
# Contributor: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>

# parabola changes and rationale:
# - don't autodetect x86 extensions at compile time (-march=native)
#   as it would break on machines that don't have the all the extensions
#   that the build machine has
# - added --disable-libwebrtc not to require sse2 (parabola minimum system
#   requirements require an i686 compatible machine, and the P6 architecture
#   only has sse and MMX, and not sse2)

pkgname=pjproject
pkgver=2.9
pkgrel=1
pkgdesc='Open source SIP stack and media stack'
arch=('i686' 'x86_64' 'armv7h')
url='http://www.pjsip.org/'
license=('GPL')
depends=('openssl' 'portaudio' 'speex' 'alsa-lib' 'libsamplerate' 'util-linux' 'ffmpeg' 'libsrtp' 'opus')
makedepends=('e2fsprogs' 'python')
optdepends=('alsa-lib' 'e2fsprogs' 'python')
source=("http://www.pjsip.org/release/$pkgver/$pkgname-$pkgver.tar.bz2")
sha256sums=('d185ef7855c8ec07191dde92f54b65a7a4b7a6f7bf8c46f7af35ceeb1da2a636')

build() {
  cd "$pkgname-$pkgver"
  export CXXFLAGS="$CXXFLAGS -fPIC"
  if [ "$CARCH" = "i686" ]; then
    export CXXFLAGS="$CXXFLAGS -march=i686"
  fi
  export CFLAGS="$CXXFLAGS -DNDEBUG"
  ./configure --prefix=/usr --with-external-speex --with-external-srtp --with-external-pa --with-external-gsm --disable-oss --enable-shared --disable-opencore-amr --disable-v4l2 --disable-video --disable-sound --disable-libwebrtc
  echo "#define PJ_HAS_IPV6 1" >> "$srcdir/$pkgname-$pkgver/pjlib/include/pj/config_site.h"
  make -j1 dep
  make -j1
}

package() {
  cd "$pkgname-$pkgver"
  make -j1 DESTDIR="$pkgdir" install
  install -D -m755 pjsip-apps/bin/pjsua-*gnu* "$pkgdir"/usr/bin/pjsua
}
