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

pkgname=RHVoice
pkgver=gitb38f589
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')

pkgver() {
	cd "${pkgname%-git}"
	printf "%s" "$(git describe --long | sed 's/\([^-]*-\)g/r\1/;s/-/./g')"
}
options=("nosrcpack" "noautodotnew")
doinst() {
	rm -f /etc/RHVoice/RHVoice-ru.conf
	rm -f /etc/RHVoice/RHVoice-ua.conf
	case $LANG in
		en*) cp etc/RHVoice.conf-en etc/RHVoice.conf.new ;;
		ru*) cp etc/RHVoice.conf-ru etc/RHVoice.conf.new ;;
		uk*) cp etc/RHVoice.conf-uk etc/RHVoice.conf.new ;;
		*) cp etc/RHVoice.conf-en etc/RHVoice.conf.new
	esac
	if [ ! -r etc/RHVoice.conf ]; then
		mv etc/RHVoice.conf.new etc/RHVoice.conf
	elif [ "$(md5sum etc/RHVoice.conf.new)" = "$(md5sum etc/RHVoice.conf)" ]; then
		rm etc/RHVoice.conf.new
	fi
}

build() {
    git clone https://github.com/RHVoice/aleksandr-hq-rus.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/marianna-ukr.git
    git clone https://github.com/RHVoice/mikhail-rus.git
    git clone https://github.com/RHVoice/tatiana-rus.git
    git clone https://github.com/RHVoice/victoria-rus.git
    git clone https://github.com/RHVoice/volodymyr-ukr.git
    git clone https://github.com/RHVoice/yuriy-rus.git
    git clone https://github.com/RHVoice/RHVoice.git
    cd RHVoice
	git submodule init
    git config submodule.cmake/thirdparty/sanitizers.active false
    git config submodule.data/voices/aleksandr-hq.url "$SRC/aleksandr-hq-rus"
    git config submodule.data/voices/evgeniy-eng.url "$SRC/evgeniy-eng"
    git config submodule.data/voices/evgeniy-rus.url "$SRC/evgeniy-rus"
    git config submodule.data/voices/marianna.url "$SRC/marianna-ukr"
    git config submodule.data/voices/mikhail.url "$SRC/mikhail-rus"
    git config submodule.data/voices/tatiana.url "$SRC/tatiana-rus"
    git config submodule.data/voices/victoria.url "$SRC/victoria-rus"
    git config submodule.data/voices/volodymyr.url "$SRC/volodymyr-ukr"
    git config submodule.data/voices/yuriy.url "$SRC/yuriy-rus"
    git config submodule.external/libs/sonic.active false
    git config submodule.src/third-party/cldr.active false
    git submodule update
	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"
	DOCDIR=$PKG/usr/doc/${pkgname}-$pkgver
	mkdir -p /etc/RHVoice
	mkdir -p $DOCDIR
	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
	 cp -a doc/* $DOCDIR/
	 rm -f $PKG/etc/RHVoice/RHVoice.conf
	 mv $DOCDIR/en/RHVoice.conf $PKG/etc/RHVoice/RHVoice.conf-en
	 mv $DOCDIR/ru/RHVoice.conf $PKG/etc/RHVoice/RHVoice.conf-ru
	 mv $DOCDIR/ua/RHVoice.conf $PKG/etc/RHVoice/RHVoice.conf-uk
}
