# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=pgloader
pkgver=3.6.9
pkgrel=3
pkgdesc="Migrate to PostgreSQL in a single command"
url="https://pgloader.io/"
# armhf,armv7: fails to build (Heap exhausted during garbage collection)
# ppc64le,riscv64,s390x,x86,loongarch64: blocked by sbcl
arch="all !armhf !armv7 !riscv64 !s390x !ppc64le !x86 !loongarch64"
# pgloader is licensed under PostgreSQL license, other licenses are for bundled
# dependencies
license="PostgreSQL AND MIT AND BSD AND Unlicense AND LGPL-2.1 AND GPL-2.0"
depends="
	so:libcrypto.so.3
	so:libsqlite3.so.0
	so:libz.so.1
	"
makedepends="
	sbcl
	freetds-dev
	openssl-dev
	sqlite-dev
	zlib-dev
	"
checkdepends="postgresql"
# We need newer cl+ssl with OpenSSL 3 support.
_clssl_gitrev=1e2ffc9511df4b1c25c23e0313a642a610dae352
source="https://github.com/dimitri/pgloader/releases/download/v$pkgver/pgloader-bundle-$pkgver.tgz
	https://github.com/cl-plus-ssl/cl-plus-ssl/archive/$_clssl_gitrev/cl-plus-ssl-$_clssl_gitrev.tar.gz
	remove-self-upgrade.patch
	"
builddir="$srcdir/pgloader-bundle-$pkgver"
# !check: tests require running PostgreSQL
# !strip: it strips too much
options="!check !strip"

prepare() {
	default_prepare

	rm -f software/cl+ssl-2022022-git
	mv "$srcdir"/cl-plus-ssl-$_clssl_gitrev software/cl+ssl-2022022-git
}

build() {
	local opts=
	case "$CARCH" in
		armhf | armv7 | x86) opts="DYNSIZE=1024";;
	esac

	make pgloader $opts
}

check() {
	make check
}

package() {
	install -D -m755 bin/pgloader -t "$pkgdir"/usr/bin/
}

sha512sums="
e8c336f044cddc9e95eb4958319e4a16b9ad962d144f2863874ee7d54d255705be9ebc2ed37521da0659143bb59cadfe58e2d646311bc32398d456af486906e6  pgloader-bundle-3.6.9.tgz
853df9bb68095ef0608ec2cc725258444481707b8c341b39f53d61cba997e65afa400114349e2d6ab680b40c6ce7d5aaf42f19fa129b22880406995758651340  cl-plus-ssl-1e2ffc9511df4b1c25c23e0313a642a610dae352.tar.gz
bf6a18d6c6aa440d1fe39802443987765f2da81a364ac35c02fbe5fcadc9caae553c4f2860f7e3030217f0dccbd25c519a04181c5626b4a59649eb910fcce32a  remove-self-upgrade.patch
"
