# Maintainer: David Runge <dave@sleepmap.de>
pkgname=link
pkgver=3.0.2
pkgrel=1
pkgdesc="Synchronizes musical beat, tempo, and phase across multiple applications"
arch=('x86_64')
url="https://github.com/ableton/link"
license=('GPL2')
depends=('asio')
makedepends=('cmake' 'portaudio' 'qt5-tools' 'qt5-quickcontrols')
optdepends=('jack: for JACK examples'
            'portaudio: for portaudio based examples'
            'qt5-quickcontrols: for Qt examples')
source=("$pkgname-$pkgver.tar.gz::https://github.com/Ableton/link/archive/Link-${pkgver}.tar.gz"
        "${pkgname}-devendor-asio.patch")
sha512sums=('7ee81721272fe758f59889bd5c3cef4fae14189fda7113b46f71128d5ca2bed280dc2271a23ec522d49cd21653ae9999f1b58aa8c68b50e323e0dfa46d15c95e'
            '41b474ed14b6a72a637fdd796c11bda42aaceed342a2b9ab4dcce8724414e2f3e36a30b57484cf4e22493926f1e1b5eb3b818dd710efcc5cb996c6abe58a4230')

prepare() {
  mv -v "${pkgname}-Link-${pkgver}" "$pkgname-$pkgver"
  cd "$pkgname-$pkgver"
  patch -Np1 -i "../${pkgname}-devendor-asio.patch"
  mkdir -v build
}

build() {
  cd "$pkgname-$pkgver/build"
  cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DLINK_BUILD_JACK=ON \
    -DLINK_BUILD_QT_EXAMPLES=ON \
    ..
  make
}

check() {
  cd "$pkgname-$pkgver/build"
  bin/LinkCoreTest
  bin/LinkDiscoveryTest
}

package() {
  local dirs=('discovery' 'discovery/test' 'discovery/v1' 'link' 'link/v1'
  'platforms' 'platforms/asio' 'platforms/darwin' 'platforms/linux'
  'platforms/posix' 'platforms/stl' 'platforms/windows' 'test' 'test/serial_io'
  'util' 'util/test')
  cd "$pkgname-$pkgver/build"
  install -vDm 644 ../include/ableton/*.{ipp,hpp} \
    -t "${pkgdir}/usr/include/ableton"
  for dir in "${dirs[@]}"; do
    install -vDm 644 ../include/ableton/"${dir}"/*.hpp \
      -t "${pkgdir}/usr/include/ableton/${dir}"
  done
  install -vDm 755 bin/{LinkHut,QLinkHut,QLinkHutSilent} -t "${pkgdir}/usr/bin/"
  install -vDm 644 ../{{README,CONTRIBUTING}.md,*.pdf} \
    -t "${pkgdir}/usr/share/doc/${pkgname}/"
}
