# Contributor: André Klitzing <aklitzing@gmail.com>
# Maintainer: André Klitzing <aklitzing@gmail.com>
pkgname=rippled
pkgver=1.9.4
pkgrel=23
pkgdesc="Blockchain daemon implementing the Ripple Consensus Ledger"
options="net !check" # FIXME: 1 failure, rippled testsuite doesn't tell which one it is
url="https://ripple.com/"
# needs 64bit, build fails on s390x and ppc64le
#arch="aarch64 x86_64"
license="ISC"
makedepends="
	abseil-cpp-dev
	boost-dev
	c-ares-dev
	cmake
	grpc-dev
	libarchive-dev
	lz4-dev
	openssl-dev>3
	protobuf-dev
	re2-dev
	rocksdb7-dev
	samurai
	snappy-dev
	sqlite-dev
	zlib-dev
	"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/ripple/rippled/archive/$pkgver.tar.gz
	boost-1.81.patch
	disable-failing-test.patch
	gcc13.patch
	werrorformat.patch
	"

prepare() {
	default_prepare

	# don't add aports gitrev into build
	git init .
}

build() {
	cmake -B build -G Ninja \
		-Dstatic=OFF \
		-Dtests="$(want_check && echo ON || echo OFF)" \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release

	# using too many parallel jobs causes CI to run out of memory
	cmake --build build --parallel $((JOBS < 16 ? JOBS : 16))
}

check() {
	./build/rippled --unittest --unittest-jobs ${JOBS:-2}
}

package() {
	install -D -m644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE.md"
	install -D build/rippled "$pkgdir/usr/bin/rippled"
	install -D -m644 cfg/rippled-example.cfg "$pkgdir/etc/$pkgname/rippled.cfg"
	install -D -m644 cfg/validators-example.txt "$pkgdir/etc/$pkgname/validators.txt"
}

sha512sums="
8fd442c8c8950690f5325aa8653449b0e749992d600eae0e04ccefa9d92e59fad1948ea0472c4d4a678841f19953fbda44bef31c354d5e213ed3f1496dc9e89e  rippled-1.9.4.tar.gz
335a0748411f35721f322bf68c16afd12b6b7e1b274162f8322230b2e06f7bf047fd671060892865676eb4b3c08b0cd9cf80930e01efc7964826d35cd8980118  boost-1.81.patch
5df6abbea0252f42765d382f31194c2fa5137996adfaf8c9192a46c318f34e60d137ee690bd3baadea184d64f862040b91af169ee8dc226f67cf21e4ee60bf0a  disable-failing-test.patch
8b973674d8683d69ee9ab79dda278993d1c9e511442228fd25c3a062ab5f86d19005ff694ea0c6a0f5e70112fc199153a3fb57406f6265182239e34d3c5dae12  gcc13.patch
38d89924301425c5b349fae314a5c9eaca30ffbc6a51343d37d48fdf93d00afd5c439f860cf12e209c39d600936b0bd6aa13cf247c07419e226eab059b19a6a5  werrorformat.patch
"
