# Template file for 'gerbil'
pkgname=gerbil
version=0.18.1
revision=1
_gitrev="23c30a6062cd7e63f9d85300ce01585bb9035d2d"
build_style="configure"
configure_args="--prefix=/usr/lib/gerbil --enable-march="
hostmakedepends="git tar"
makedepends="openssl-devel sqlite-devel zlib-devel"
depends="gcc openssl"
checkdepends="$depends"
short_desc="Opinionated dialect of Scheme designed for Systems Programming"
maintainer="Leah Neukirchen <leah@vuxu.org>"
license="LGPL-2.1-or-later, Apache-2.0"
homepage="https://cons.io/"
nocross="yes"

do_fetch() {
	# We fetch a Git repo here because the build system insists
	# on using submodules.
	rm -rf ${wrksrc}
	git clone https://github.com/mighty-gerbils/gerbil ${wrksrc}
	cd ${wrksrc}
	git checkout ${_gitrev}

	# don't let the test suite clash with netdata's port
	vsed -i -e 's/:19999/:15296/' src/std/net/httpd-test.ss
}

# Uses custom levels of optimization.
pre_configure() {
	export CFLAGS=${CFLAGS/-O2/}
	export CXXFLAGS=${CXXFLAGS/-O2/}
}
pre_build() {
	export CFLAGS=${CFLAGS/-O2/}
	export CXXFLAGS=${CXXFLAGS/-O2/}
}

do_check() {
	./build.sh env gxtest ./...
}

do_install() {
	DESTDIR=$DESTDIR ./install.sh

	mv $DESTDIR/usr/lib/gerbil/v*/share $DESTDIR/usr/share
	vmkdir usr/bin
	for b in $DESTDIR/usr/lib/gerbil/v*/bin/g[ex]*; do
		ln -sfr $b $DESTDIR/usr/bin
	done

	./build.sh env gxtags -t emacs $DESTDIR/usr/lib/gerbil/v*/src
	sed -i 's|/destdir/gerbil-[^/]*/|/|g' src/TAGS
	cp -v src/TAGS $DESTDIR/usr/lib/gerbil/v*/src
}
