# Maintainer: David Runge <dave@sleepmap.de>
# Contributor: speps <speps at aur dot archlinux dot org>
# Contributor: Orivej Desh <masecretaire@gmx.fr>

_download_id=2491
pkgname=sonic-visualiser
pkgver=3.3
pkgrel=1
pkgdesc="A viewer and analyser of music audio files."
arch=('x86_64')
url="https://www.sonicvisualiser.org/"
license=('GPL2')
groups=('pro-audio')
depends=('capnproto' 'desktop-file-utils' 'hicolor-icon-theme' 'libfishsound'
'libid3tag' 'liblo' 'liblrdf' 'libmad' 'liboggz' 'libpulse' 'opusfile'
'portaudio' 'qt5-svg' 'rubberband' 'sord')
source=("https://code.soundsoftware.ac.uk/attachments/download/${_download_id}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('521aac13060713366cc6827c5b574977d58787eb54a07651d7b43df68c4a0164f45251617a4f46268c80ec966ac63c3af19a5e5b50ac03fbef4e0529d9dad467')

prepare() {
  cd "${pkgname}-${pkgver}"
  autoreconf -vfi
}

build() {
  cd "${pkgname}-${pkgver}"
  # DESTDIR still ignored
  # https://sourceforge.net/p/sv1/bugs/254
  export INSTALL_ROOT="${pkgdir}/"
  export LIBS="$(pkgconf --libs rubberband) ${LIBS}"
  ./configure --prefix=/usr
  make
}

package() {
  cd "${pkgname}-${pkgver}"
  # DESTDIR still ignored
  # https://sourceforge.net/p/sv1/bugs/254
  export INSTALL_ROOT="${pkgdir}/"

  make install
  # install some things separately, because build system is broken:
  # https://sourceforge.net/p/sv1/bugs/247/

  # desktop files
  install -t "${pkgdir}/usr/share/applications/" -vDm 644 "${pkgname}.desktop"
  # samples
  install -t "${pkgdir}/usr/share/${pkgname}/samples" -vDm 644 samples/*
  # templates
  install -t "${pkgdir}/usr/share/${pkgname}/templates" -vDm 644 templates/*
  # docs
  install -t "${pkgdir}/usr/share/doc/${pkgname}" \
    -vDm 644 {CHANGELOG,CITATION,README.{md,OSC}}
}
