# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: TBK <alpine@jjtc.eu>
pkgname=leveldb
pkgver=1.23
pkgrel=0
_gtest=662fe38e44900c007eccb65a5d2ea19df7bd520e
_benchmark=7d0d9061d83b663ce05d9de5da3d5865a3845b79
pkgdesc="A fast and lightweight key/value database library by Google"
url="https://github.com/google/leveldb"
arch="all"
license="BSD-3-Clause"
makedepends="cmake samurai snappy-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/google/$pkgname/archive/$pkgver.tar.gz
	benchmark-$_benchmark.tar.gz::https://github.com/google/benchmark/archive/$_benchmark.tar.gz
	gtest-$_gtest.tar.gz::https://github.com/google/googletest/archive/$_gtest.tar.gz
	no-install-test-deps.patch
	benchmark.patch
	"

prepare() {
	rmdir third_party/benchmark
	rmdir third_party/googletest

	mv "$srcdir"/googletest-$_gtest third_party/googletest
	mv "$srcdir"/benchmark-$_benchmark third_party/benchmark

	# patch after completed third-party packages
	default_prepare
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=/usr/lib \
		-DLEVELDB_BUILD_TESTS=ON \
		-DLEVELDB_INSTALL=ON \
		-DBUILD_SHARED_LIBS=ON
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	mkdir -p "$pkgdir"/usr/share/doc
	cp -a doc "$pkgdir"/usr/share/doc/$pkgname
}

sha512sums="
ac15eac29387b9f702a901b6567d47a9f8c17cf5c7d8700a77ec771da25158c83b04959c33f3d4de7a3f033ef08f545d14ba823a8d527e21889c4b78065b0f84  leveldb-1.23.tar.gz
10d9cab9dd20b59d38ff89f499590d1648f3347052c8e7662e36120c9a7e8d0f9a6334f5be673de83ab894faf15cf69bfc90edd6030342e46f8bdb9f9f07d47c  benchmark-7d0d9061d83b663ce05d9de5da3d5865a3845b79.tar.gz
8c58145d8a19909ce57bf5fcfa69a9b65eced7521349204cf5e6e34772492de98c58831bc2bb36fea8b359b4ba5fd8b7fbc4a44e89dfc5e0cc686c8c30d65c80  gtest-662fe38e44900c007eccb65a5d2ea19df7bd520e.tar.gz
53f5b94aecfb81dcfde17319d36446fc4a0f5131991ed8bfab7f86d572870405e7926515617f0eb433e38c3de84b50fb00aba26a07804900fdd7b0974a44a12d  no-install-test-deps.patch
11979bdb870e42f3b977dbc849c36055d5144b9dac8d158d533de56fa84760f92139b97080c1cd804d3838cd0649386110586c00ffd389ffe096855f935033de  benchmark.patch
"
