# Maintainer: David Runge <dvzrv@archlinux.org>

_name=Tidal
pkgname=haskell-tidal
pkgver=1.7.8
pkgrel=14
pkgdesc="A domain specific language for live coding pattern."
arch=('x86_64')
url="https://tidalcycles.org/"
license=('GPL3')
groups=('pro-audio')
depends=('ghc' 'ghc-libs' 'glibc' 'haskell-bifunctors' 'haskell-clock'
'haskell-colour' 'haskell-hosc' 'haskell-mwc-random' 'haskell-network'
'haskell-primitive' 'haskell-random' 'haskell-vector' 'supercollider')
makedepends=('uusi')
checkdepends=('haskell-microspec')
optdepends=('sc3-plugins: Examples using special UGens')
conflicts=('tidalcycles')
replaces=('tidalcycles')
source=("$pkgname-$pkgver.tar.gz::https://github.com/tidalcycles/${_name}/archive/refs/tags/${pkgver}.tar.gz")
sha512sums=('1ca3a8de260731349f41824ce284504edb0cdc68c4c00153f99fb307b34cdc96a306f14e86603edc402934df740489a08ac16743c69e5cde0f6fa433eab6e0e3')
b2sums=('bed7d0140ebcc1480e5d4c5d47b0efd2cf64c7862af756026f191da655e547bd0fec7349f4fedfe1bfa3aa32f785612dd782a302d18d0e196e5ed8f7adaaf61e')

prepare() {
  mv -v "${_name}-$pkgver" "$pkgname-$pkgver"
  uusi -u hosc $pkgname-$pkgver/tidal.cabal
}

build() {
  cd "$pkgname-$pkgver"
  runhaskell Setup configure -O \
                             --enable-shared \
                             --enable-executable-dynamic \
                             --disable-library-vanilla \
                             --prefix=/usr \
                             --docdir="/usr/share/doc/${pkgname}" \
                             --enable-tests \
                             --dynlibdir=/usr/lib \
                             --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd "$pkgname-$pkgver"
  runhaskell Setup test --show-details=direct
}

package() {
  cd "$pkgname-$pkgver"
  runhaskell Setup copy --destdir="${pkgdir}"
  install -vDm 744 register.sh "$pkgdir/usr/share/haskell/register/$pkgname.sh"
  install -vDm 744 unregister.sh "$pkgdir/usr/share/haskell/unregister/$pkgname.sh"
}
