# Maintainer: Alexander Epaneshnikov <alex19ep@archlinux.org>
# Maintainer: vantu5z <vantu5z@mail.ru>
# Contributor: der_fenix <derfenix@gmail.com>

pkgname=RHVoice
pkgver=git159f2372
pkgrel=1slint
slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"$pkgname (Free and open source synthesizer)"
"RHVoice is a free and open source speech synthesizer."
"It consists of the following components: command line tools, speech"
"modules for NVDA and Speech Dispatcher, Windows (SAPI5), Android App"
)
arch=('x86_64')
docs=("README.md" "LICENSE.md" "NEWS")
url="https://github.com/RHVoice/RHVoice"
license=('GPL3' 'custom' 'custom:by-nc-nd-4.0' 'custom:by-sa-4.0')
depends=('libpulse')
makedepends=('git' 'scons' 'speech-dispatcher' 'portaudio' 'libao')
optdepends=('rhvoice-dictionary-git: extended russian dictionary'
            'speech-dispatcher: for speech-dispatcher module support'
            'portaudio: for portaudio backend'
            'libao: for ao backend')
provides=(${pkgname%-git})
conflicts=(${pkgname%-git})
backup=('etc/RHVoice/RHVoice.conf')

pkgver() {
	cd "${pkgname%-git}"
	printf "%s" "$(git describe --long | sed 's/\([^-]*-\)g/r\1/;s/-/./g')"
}

build() {
#	git clone https://github.com/RHVoice/RHVoice.git
#    git clone https://github.com/RHVoice/victoria-ru.git
#    git clone https://github.com/RHVoice/evgeniy-rus.git
#    git clone https://github.com/RHVoice/evgeniy-eng.git
#    git clone https://github.com/rhvoice/aleksandr-hq-rus.git
#    git clone https://github.com/rhvoice/yuriy-rus.git
#    git clone https://github.com/rhvoice/volodymyr-ukr.git
#    git clone https://github.com/rhvoice/tatiana-rus.git
	cp -a ../cloned/* .
	cd RHVoice
	mkdir -p $PKG/etc/RHVoice
	cd doc
	for i in $(ls); do
		cd $i
		if [ -f RHVoice.conf ]; then
			if [ "$i" = "en" ]; then
				cp RHVoice.conf  $PKG/etc/RHVoice/
			else
				cp RHVoice.conf  $PKG/etc/RHVoice/RHVoice-${i}.conf
			fi
		fi
		mkdir -p $PKG/usr/doc/${pkgname}-$pkgver/$i
		if [ -f License.md ]; then
			pandoc -s -t html5 -o $PKG/usr/doc/${pkgname}-$pkgver/$i/License.html \
			--metadata pagetitle="License" License.md
		fi
		if [ -f Configuration-file.md ]; then
			pandoc -s -t html5 -o $PKG/usr/doc/${pkgname}-$pkgver/$i/Configuration-file.html \
			Configuration-file.md --metadata pagetitle="RHVoice"
		fi
		cd ..
	done
	cd ..
	pandoc -s -t html5 -o $PKG/usr/doc/${pkgname}-$pkgver/LICENSE.html \
	 --metadata pagetitle="LICENSE" LICENSE.md
	pandoc -s -t html5 -o $PKG/usr/doc/${pkgname}-$pkgver/README.html \
	 --metadata pagetitle="README" README.md
	git submodule init
	git config submodule.data/voices/victoria.url "$SRC/victoria-ru"
	git config submodule.data/voices/evgeniy-rus.url "$SRC/evgeniy-rus"
	git config submodule.data/voices/evgeniy-eng.url "$SRC/evgeniy-eng"
	git config submodule.data/voices/aleksandr-hq.url "$SRC/aleksandr-hq-rus"
	git config submodule.data/voices/yuriy.url "$SRC/yuriy-rus"
	git config submodule.data/voices/volodymyr.url "$SRC/volodymyr-ukr"
	git config submodule.data/voices/tatiana.url "$SRC/tatiana-rus"
	git config submodule.external/libs/sonic.active false
	git config submodule.src/third-party/cldr.active false
	git config submodule.cmake/thirdparty/sanitizers.active false
	git submodule update
	mkdir -p $PKG/usr/doc/${pkgname}-$pkgver
	pandoc -s -t html5 -o $PKG/usr/doc/${pkgname}-$pkgver/LICENSE.html \
	 --metadata pagetitle="LICENSE" LICENSE.md
	pandoc -s -t html5 -o $PKG/usr/doc/${pkgname}-$pkgver/README.html \
	 --metadata pagetitle="README" README.md
	scons \
	spd_version=0.10.2 \
	prefix=/usr \
	libdir=/usr/lib${LIBDIRSUFFIX} \
	sysconfdir=/etc \
	servicedir='/usr/share/dbus-1/services/' \
	languages=brazilian-portuguese,english,russian,ukrainian
	export SCONSFLAGS="$MAKEFLAGS"
	scons install DESTDIR="$PKG" prefix="/usr" sysconfdir="/etc" \
	      CPPFLAGS="$CPPFLAGS" CCFLAGS="$CFLAGS" LINKFLAGS="$LDFLAGS"
	mkdir -p $PKG/usr/doc/${pkgname}-$pkgver
	mkdir -p $PKG/usr/lib${LIBDIRSUFFIX}/speech-dispatcher-modules
	rm -f $PKG/usr/lib${LIBDIRSUFFIX}/speech-dispatcher-modules/sd_rhvoice
	cp $PKG/usr/bin/sd_rhvoice $PKG/usr/lib${LIBDIRSUFFIX}/speech-dispatcher-modules/
	install -vDm0644 licenses/gpl-3.0.txt "$$PKG/usr/doc/${PKG}-$pkgver/LICENSE"
	install -vDm0644 licenses/by-nc-nd-4.0.txt "$$PKG/usr/doc/${PKG}-$pkgver/by-nc-nd-4.0"
	install -vDm0644 licenses/by-sa-4.0.txt "$PKG/usr/doc/${PKG}-$pkgver/by-sa-4.0"
}
