# Contributor: Michael Pirogov <vbnet.ru@gmail.com>
# Maintainer: Michael Pirogov <vbnet.ru@gmail.com>
pkgname=odyssey
pkgver=1.3
pkgrel=3
pkgdesc="Scalable PostgreSQL connection pooler"
url="https://github.com/yandex/odyssey"
arch="x86_64 x86" # limited by machinarium supported architecture
license="BSD-3-Clause"
makedepends="
	argp-standalone
	cmake
	linux-pam-dev
	samurai
	openssl-dev
	postgresql-dev
	"
options="!check" # https://github.com/yandex/odyssey/issues/134
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/yandex/odyssey/archive/$pkgver.tar.gz
	argp.patch
	types.patch
	gcc14.patch
	odyssey.initd
	odyssey.confd"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	export CXXFLAGS="$CXXFLAGS -I$(pg_config --includedir)/server)"
	export CMAKE_GENERATOR=Ninja
	cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	cd "$builddir"/build/test
	./odyssey_test
}

package() {
	install -Dm755 "$builddir"/build/sources/$pkgname \
		"$pkgdir"/usr/bin/$pkgname
	install -Dm600 "$builddir"/$pkgname.conf \
		"$pkgdir"/etc/$pkgname.conf.example
	install -Dm755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname

}

sha512sums="
d78fd48439074fe75b800051d69ed611efdafdceff339a9fbae5bb4c961c1f934c4c6e6e10c0350ad240977d8ad655586e55c7f7153528abebb7175a62fe68e6  odyssey-1.3.tar.gz
8b3c6ca3490cf96d3578161fb7ed35fc3fbb56bed8d71dcdf4cbdce284cd352b14fc0ad6c309e087b198c4fdab3859d274825a0f77f4282b27bfd7df7077f52d  argp.patch
d938644040a555349a50f8b9cbe7b111c105f8a3d96609152aeb86880c7c6529f0a05202358bce7674ce2244d8657ae0e1781a7386e94ed124e5b975e29d987d  types.patch
5f9c1ed5b57418a6ed87b3543ba246919e8abb236783bb5f0e5cec0bd49ebe3955005360799433b3270295056dc67eaf740f03aee7b9ca15f3ec8a098b758d9e  gcc14.patch
a1f129b06476c103465e9e649e88e1d5da071a377453e7a5b6dce4734928e8a5eb1c29b4a026d38b81587e6ca813ac3f533c668a264ae4ae7997716c2ec85715  odyssey.initd
1e9fdd3cc7cf0d789b2ea57b275cca6de171d3adc887f1cddfb5a0b273988a514db133e58403fd5a01ec0511446b8746c6a78137df1d5141c7499065e9bd745a  odyssey.confd
"
