# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=jimtcl
pkgver=0.83
pkgrel=0
pkgdesc="An open-source, small footprint implementation of Tcl"
url="https://github.com/msteveb/jimtcl"
arch="all"
license="BSD-2-Clause"
depends_dev="openssl-dev"
makedepends="
	$depends_dev
	asciidoc
	readline-dev
	sqlite-dev
	tcl
	zlib-dev
	"
options="net"  # fix check with abuild rootbld
subpackages="
	$pkgname-dbg
	$pkgname-readline
	$pkgname-sqlite3
	$pkgname-dev
	$pkgname-doc
	"
source="https://github.com/msteveb/jimtcl/archive/$pkgver/jimtcl-$pkgver.tar.gz
	include-stdio-h.patch
	tests-skip-exec2-3.2.patch
	tests-skip-socket.patch
	"

prepare() {
	default_prepare

	# tty tests fail on builders - no tty available there.
	rm tests/tty.test

	cp -r "$builddir" "$builddir-static"
}

build() {
	# CRTSCTS
	export CFLAGS="$CFLAGS -D_BSD_SOURCE"
	_build --shared

	cd "$builddir-static"
	_build
}

_build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--docdir=/usr/share/doc/$pkgname \
		--full \
		--with-mod=sqlite3,readline,rlprompt \
		"$@"
	# https://github.com/msteveb/jimtcl/issues/256
	CFLAGS="$CFLAGS -D_GNU_SOURCE=1" \
		make -j1
}

check() {
	make check
}

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

	install -m644 "$builddir-static"/libjim.a -t "$pkgdir"/usr/lib/
}

readline() {
	pkgdesc="Interface to readline and Tcl wrapper for Jim Tcl"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/jim/readline.so
	amove usr/lib/jim/rlprompt.tcl
}

sqlite3() {
	pkgdesc="Interface to sqlite3 for Jim Tcl"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/jim/sqlite3.so
}

dev() {
	default_dev
	amove usr/bin/build-jim-ext
}

sha512sums="
fbdcb84eb5d6be55fbb8d192654e22e3bc6e0e2685bc68bd0e4e5cbf9ac9cde7012780b02b9c98830954d28733494d5aacd9595c4cec353dd0945ee09d4194b4  jimtcl-0.83.tar.gz
3f2ff295f72015234c71f8893b3d52ac0c1de18c8e70c8b64037363598955f2c78e9f4d5c91d037629e7a4445c9f1ec19d3ec8153043b4d1812074e1cf41d33f  include-stdio-h.patch
188df3307b0983bda5904f1ec26ba195f7cb435244bc516d4b8b5377320ab37a76f44500af6faac1e3dfee2dae8bc8f942b8543268d56aa21bd59de4d34099da  tests-skip-exec2-3.2.patch
cbc3f08d23cfe7ebd45e677a09e7178436e728a965ab7af44d6e27621049c1cdc82768c4e81397004be3486bf3f767684601ec28d3584ea14d3dde69ccdd8bdb  tests-skip-socket.patch
"
