# Maintainer: Natanael Copa <ncopa@alpinelinux.org>

# NOTE: Please do not push changes to this package without requesting a test run
# across all supported architectures.  Untested changes to this package may be
# reverted at any time, at the core team's discretion.

pkgname=guile
pkgver=3.0.9
pkgrel=1
pkgdesc="portable, embeddable Scheme implementation written in C"
url="https://www.gnu.org/software/guile/"
arch="all"
license="LGPL-3.0-or-later AND GPL-3.0-or-later"
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs $pkgname-readline"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	gc-dev
	gmp-dev
	"
makedepends="
	$depends_dev
	libffi-dev
	libtool
	libunistring-dev
	ncurses-dev
	readline-dev
	texinfo
	"
source="https://ftp.gnu.org/gnu/guile/guile-$pkgver.tar.gz
	0002-Mark-mutex-with-owner-not-retained-threads-test-as-u.patch
	failing-encoding-test.patch
	failing-filesys-test.patch
	gcc14.patch
	"

case "$CARCH" in
# Otherwise we'll get strip: Unable to recognise the format of the input file
x86|x86_64|loongarch64) options="$options !strip" ;;
esac

prepare() {
	# remove sticky bit. it breaks the test suite
	find . -type d -exec chmod g-s {} \;

	default_prepare

	# remove tests that don't pass with musl libc.
	# most of them fail because musl only supports UTF-8.
	rm -f \
		./test-suite/tests/time.test \
		./test-suite/tests/encoding-escapes.test \
		./test-suite/tests/i18n.test \
		./test-suite/tests/encoding-iso88597.test \
		./test-suite/tests/iconv.test \
		./test-suite/tests/suspendable-ports.test \
		./test-suite/tests/r6rs-ports.test

	case "$CARCH" in
	x86)
		# probably needs sse2?
		rm -f ./test-suite/tests/numbers.test
		;;
	esac
}

build() {
	# programming language
	CFLAGS="$CFLAGS -g0 -O2" \
	CXXFLAGS="$CXXFLAGS -g0 -O2" \
	./configure \
		--build="$CBUILD" \
		--host="$CHOST" \
		--prefix=/usr \
		--disable-error-on-warning \
		--disable-static
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
}

doc() {
	default_doc
	license="GFDL-1.3-or-later"
}

readline() {
	amove \
		usr/lib/guile/3.0/ccache/ice-9/readline.go \
		usr/lib/guile/3.0/extensions/guile-readline.so \
		usr/lib/guile/3.0/extensions/guile-readline.so.0 \
		usr/lib/guile/3.0/extensions/guile-readline.so.0.0.0 \
		usr/share/guile/3.0/ice-9/readline.scm
}

sha512sums="
6fd14f0860c7f5b7a9b53c43a60c6a7ca53072684ddc818cd10c720af2c5761ef110b29af466b89ded884fb66d66060894b14e615eaebee8844c397932d05fa2  guile-3.0.9.tar.gz
54a9fe0fa2ea83da7ae61f96612e3e653ec80f60ab41d1995dc44bd05c7ff68cc4fab36a655e8835c4ab1cf0966765a299ef2d73cb9f69d3ef955e6aeaa8062d  0002-Mark-mutex-with-owner-not-retained-threads-test-as-u.patch
257b32dda7a9195f14dadb00e2699fa7711198087f78cc100b768cf9d5bb8a0d69fb5b84003a893e05c63b7f6fb9f550d3991fb41d840d9826214529d20610c1  failing-encoding-test.patch
810e4afc6b097c169672e23725426a9a523c1bdeabe7770e3dfb9ad0b2e0c0f93c7207e1d34b1190f71ae8518a488ecae3f114094db5aa74f086d42ae7a30381  failing-filesys-test.patch
563e85f476bb74d9ce0657909f62feaf8fec87c3b2c9dc97f02e4dd88ae32eff202bf34c1ff87a49c0a8d2b63849fceb0c7beb154414cdeb6770b2999728b224  gcc14.patch
"
