# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=abiword
pkgver=3.0.2
pkgrel=1
pkgdesc="A fully-featured word processor"
url="http://www.abisource.com"
arch="all"
license="GPL-2.0-or-later"
makedepends="gtk+3.0-dev libgsf-dev enchant-dev fribidi-dev wv-dev
	popt-dev libjpeg-turbo-dev librsvg-dev bzip2-dev goffice-dev pcre-dev
	libxslt-dev"

# openxml plugin
makedepends="$makedepends boost-dev"

# collab plugin
makedepends="$makedepends gnutls-dev libsoup-dev dbus-glib-dev"

subpackages="$pkgname-dev $pkgname-doc $pkgname-plugins"

_plugins="applix babelfish bmp clarisworks collab docbook eml epub
	freetranslation garble gdict gimp google hancom hrtext iscii kword
	latex loadbindings mht mif mswrite openwriter openxml opml paint
	passepartout pdb pdf presentation s5 sdw t602 urldict wikipedia wml
	xslfo"

for _i in $_plugins; do
	subpackages="$subpackages $pkgname-plugin-$_i:$_i"
done

source="http://www.abisource.com/downloads/$pkgname/$pkgver/source/$pkgname-$pkgver.tar.gz
	fix-black-drawing-regression.patch
	fix-nullptr-c++98.patch"

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

build() {
	cd "$builddir"
	export CXXFLAGS="$CXXFLAGS -std=gnu++98"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--enable-shared \
		--disable-static \
		--enable-plugins
	make
}

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

_do_plugin() {
	local plugin="$1"
	pkgdesc="Abiword $1 plugin"
	local dir="usr/lib/abiword-${pkgver%.*}/plugins"
	mkdir -p "$subpkgdir"/$dir
	mv "$pkgdir"/$dir/$plugin.so "$subpkgdir"/$dir/
}

for _i in $_plugins; do
	eval "$_i() { _do_plugin $_i; }"
done

plugins() {
	pkgdesc="Abiword plugins, all of them"
	depends=
	for _i in $_plugins; do
		depends="$depends $pkgname-plugin-$_i"
	done
	mkdir -p "$subpkgdir"
}

sha512sums="29ce9e80b3b85ab2933e7d39216771d8c4e05db5255eaed0cf8e1d032ffaac2cb1880bf24e754196ad5dae4969a1c2101ce4dc9c1db14604adc2f852b6a17fe3  abiword-3.0.2.tar.gz
cae9a08047cd97d11acea25a2f0b0ca4e8e4556b462eb476507fa178a7412221839febfeb36bebf491bb94d53525c4584d86230f96c403a7ceb2dec4223be8fe  fix-black-drawing-regression.patch
fbfedad9b58ba44fac53142fae77dce499b9d3f01acb2967e6507b94a8206436240e924ae420c1b92f707a0e08df9874c8de034532032cf6d8df9b28dcd8a3cf  fix-nullptr-c++98.patch"
