# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=graphite2
_realname=${pkgname/2/}
pkgver=1.3.14
pkgrel=6
pkgdesc="reimplementation of the SIL Graphite text processing engine"
options="!check" # Testsuite requires graphite 1
url="https://graphite.sil.org/"
arch="all"
license="LGPL-2.1-or-later OR MPL-1.1"
depends_dev="freetype-dev"
makedepends="$depends_dev cmake samurai"
subpackages="$pkgname-static $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/silnrsi/$_realname/archive/$pkgver.tar.gz
	cmake.patch
	"

builddir="$srcdir"/$_realname-$pkgver

build() {
	# static and shared version needs to be build in separated dirs
	# See https://github.com/silnrsi/graphite/pull/12#issuecomment-311756732

	# shared
	# they pass ndebug in release mode
	CFLAGS="$CFLAGS -O2 -flto=auto -DNDEBUG" \
	CXXFLAGS="$CXXFLAGS -O2 -flto=auto -DNDEBUG" \
	cmake -B build-shared -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_SKIP_INSTALL_RPATH=ON \
		-DGRAPHITE2_COMPARE_RENDERER=OFF \
		-DGRAPHITE2_NFILEFACE=ON \
		-DGRAPHITE2_VM_TYPE="direct"
	cmake --build build-shared

	# static
	cmake -B build-static -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_SHARED_LIBS=OFF \
		-DCMAKE_SKIP_INSTALL_RPATH=ON \
		-DGRAPHITE2_COMPARE_RENDERER=OFF \
		-DGRAPHITE2_NFILEFACE=ON \
		-DGRAPHITE2_VM_TYPE="direct"
	cmake --build build-static
}

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

sha512sums="
49d127964d3f5c9403c7aecbfb5b18f32f25fe4919a81c49e0534e7123fe845423e16b0b8c8baaae21162b1150ab3e0f1c22c344e07d4364b6b8473c40a0822c  graphite2-1.3.14.tar.gz
729fb5ce0b012dca27cda10ec2b8cdf90029394915072f3a11ee4a3ec1b62aa5d810ca118a428419ac88d0dd316b07de557601d1ce079d3f96bfff4be271addb  cmake.patch
"
