# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=cairo
pkgver=1.18.2
pkgrel=0
pkgdesc="A vector graphics library"
url="https://cairographics.org/"
arch="all"
options="!check"  # Recursive dependency on gtk+2.0 for check.
license="LGPL-2.1-or-later OR MPL-1.1"
depends_dev="
	$pkgname-tools=$pkgver-r$pkgrel
	fontconfig-dev
	freetype-dev
	libxext-dev
	libxrender-dev
	pixman-dev
	xcb-util-dev
	"
makedepends="
	$depends_dev
	expat-dev
	glib-dev
	gtk-doc
	libpng-dev
	meson
	zlib-dev
	"
subpackages="
	$pkgname-dbg
	$pkgname-static
	$pkgname-dev
	$pkgname-doc
	$pkgname-gobject
	$pkgname-tools
	"
source="https://gitlab.freedesktop.org/cairo/cairo/-/archive/$pkgver/cairo-$pkgver.tar.bz2
	musl-stacksize.patch
	"

# secfixes:
#   1.17.4-r1:
#     - CVE-2019-6462
#   1.16.0-r2:
#     - CVE-2020-35492
#   1.16.0-r1:
#     - CVE-2018-19876

build() {
	abuild-meson \
		-Db_lto=true \
		-Ddefault_library=both \
		-Dgtk_doc=true \
		-Dtests="$(want_check && echo enabled || echo disabled)" \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

gobject() {
	pkgdesc="$pkgdesc (gobject bindings)"

	amove usr/lib/libcairo-gobject.so.*
}

tools() {
	pkgdesc="$pkgdesc (development tools)"

	amove usr/bin
	amove usr/lib/cairo/libcairo-trace.*
}

sha512sums="
8db31b675791b892379bc5fca7f421d3e8ebca9c3cbcdc27fa80efb1274f12d89276a54fa1ec18008f81de9b1dc2fafb9fbee9ee368e893e8b035a332d07e141  cairo-1.18.2.tar.bz2
86f26fe41deb5e14f553c999090d1ec1d92a534fa7984112c9a7f1d6c6a8f1b7bb735947e8ec3f26e817f56410efe8cc46c5e682f6a278d49b40a683513740e0  musl-stacksize.patch
"
