# Maintainer: David Runge <dave@sleepmap.de>
# Contributor: speps <speps at aur dot archlinux dot org>
# Contributor: osc <farid at archlinux-br.org>

_name=SuperCollider
pkgname=supercollider
pkgver=3.10.3
pkgrel=1
pkgdesc="Environment and programming language for real time audio synthesis and algorithmic composition"
arch=('x86_64')
url="https://supercollider.github.io"
license=('GPL3')
groups=('pro-audio')
depends=('boost-libs' 'desktop-file-utils' 'fftw' 'jack' 'qt5-svg'
'qt5-webengine' 'qt5-websockets' 'yaml-cpp')
makedepends=('boost' 'cmake' 'emacs' 'qt5-tools')
checkdepends=('xorg-server-xvfb')
optdepends=('emacs: emacs interface'
            'gedit: gedit interface'
            'sc3-plugins: additional extension plugins for scsynth')
provides=('libscsynth.so')
source=("https://github.com/${pkgname}/${pkgname}/releases/download/Version-${pkgver}/${_name}-${pkgver}-Source-linux.tar.bz2"
        "${pkgname}-use_system_boost.patch"
)
install="${pkgname}.install"
sha512sums=('e6427ae367395e50e3f31986bab43aa53894f6d8c35563371c14940e6c3303068d419f95edf198509479d8ac7420400d8f9df7d4168a326db2f262b954ea2c24'
            'd9b2ef108673b11a27c63654ceacf3b7e51df11ce05fc6d9045abd219ea718c2552f5ea026a5182c272639e695a1073192013b14cae257e7e4b00dd3c303ecae')

prepare() {
  mv -v "${_name}-Source" "${pkgname}-${pkgver}"
  cd "${pkgname}-${pkgver}"
  # make sure system boost is used
  # https://github.com/supercollider/supercollider/issues/4096
  patch -Np1 -i ../"${pkgname}-use_system_boost.patch"
  mkdir -v build
}

build() {
  cd "${pkgname}-${pkgver}/build"
  cmake .. -DCMAKE_INSTALL_PREFIX=/usr \
           -DCMAKE_BUILD_TYPE=Release \
           -DLIBSCSYNTH=ON \
           -DFORTIFY=ON \
           -DSYSTEM_YAMLCPP=ON \
           -DSYSTEM_BOOST=ON \
           -DSC_VIM=OFF
  make VERBOSE=1
}

check() {
  cd "${pkgname}-${pkgver}/build"
  xvfb-run make test ARGS="-V" || warning "Known failing tests: https://github.com/supercollider/supercollider/issues/3555"
}

package() {
  cd "${pkgname}-${pkgver}/build"
  make DESTDIR="${pkgdir}" install
  install -t "${pkgdir}/usr/share/doc/${pkgname}/" \
    -vDm 644 ../{AUTHORS,{CHANGELOG,README,README_LINUX}.md}
}
