# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
#
# TODO: Separate packages into subpackages?
# TODO: Install even packages from the full tarball?
# TODO: Figure out how to run tests.
pkgname=racket
pkgver=6.12
pkgrel=1
pkgdesc="A general purpose programming language in the Lisp-Scheme family"
url="https://racket-lang.org/"
arch="all"
license="LGPL-3.0-or-later MIT"
depends="ca-certificates libressl2.6-libcrypto libressl2.6-libssl"
makedepends="chrpath libffi-dev libucontext-dev paxmark"
subpackages="$pkgname-dev $pkgname-doc"
source="https://download.racket-lang.org/releases/$pkgver/installers/$pkgname-minimal-$pkgver-src.tgz
	paxmark.patch
	musl-fixes.patch
	makefile-fix-bashism.patch
	libressl.patch"
builddir="$srcdir/$pkgname-$pkgver"

prepare() {
	default_prepare
	cd "$builddir"

	# Remove bundled libffi to be sure that system-provided is used.
	rm -Rf src/foreign/libffi
}

build() {
	cd "$builddir"/src

	export CFLAGS="$CFLAGS -D_GNU_SOURCE"
	export LDFLAGS="$LDFLAGS -lucontext"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--target=$CTARGET \
		--prefix=/usr \
		--sysconfdir=/etc \
		--enable-shared \
		--disable-docs
	make
}

package() {
	cd "$builddir"/src

	make install DESTDIR="$pkgdir"

	cd "$pkgdir"

	# Remove redundant RPATH.
	chrpath -d usr/bin/racket usr/lib/racket/gracket

	# Needed when running on Grsecurity kernel.
	paxmark m usr/bin/racket
	paxmark m usr/lib/racket/gracket

	mkdir -p usr/share/licenses/$pkgname
	mv usr/share/racket/COPYING* usr/share/licenses/$pkgname/

	rm -Rf usr/share/applications
}

sha512sums="f342f0e475abb8ceb692cc66cde8d0741f0b106721210d427b569453ead642bbb951dd182378bcb468c53e170c2691cf05a64ccd49fc5a701ff24047874eb82a  racket-minimal-6.12-src.tgz
ff7804e37cbab237921f7d4c334f6cbb2909e9284b7b2cec1dfd3e73ec189b8ecf0cb0cabd1abedb09020f2a57ad4c32088ea73e5cb71afdafce39a7a718b10c  paxmark.patch
6af0ae984ac54f167f0513795905e9dc845e1c1554935f73958d4e21c5fad35eca791866cfdf94dfcee586ec28335d90520d769010c63cd6ab528e6be3f2c21c  musl-fixes.patch
1a96718e6a065bd08f0ff046e799fd4d7657d99789b2cdda8cf7cdd8c2d91742dd34fb43f4c6fabde89a764e073bdecdd96e2caeee49feaac242d30b17d6422b  makefile-fix-bashism.patch
72fd6870c849e6f94a426041ccee0e94146c85e33fe7da4a4bdbc72f8b81fac846935f9abfe91170a91dc32180652ec1d0260ec94587e3480ce1fa578400f8f4  libressl.patch"
