# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=cairo
pkgver=1.14.10
pkgrel=0
pkgdesc="A vector graphics library"
url="http://cairographics.org/"
arch="all"
license="LGPL-2.0-or-later MPL-1.1"
depends=
depends_dev="fontconfig-dev freetype-dev libxrender-dev pixman-dev
	xcb-util-dev libxext-dev $pkgname-tools"
makedepends="$depends_dev zlib-dev expat-dev glib-dev libpng-dev autoconf automake libtool"
subpackages="$pkgname-dev $pkgname-doc $pkgname-gobject $pkgname-tools $pkgname-dbg"
# fontconfig-ultimate https://github.com/bohoomil/fontconfig-ultimate
_ultver="2016-04-23"
source="http://cairographics.org/releases/$pkgname-$pkgver.tar.xz
	fontconfig-ultimate-$_ultver.tar.gz::https://github.com/bohoomil/fontconfig-ultimate/archive/$_ultver.tar.gz
	musl-stacksize.patch
	"
builddir="$srcdir/$pkgname-$pkgver"

prepare() {
	cd "$builddir"
	default_prepare || return 1

	# infinality
	for j in "$srcdir"/fontconfig-ultimate-$_ultver/$pkgname/*.patch; do
		msg "Applying ${j}"
		patch -p1 -i $j || return 1
	done
}

build() {
	cd "$builddir"
	autoreconf -vif
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--enable-ft \
		--enable-gobject \
		--enable-pdf \
		--enable-png \
		--enable-ps \
		--enable-tee \
		--enable-xcb \
		--enable-xlib-xrender \
		--disable-xlib-xcb \
		--disable-static \
		|| return 1
	make || return 1
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install || return 1
}

gobject() {
	pkgdesc="$pkgdesc (gobject bindings)"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libcairo-gobject.so.* "$subpkgdir"/usr/lib/
}

tools() {
	pkgdesc="$pkgdesc (development tools)"
	mkdir -p "$subpkgdir"/usr/lib/cairo
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/ || return 1
	mv "$pkgdir"/usr/lib/cairo/libcairo-trace.* \
		"$subpkgdir"/usr/lib/cairo/
}

sha512sums="a381d97e6046da0012eb5595118efb95ff02e3e84310682e458b503ebf22d6b2663bcc1391980768bb9cd02ae809b8df2e11d6200b48745dc5ec824c342b5852  cairo-1.14.10.tar.xz
d8185f4ec74f44c4746acf7e79bba7ff7ffd9d35bdabeb25e10b4e12825942d910931aa857f1645e5c8185bcb40a1f1ffe1e7e647428e9ea66618b2aec52fac3  fontconfig-ultimate-2016-04-23.tar.gz
86f26fe41deb5e14f553c999090d1ec1d92a534fa7984112c9a7f1d6c6a8f1b7bb735947e8ec3f26e817f56410efe8cc46c5e682f6a278d49b40a683513740e0  musl-stacksize.patch"
