# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: speps <speps at aur dot archlinux dot org>
# Contributor: Philipp Überbacher <murks at lavabit dot com>

pkgbase=zita-resampler
pkgname=(
  zita-resampler
  zita-resampler-docs
)
pkgver=1.11.2
pkgrel=2.1
pkgdesc="A C++ library for resampling audio signals"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://kokkinizita.linuxaudio.org/linuxaudio"
license=(GPL-3.0-or-later)
makedepends=(
  gcc-libs
  glibc
  libsndfile
)
source=($url/downloads/$pkgname-$pkgver.tar.xz
        zita-resampler-1.11.2-makefile.patch)
sha512sums=('1598c9ead4bf858d3a11677c9512932077e1d0b83588682eba402820936fa1cfc5fe1112abbecd945469b4ae2f7a6f59938a5fbb0fdd79de3b0a3a73703b03dd'
            'e59081959ce76c93c919d2b25f5d7f078f2cd6469559886b35cb448785fe5e481b54d339450c9bc6fb34d6fd83ef03b431998296c15c31511867cf7988c84a4b')
b2sums=('627b309b38b238902b1cad2cb0963d0182f8f4cc4bc72efcd2b9ecc9810f019968c141e31ffb94110e8c4ca781e1c57b7d3393a3d4699b3f90873958b34ce47c'
        '8a94d3c5962b27e8fa11a7cdf8a719b600474540ecbd7b35462315f44d33caa6e419428cb76d5deb2913286a459495be558fcc7155630944a9fbca239fd61902')

prepare() {
  cd $pkgname-$pkgver

  patch -Np1 -i ${srcdir}/zita-resampler-1.11.2-makefile.patch

  # remove march=native
  sed -e '/native/d' -i {source,apps}/Makefile
}

build() {
  cd $pkgname-$pkgver
  # libs
  make -C source
  # create lib link for building apps
  ln -sv lib$pkgname.so.$pkgver source/lib$pkgname.so
  # apps
  make LDFLAGS+=" -L../source" CXXFLAGS+=" -I../source" -C apps
  # cleanup link
  rm -rv source/lib$pkgname.so
}

package_zita-resampler() {
  depends=(gcc-libs glibc)
  optdepends=(
    'libsndfile: for zresample and zretune'
    'zita-resampler-docs: for documentation'
  )
  provides=(libzita-resampler.so)

  for location in $pkgbase-$pkgver/{source,apps}; do
    make DESTDIR="$pkgdir/" PREFIX=/usr SUFFIX="" install -C $location
  done
}

package_zita-resampler-docs() {
  pkgdesc+=" - documentation"

  install -vDm 644 $pkgbase-$pkgver/{AUTHORS,README,docs/*}  -t "$pkgdir/usr/share/doc/$pkgbase/"
}
