# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: damir <damir@archlinux.org>

pkgname=ladspa
pkgver=1.17
pkgrel=5.1
pkgdesc="Linux Audio Developer's Simple Plugin API (LADSPA)"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=(LGPL-2.1)
url="https://www.ladspa.org/"
depends=(
  gcc-libs
  glibc
)
makedepends=(libsndfile)
optdepends=('libsndfile: for applyplugin')
options=(!distcc)
source=(
  https://ladspa.org/download/ladspa_sdk_$pkgver.tgz
  $pkgname-1.17-plugin_underlinking.patch
  fix-memleak-in-plugin-scanning.patch
)
sha512sums=('c096e70d245c50ffad379f2c9aab2735c205dfe7c27b5710cad6e43b39f8accc7b8bd2cd7ebbea2c399ad76018b3d4c701ed271de552d098b12ab218a58f0497'
            '9660937df8cfcd2005f8e6b4d7257a6d295a2d7e06979dd05ff2894461e91fc3f812497878673724ee9209bffd67fbb690fbdc3669ecb5932503d0770454301b'
            'e80a575e6afe42f9d0ac1234a7832a29fb9362c7ab7b2d6b14cc3e6da6a9ba67af886cf09f1c0b78c161205084f705049fb4dc22fe2795efaeb7d94da90dc93e')
b2sums=('234f6c42e2736d250259b9473f70def136bcf57c2395d79e3a3cd6da715181dbfa87c1c35e8f0b840e0c5c00c39bfbb93d1ddd73b4c1547140caa080589d91b3'
        'a997afed65bd747c970e0110b1d9d8a3ea69e3ff30c7b9fa65177597661fc2043b252ea90b5eaac24dd5b770480bac7eac1eec31a98ccf0780f69828ca986ffa'
        'b2235b41d9638cceb93a41452f1f0b710bc3f9264fe735972099244dfc8d98d354c7d15084d79b0bdfc4fa3f437f9368f81aa0ebdb7e39df5900fbbf172927c2')

prepare() {
  cd ${pkgname}_sdk_$pkgver
  patch -Np0 -i "../fix-memleak-in-plugin-scanning.patch"
  # fix underlinking of plugins
  patch -Np1 -i ../$pkgname-1.17-plugin_underlinking.patch
  # add LDFLAGS for full RELRO
  sed -e "s#-O2#${CFLAGS} ${LDFLAGS}#" -i src/Makefile
}

build() {
  make -C ${pkgname}_sdk_$pkgver/src
}

package() {
  local make_options=(
    INSTALL_PLUGINS_DIR="$pkgdir/usr/lib/ladspa/"
    INSTALL_INCLUDE_DIR="$pkgdir/usr/include/"
    INSTALL_BINARY_DIR="$pkgdir/usr/bin/"
    install
    -C ${pkgname}_sdk_$pkgver/src
  )
  make "${make_options[@]}"
  install -vDm 644 ${pkgname}_sdk_$pkgver/doc/*.{html,txt} -t "$pkgdir/usr/share/doc/$pkgname"
}

