# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Eric Timmons <etimmons@alum.mit.edu>
# Contributor: Will Sinatra <wpsinatra@gmail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=sbcl
pkgver=2.4.8
pkgrel=0
pkgdesc="Steel Bank Common Lisp"
url="http://www.sbcl.org/"
# s390x/loongarch64: not currently supported
# riscv64/ppc64le: doesn't build
arch="all !ppc64le !s390x !riscv64 !loongarch64"
license="custom"
options="!check"
checkdepends="ed"
makedepends="
	emacs-nox
	linux-headers
	mpfr-dev
	sbcl-bootstrap
	zstd-dev
	"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.bz2::https://prdownloads.sourceforge.net/sbcl/sbcl-$pkgver-source.tar.bz2
	ppc-musl.patch
	march-armv5-removed.patch
	"

# This follows how other -stage0 aports work, see APKBUILD of
# sbcl-stage0 for a brief explanation of the bootstrap process.
provides="sbcl-bootstrap=$pkgver"
provider_priority=100 # highest

build() {
	#All systems can build with these features enabled
	all_arch_conf='--with-sb-core-compression --with-sb-linkable-runtime'

	#Please add additional package support by arch
	#armv7 is incapable of supporting sb:thread
	case "$CARCH" in
		armv7) conf="$all_arch_conf" ;;
		x86) conf="$all_arch_conf --fancy --with-sb-thread" ;;
		x86_64) conf="$all_arch_conf --fancy --with-sb-thread" ;;
		aarch64) conf="$all_arch_conf --fancy --with-sb-thread" ;;
		riscv64) conf="--with-sb-core-compression --fancy --with-sb-thread" ;;
		loongarch64) conf="$all_arch_conf" ;;
		ppc64le) conf="$all_arch_conf" ;;
	esac

	GNUMAKE=make ./make.sh sbcl --prefix=/usr $conf
}

package() {
	INSTALL_ROOT="$pkgdir/usr" \
		LIB_DIR="/usr/lib" \
		DOC_DIR="$pkgdir/usr/share/doc/$pkgname" \
		sh install.sh

	install -Dm644 COPYING \
		"$pkgdir"/usr/share/licenses/$pkgname/LICENSE.txt

	rmdir "$pkgdir"/usr/share/doc/$pkgname/html \
		"$pkgdir"/usr/share/info 2>/dev/null || true
}

sha512sums="
a958aa2284fba737ad8724b35a5de9871a1354515852d962650083afab45ac5202e5b7daee3c26d6c70f92d7da708d4de37a79d8f37414b03c5d9474d2f25e40  sbcl-2.4.8.tar.bz2
549cc9936ddbd4c19067a455dfad151bd0ce59200b2dce761de67e259e621e4174beefaa5a322886bcd731d2470d229a3e1b75a55a194c54e2feb7c0bcdffb37  ppc-musl.patch
b8b9b8d8e489bfa18d0c59de54420e5a930a9c0e4cb9ffe1fe9c69d6a10b67880601b66ca2fab0fe77733f722b6709bf8e1cd32a257398a6e28d61b50080e26e  march-armv5-removed.patch
"
