# Contributor: Nathan Johnson <nathan@nathanjohnson.info>
# Maintainer: Nathan Johnson <nathan@nathanjohnson.info>
pkgname=libcouchbase
pkgver=3.3.12
pkgrel=0
pkgdesc="C client library for Couchbase"
url="https://developer.couchbase.com/community"
arch="all"
license="Apache-2.0"
depends_dev="
	openssl-dev>3
	snappy-dev
	"
makedepends="
	$depends_dev
	cmake
	libev-dev
	libevent-dev
	libtool
	libuv-dev
	perl
	samurai
	zlib-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-utils
	$pkgname-doc
	$pkgname-libevent
	$pkgname-libev
	$pkgname-libuv
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/couchbase/libcouchbase/archive/$pkgver.tar.gz
	fix_socktest.patch
	"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DLCB_NO_MOCK=ON \
		-DLCB_SKIP_GIT_VERSION=ON
	cmake --build build
}

check() {
	cd "$builddir"/build
	ctest -j1 -E 'check-(select|libevent|libev|libuv)-sock-tests'
}

package() {
	 DESTDIR="$pkgdir" cmake --install build
}

dev() {
	default_dev
	mv "$subpkgdir"/usr/bin/cbc-write-config \
		"$pkgdir"/usr/bin
	rmdir "$subpkgdir"/usr/bin
}

libevent() {
	pkgdesc="$pkgdesc (libevent backend)"
	depends="$pkgname=$pkgver-r$pkgrel"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libcouchbase/libcouchbase_libevent.so "$subpkgdir"/usr/lib
}

libev() {
	pkgdesc="$pkgdesc (libev backend)"
	depends="$pkgname=$pkgver-r$pkgrel"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libcouchbase/libcouchbase_libev.so "$subpkgdir"/usr/lib
}

libuv() {
	pkgdesc="$pkgdesc (libuv backend)"
	depends="$pkgname=$pkgver-r$pkgrel"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libcouchbase/libcouchbase_libuv.so "$subpkgdir"/usr/lib
}

utils() {
	pkgdesc="$pkgdesc (command line utilities)"
	depends="$pkgname=$pkgver-r$pkgrel"
	provides="$pkgname-bin=$pkgver-r$pkgrel"

	amove usr/bin
}

sha512sums="
9aaee2fbf5b94779b5dc47a2c3258a59b5c8312d233f0525c34d2c85df3c08196ca72e59a9b26bcfd554647fb4e858529069e87080721b8500e6a47881ef2158  libcouchbase-3.3.12.tar.gz
72319b86fdd91728723ccb091e72199788a84e2ec9ea12c0fcd1ed686eb155ec11e0addbff96735f83e7f31764a85650f0483b6e76d3a8bee16f71b2751fe4a9  fix_socktest.patch
"
