# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: OSAMC <https://github.com/osam-cologne/archlinux-proaudio>
# Contributor: Christopher Arndt <aur -at- chrisarndt -dot- de>

pkgname=python-rtmidi
pkgver=1.4.9
pkgrel=4
pkgdesc='Python bindings for the MIDI I/O library RtMidi'
arch=('x86_64')
url='https://github.com/SpotlightKid/python-rtmidi'
license=('MIT')
depends=('python' 'rtmidi')
makedepends=(
  'git'
  'python-installer'
  'python-wheel'
  'python-setuptools'
  'cython'
  'alsa-lib'
  'jack'
  'python-sphinx'
)
_commit='0a5aa06d46485cb2dab836bd20205f60efb95eed'
source=(
  "$pkgname::git+$url#commit=$_commit"
  'unbundle-rtmidi.patch'
  'remove-xdg-open.patch'
  'remove-dev-suffix.patch'
  'skip-broken-clean.patch'
)
b2sums=('SKIP'
        'b27c438fa93c00fd458fd8083302838ad0ca96c09c89f0993c6fdc09681f8eccddca53445925c1b437860faa488115d2bc33076a202a5dd730f44cef298c9831'
        'ad41a0730e09cee2c0729c7b79e497187bf6cf8fd603b3dbe4af061859a14e868d1522c746bee17c1a9587709a8cba38dd573bf876dff0f47d82dbe1876ffb2f'
        '083a035e09ac1338c6a96841ec8c360f1bf50b2a568ab39e3d388ef4205b25eb5e85062af6fb26e7ca19254d20e2ead45b3e8333695546790c85308a29f05ac5'
        '8a15a1b6a977bb2ab3bd642cefb5e136b7f76f7784a8a3d33678ee892771969e3fb20039b8de4850007dc166ef9cde9445bf66a475eb577f25a9edf947828338')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # use system rtmidi
  patch -p1 -i "$srcdir/unbundle-rtmidi.patch"

  # remove xdg-open from Makefile
  patch -p1 -i "$srcdir/remove-xdg-open.patch"

  # skip broken clean in Makefile
  patch -p1 -i "$srcdir/skip-broken-clean.patch"

  # remove -dev suffix from version
  patch -p1 -i "$srcdir/remove-dev-suffix.patch"
}

build() {
  cd "$pkgname"

  # module
  make dist

  # documentation
  make docs
}

package() {
  depends+=('libasound.so' 'libjack.so')
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE.txt

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.rst
  cp -vr docs/_build/html "$pkgdir/usr/share/doc/$pkgname"
}
