# Contributor: Magnus Sandin <magnus.sandin@valitron.se>
# Maintainer: Magnus Sandin <magnus.sandin@valitron.se>
pkgname=lsp-plugins
pkgver=1.2.21
pkgrel=0
pkgdesc="Collection of free plugins compatible with LADSPA, LV2 and LinuxVST"
url="https://lsp-plug.in"
# loongarch64: make fetch fails on the builder
arch="all !loongarch64"
license="LGPL-3.0-or-later"
install="$pkgname.post-upgrade"
makedepends="
	cairo-dev
	cmd:php
	cmd:git
	gst-plugins-base-dev
	jack-dev
	ladspa-dev
	libsndfile-dev
	libxrandr-dev
	lv2-dev
	mesa-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-dev
	liblsp-r3d-glx-lib
	$pkgname-xdg::noarch
	$pkgname-clap
	$pkgname-ladspa
	$pkgname-lv2
	$pkgname-vst2
	"
source="
	lsp-plugins-$pkgver.tar.gz::https://github.com/lsp-plugins/lsp-plugins/archive/refs/tags/$pkgver.tar.gz
	"
options="!check" # no testsuite

# GitLab CI and builders run armhf/armv7 as 32-bit arches on aarch64. Thus, we
# cannot rely on the uname -m output on these platforms, as the build system is
# broken and does not use the gcc default architecture, rather passing -march
# values manually.
case "$CARCH" in
armhf) export ARCHITECTURE=armv6l ;;
armv7) export ARCHITECTURE=armv7l ;;
esac

build() {
	export CFLAGS="$CFLAGS -O2"
	export CXXFLAGS="$CXXFLAGS -O2 -fno-lto"
	export LDFLAGS="-fno-lto"
	make clean
	make \
		PREFIX=/usr \
		ADD_FEATURES=xdg \
		ARTIFACT_EXPORT_HEADERS=1 \
		config
	make fetch
	make
}

package() {
	make DESTDIR="$pkgdir" install
	rm "$pkgdir"/usr/lib/*.a
}

lib() {
	pkgdesc="$pkgdesc (lsp-plugins gfx library)"

	amove usr/lib/liblsp-r3d-glx-lib*
}

xdg() {
	pkgdesc="$pkgdesc (XDG integration)"

	amove usr/share/applications
	amove usr/share/desktop-directories
	amove usr/share/icons
	amove etc/xdg/menus/applications-merged
}

clap() {
	pkgdesc="$pkgdesc (clap integration)"
	depends="liblsp-r3d-glx-lib=$pkgver-r$pkgrel"

	amove usr/lib/clap
}

ladspa() {
	pkgdesc="$pkgdesc (ladspa integration)"
	depends="liblsp-r3d-glx-lib=$pkgver-r$pkgrel"

	amove usr/lib/ladspa
}

lv2() {
	pkgdesc="$pkgdesc (lv2 plugins)"
	depends="liblsp-r3d-glx-lib=$pkgver-r$pkgrel"

	amove usr/lib/lv2
}

vst2() {
	pkgdesc="$pkgdesc (vst2 plugins)"
	depends="liblsp-r3d-glx-lib=$pkgver-r$pkgrel"

	amove usr/lib/vst
}

sha512sums="
c099b555b7baf01ac496a5136a363331357d1b98f6de87c1d16288cb4827c8b1b72cde04ecd896bfc78c58521ec00f0d4537bc15776c4e30b86113a7fc519d09  lsp-plugins-1.2.21.tar.gz
"
