# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Jason Chu <jchu@xentac.net>

pkgbase=openal
pkgname=(
  openal
  #openal-examples
)
pkgver=1.23.1
pkgrel=1.1
pkgdesc="Cross-platform 3D audio library, software implementation"
url="https://github.com/kcat/openal-soft"
arch=(x86_64 aarch64)
license=(LGPL)
depends=(
  gcc-libs
)
makedepends=(
  alsa-lib
  cmake
  # ffmpeg
  # fluidsynth
  git
  jack2
  # libmysofa
  # libpulse
  libsndfile
  ninja
  # pipewire
  # portaudio
  # qt5-base
  # sdl2
  base-devel
)
optdepends=(
  # 'qt5-base: alsoft-config GUI Configurator'
  # 'fluidsynth: MIDI rendering'
  # 'libmysofa: makemhr tool'
)
_commit=d3875f333fb6abe2f39d82caca329414871ae53b  # tags/1.23.1
source=("git+https://github.com/kcat/openal-soft#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd openal-soft
  git describe --tags | sed 's/^openal-soft-//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd openal-soft
}

build() {
  local cmake_options=(
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_LIBDIR=lib
    -DALSOFT_UTILS=off
    -DALSOFT_BACKEND_SDL=off
    -DALSOFT_BACKEND_PULSEAUDIO=off
    -DALSOFT_BACKEND_PIPEWIRE=off
    -DALSOFT_BACKEND_PORTAUDIO=off
  )

  cmake -S openal-soft -B build -G Ninja "${cmake_options[@]}"
  cmake --build build
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_openal() {
  provides+=(libopenal.so)

  DESTDIR="$pkgdir" cmake --install build
  install -Dt "$pkgdir/usr/share/doc/openal" -m644 openal-soft/docs/*

  cd "$pkgdir"
  _pick examples usr/bin/al{hrtf,latency,multireverb} # alffplay, alloopback
  _pick examples usr/bin/al{play,record,reverb,stream,tonegen}
}

# package_openal-examples() {
#   pkgdesc+=" (example programs)"
#   depends=("openal=$pkgver-$pkgrel" sdl2 libsndfile ffmpeg)
#   optdepends=()
#   mv examples/* "$pkgdir"
# }

# vim:set sw=2 sts=-1 et:
