# Forked from Alpine: downgrade because of breakage in 3.35 (#1008)

pkgname=sqlite-tcl
pkgver=9999
_pkgver=3.34.1
pkgrel=0
pkgdesc="Sqlite Tcl Extension Architecture (TEA)"
url="https://www.sqlite.org/"
arch="all"
license="Public-Domain"
makedepends="readline-dev tcl-dev sqlite-dev libtool autoconf automake"
subpackages="$pkgname-doc"
options="!check" # no testsuite from upstream

# compute _ver
_a=${_pkgver%%.*}
_b=${_pkgver#$_a.}
_b=${_b%%.*}
_c=${_pkgver#$_a.$_b.}
_c=${_c%%.*}
case $_pkgver in
	*.*.*.*)_d=${_pkgver##*.};;
	*.*.*)	_d=0;;
esac
[ $_b -lt 10 ] && _b=0$_b
[ $_c -lt 10 ] && _c=0$_c
[ $_d -lt 10 ] && _d=0$_d
_ver=${_a}${_b}${_c}$_d

# these variables depend on _ver being set
source="https://www.sqlite.org/2021/sqlite-autoconf-$_ver.tar.gz"
builddir="$srcdir/sqlite-autoconf-$_ver/tea"

prepare() {
	default_prepare

	if [ -f "$startdir"/../sqlite/APKBUILD ]; then
		(
		_tclver=$_pkgver
		. "$startdir"/../sqlite/APKBUILD
		if [ "$_tclver" != "$_pkgver" ]; then
			die "sqlite version mismatch ($_tclver != $_pkgver)"
		fi
		)
	fi
}

build() {
	./configure \
		--build="$CBUILD" \
		--host="$CHOST" \
		--prefix=/usr \
		--with-system-sqlite \
		--enable-threads
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm644 license.terms \
		"$pkgdir"/usr/share/licenses/$pkgname/license.terms
}

sha512sums="adaa306ebacfbeeea6efe71aa964b1dee4a05ade794c55c7afad8693ed291354e9daa2449226c4dc50fbfa5919dfc9a17dea946f01171ff63d472af78cbed987  sqlite-autoconf-3340100.tar.gz"
