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

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


sha256sums=(a)

# Copyright     : Obarun
#------------------------
# Maintainer    : Eric Vidal <eric@obarun.org>
# Contributors  : Obarun Packagers <obpack@obarun.org>
#----------------
# Obarun PkgSrc : https://git.obarun.org/pkg/obextra/jack2
#--------------------------------------------------------------
# DESCRIPTION ]

pkgbase=jack2
pkgver=1.9.22
pkgrel=2
pkgdesc="The JACK low-latency audio server"
 url="https://github.com/jackaudio/jack2"
_commit=80149e552b56d6d57d754dc04d119b8170d27313  # refs/tags/v1.9.22
source=(git+$url#tag=$_commit?signed
        $pkgbase-1.9.22-db-5.3.patch)

pkgname=(
    'jack2'
    'jack2-dbus'
    'jack2-docs'
)

## preparation ###

prepare() {
  patch -Np1 -d $pkgbase -i ../$pkgbase-1.9.22-db-5.3.patch
  # remove custom waflib, as we are using system provided waf
#  (
#    touch __init__.py
#    rm -rv waflib
#  )
#  patch -Np1 -i ../bdb_5.3.patch  
  rm -rv $pkgbase/waflib
}


#----------------------
# BUILD CONFIGURATION ]

makedepends=(
    'alsa-lib'
    'dbus'
    'doxygen'
    'expat'
    'git'
    'libffado'
    'libsamplerate'
    'opus'
    'waf'
)

options=(
    '!lto'
)

#--------------------
# BUILD PREPARATION ]

prepare() {
    cd $pkgbase

    # remove custom waflib, as we are using system provided waf
    (
      touch __init__.py
      rm -rv waflib
    )
}

#--------
# BUILD ]

_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
}

build() {
    cd $pkgbase

    export LINKFLAGS="$LDFLAGS"
    export PYTHONPATH="${PWD}:${PYTHONPATH}"

    waf configure \
        --prefix=/usr \
        --htmldir="/usr/share/doc/${pkgbase}/html" \
        --autostart=none \
        --doxygen=yes \
        jack-example-tools=no \
        --classic \
        --dbus
    waf build
}

#----------
# PACKAGE ]

package_jack2() {
    license+=(LGPL2.1)

    depends+=(
    alsa-lib libasound.so
    db5.3
    dbus libdbus-1.so
    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-dbus: for dbus integration'
        'jack2-docs: for developer documentation'
        'realtime-privileges: for realtime privileges'
    )
    conflicts=(
        'jack'
    )
    provides=(
        'jack'
        'libjack.so'
        'libjacknet.so'
        'libjackserver.so'
    )

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

    ( cd "$pkgdir"

    _pick jack2-dbus usr/bin/jack{dbus,_control}
    _pick jack2-dbus usr/share/dbus-1/services/*
    _pick jack2-docs usr/share/doc/$pkgbase/html
    )
}

package_jack2-dbus() {
    pkgdesc+=" (dbus integration)"

    depends=(
        'gcc-libs'
        'glibc'
        'jack2'
        'libdbus-1.so'
        'libexpat.so'
        'libjackserver.so'
        'python-dbus'
    )

    mv -v jack2-dbus/* "$pkgdir"
}

package_jack2-docs() {
    pkgdesc+=" (documentation)"

    mv -v jack2-docs/* "$pkgdir"
}

#--------------------
# ARCH LICENSE AUTH ]

arch=(x86_64)
license=(GPL2 LGPL2.1)

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

sha512sums=(SKIP
            'f5a5abaf6a0c0a7326b60b8bfe2eff84251d27037cfec7e6dc3194c7ceb296290779fdb26dca188cfbcf49f0a8a62707506584a1f7b0ed36c39f8a794154c4eb')
 
 
