# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=megasdk
# NOTE: It's usually needed to also bump the megacmd aport.
pkgver=4.17.1d
pkgrel=1
pkgdesc="MEGA C++ SDK"
url="https://github.com/meganz/sdk"
# s390x: tests fail
# x86: blocked by crypto++-dev
arch="all !s390x !x86"
license="BSD-2-Clause"
depends_dev="
	c-ares-dev
	crypto++-dev
	curl-dev
	icu-dev
	libsodium-dev
	sqlite-dev
	"
makedepends="
	$depends_dev
	autoconf
	automake
	libtool
	linux-headers
	openssl-dev
	"
checkdepends="
	gtest-dev
	"
subpackages="$pkgname-dev"
source="https://github.com/meganz/sdk/archive/refs/tags/v$pkgver/megasdk-$pkgver.tar.gz
	0001-SDK-2974-fix-glibcxx-assertions-on-unit-test.patch

	fix-null-to-bool-cast.patch
	fix-missing-headers.patch
	fix-tests-include-iomanip.patch
	"
builddir="$srcdir/sdk-$pkgver"

prepare() {
	default_prepare

	# gtest requires at least c++14
	sed -i 's/-std=c++11/-std=c++14/g' configure.ac

	./autogen.sh
}

build() {
	# MEGAsdk still uses autohells for Linux builds and they don't provide
	# install task for cmake.
	# FIXME: the test suite crashes on a libstdc++ assertion. this means something is broken!
	CXXFLAGS="$CXXFLAGS -flto=auto"  \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-shared \
		--disable-chat \
		--disable-examples \
		--"$(want_check && echo enable || echo disable)"-tests \
		--with-cryptopp \
		--with-sodium \
		--with-sqlite \
		--without-ffmpeg \
		--without-libmediainfo \
		--with-cares \
		--without-freeimage \
		--without-pdfium \
		--with-gtest=/usr/lib
	make
}

check() {
	./tests/test_unit
}

package() {
	make DESTDIR="$pkgdir" install
}

sha512sums="
bc67910b0a5fbbe9bb5d9d6ef9a746f1762dbb9968d9c825fd0ede256ab674670d804c2d99c9c472f72b2f06fd2bac4765bd7fa7dbebb3746cd1e1cfd780d71c  megasdk-4.17.1d.tar.gz
6d3801e3c0e0d842fdbdf1695f5f89f2b048b651b2267cbbf7651dfab238b542e9f9fda13d08a799d86309b3e998c73dff301543fa04438b4951a873224a9580  0001-SDK-2974-fix-glibcxx-assertions-on-unit-test.patch
62bd518dbd01541f4300c887491d9d00ee03d0ee9b19d3d8ab419c8bce401999c98677e591c53acedc4a4fe0d90f4125a69ac0396c0dbb2dc250c2fedaec7720  fix-null-to-bool-cast.patch
d11dce3f9ed63ff4da76af547fb581ec3a60339b6a01c3bd239e6742986bdf16208d7849cadcbc85580b9f9d688c8df1365da0f14fe22d2e81c1348334536c80  fix-missing-headers.patch
a5214af48f6ac7ba39ba9b16609b9e2b3195f66f334cb261a4eb3ad2085e58081b592780e6196317a7a06ddb35f407bad38dece807cbe4b9ac9c688da1800738  fix-tests-include-iomanip.patch
"
