# Description: A fast and lightweight key/value database library
# URL: https://github.com/google/leveldb
# Maintainer: Danny Rawlins, crux at romster dot me
# Depends on: snappy cmake ninja

name=leveldb
version=1.23
release=1
source=(https://github.com/google/leveldb/archive/$version/$name-$version.tar.gz
	0001-Allow-leveldbjni-build.patch
	0002-Added-a-DB-SuspendCompations-and-DB-ResumeCompaction.patch
	0003-allow-Get-calls-to-avoid-copies-into-std-string.patch
	0004-bloom_test-failure-on-big-endian-archs.patch
	0005-Restore-soname-versioning-with-CMake-build.patch
	0006-revert-no-rtti.patch)

build() {
	patch -d $name-$version -p1 -i $SRC/0001-Allow-leveldbjni-build.patch
	patch -d $name-$version -p1 -i $SRC/0002-Added-a-DB-SuspendCompations-and-DB-ResumeCompaction.patch
	patch -d $name-$version -p1 -i $SRC/0003-allow-Get-calls-to-avoid-copies-into-std-string.patch
	patch -d $name-$version -p1 -i $SRC/0004-bloom_test-failure-on-big-endian-archs.patch
	patch -d $name-$version -p1 -i $SRC/0005-Restore-soname-versioning-with-CMake-build.patch
	patch -d $name-$version -p1 -i $SRC/0006-revert-no-rtti.patch

	cmake -S $name-$version -B build -G Ninja \
		-D CMAKE_INSTALL_PREFIX=/usr \
		-D CMAKE_INSTALL_LIBDIR=lib \
		-D CMAKE_BUILD_TYPE=Release \
		-D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \
		-D CMAKE_C_FLAGS_RELEASE="$CFLAGS" \
		-D BUILD_SHARED_LIBS=ON \
		-DLEVELDB_BUILD_TESTS=OFF \
		-DLEVELDB_BUILD_BENCHMARKS=OFF \
		-Wno-dev

	cmake --build build
	DESTDIR=$PKG cmake --install build

cat <<- EOF > leveldb.pc
prefix=/usr
exec_prefix=\${prefix}
includedir=\${prefix}/include
libdir=\${exec_prefix}/lib

Name: ${name}
Description: A fast and lightweight key/value database library
Version: ${version}
Libs: -L\${libdir} -lleveldb
EOF

	install -Dm644 leveldb.pc $PKG/usr/lib/pkgconfig/leveldb.pc
}