#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=jack2
pkgdesc="The JACK low-latency audio server w/o systemd or dbus"
pkgver=1.9.22
_commit=80149e552b56d6d57d754dc04d119b8170d27313  # refs/tags/v1.9.22
pkgrel=02
arch=(x86_64)
url="https://github.com/jackaudio/jack2"
makedepends=(alsa-lib db5.3 doxygen expat git libffado libsamplerate opus waf)
# jack breaks when built with LTO: https://github.com/jackaudio/jack2/issues/485
options=(!lto)
source=(git+$url#tag=$_commit?signed
	$pkgname-1.9.22-db-5.3.patch)

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

prepare() {
  patch -Np1 -d $pkgname -i ../$pkgname-1.9.22-db-5.3.patch

  # remove custom waflib, as we are using system provided waf
  rm -rv $pkgname/waflib
}

build() {
  local waf_options=(
    --prefix=/usr
    --htmldir=/usr/share/doc/$pkgname/html
    --autostart=none
    --doxygen=yes
    --classic
    --alsa=yes
    --db=yes
  )

  cd $pkgname
  export CXXFLAGS="$CXXFLAGS -I/usr/include/db5.3"
  export LDFLAGS="$LDFLAGS -ldb-5.3"
  export LINKFLAGS="$LDFLAGS"
  export PYTHONPATH="$PWD:$PYTHONPATH"
  waf configure "${waf_options[@]}"
  waf build
}

package() {
  license+=(LGPL2.1)
  depends=(
    alsa-lib libasound.so
    db5.3
    gcc-libs
    glibc
    libsamplerate libsamplerate.so
    opus libopus.so
   )
  optdepends=(
    'a2jmidid: for ALSA MIDI to JACK MIDI bridging'
    'libffado: for firewire support using FFADO'
    'jack-example-tools: for official JACK example-clients and tools'
    'jack2-docs: for developer documentation'
    'realtime-privileges: for realtime privileges'
  )
  conflicts=(jack)
  provides=(jack libjack.so libjacknet.so libjackserver.so)

  cd $pkgname
  export PYTHONPATH="$PWD:$PYTHONPATH"
  waf install --destdir="$pkgdir"
}

#---- license gpg-key sha256sums ----

license=(GPL2)

validpgpkeys=('62B11043D2F6EB6672D93103CDBAA37ABC74FBA0') # falkTX <falktx@falktx.com>

sha256sums=(SKIP
	11cff3fb28b26641866f11a60ebb969fa0d1a993a4478dba6d80d9f4f24dacfd) # jack2-1.9.22-db-5.3.patch

