# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Adrian "asie" Siekierka, 2023

pkgname=(wf-sox wf-sox-dev)
_pkgver=14.6.0.4
pkgver=14.6.0.4.r3753.3b5dd42c
pkgrel=1
epoch=
pkgdesc="The Swiss Army knife of sound processing tools (sox_ng fork)"
arch=("x86_64" "aarch64")
url="https://codeberg.org/sox_ng/sox_ng"
license=("GPL2" "LGPL2.1" "BSD-3-Clause")
source=(
	"$pkgname::git+https://codeberg.org/sox_ng/sox_ng.git#tag=sox_ng-$_pkgver"
)
depends=(runtime-gcc-libs runtime-musl)
makedepends=(runtime-musl-dev)
sha256sums=(
	'SKIP'
)

. "/wf/config/runtime-env-vars.sh"

. "../templates/git-pkgver.PKGBUILD"

prepare() {
	cd wf-sox

	# Ignore system-provided versions of libgsm and liblpc10.
	sed -i \
		-e 's/libgsm" = yes/libgsm" = never/' \
		-e 's/liblpc10" = yes/liblpc10" = never/' \
		configure.ac

	autoreconf -vfi
}

build() {
	cd wf-sox
	CFLAGS="-O2 -flto $WF_RUNTIME_INCLUDES" \
	CXXFLAGS="-O2 -flto $WF_RUNTIME_INCLUDES" \
	LDFLAGS="-static $WF_RUNTIME_LDFLAGS" \
	./configure --prefix="$WF_PATH" \
		--sysconfdir=/etc \
		--without-libltdl --without-ladspa --without-magic --without-png \
		--without-id3tag --without-mad --without-lame \
		--without-twolame \
		--disable-symlinks \
		--with-distro="Wonderful Toolchain"
	make all
}

package_wf-sox() {
	cd wf-sox
	make DESTDIR="$pkgdir" install
	cd "$pkgdir"
	wf_relocate_path_to_destdir

	mv bin/sox_ng$WF_EXECUTABLE_SUFFIX bin/wf-sox$WF_EXECUTABLE_SUFFIX

	rm -r include share
	rm -r lib/libsox*.a lib/libsox*.la lib/pkgconfig
}

package_wf-sox-dev() {
	cd wf-sox
	make DESTDIR="$pkgdir" install
	cd "$pkgdir"
	wf_relocate_path_to_destdir

	rm -r bin share
}
