#Maintainer: Didier Spaier <didier~at~slint~dot~fr>

pkgname=$(pwd|sed "s,.*/,,")
export srcver=0.11.0
pkgver=0.11.0
pkgrel=1slint
#source=("spd-list" "rhvoice.conf" "http://www.freebsoft.org/pub/projects/sound-icons/sound-icons-0.1.tar.gz")
source=("speech-dispatcher-${pkgver}.tar.?z" "spd-list" "rhvoice.conf" "http://www.freebsoft.org/pub/projects/sound-icons/sound-icons-0.1.tar.gz")
docs=("ANNOUNCE" "AUTHORS" "COPYING*" "ChangeLog" "NEWS" "TODO")
url=http://devel.freebsoft.org/speechd
options=("nosrcpack")

slackdesc=\
(
 #|-----handy-ruler------------------------------------------------------|
 "speech-dispatcher (text speech program)"
 "Speech Dispatcher project provides a high-level device"
 "independent layer for access to speech synthesis through a simple,"
 "stable and well documented interface."
 ""
 "HomePage:http://devel.freebsoft.org/speechd"
)
doinst() {
if [ -f /etc/speech-dispatcher/modules/espeak-ng-mbrola-generic.conf ]; then
	rm  -f /etc/speech-dispatcher/modules/espeak-ng-mbrola-generic.conf
fi
}

build() {
cd $SRC/$pkgname-$pkgver || return 1
echo "patch -p1 --verbose < $startdir/add_flite_generic.conf.diff"
patch -p1 --verbose < $startdir/add_flite_generic.conf.diff
cd config
sed 's/# AudioOutputMethod "pulse"/# In Slint the default is libao\nAudioOutputMethod "libao"/' speechd.conf > bof
mv bof speechd.conf
cd ..
#echo "patch -p1 --verbose < $startdir/doc.diff"
#patch -p1 --verbose < $startdir/doc.diff
./configure --prefix=/usr \
--libdir=/usr/lib${LIBDIRSUFFIX} \
--localstatedir=/var \
--sysconfdir=/etc \
--disable-static \
--with-espeak=no \
--with-espeak-ng=yes \
--with-flite=yes \
--with-ibmtts=yes \
--with-voxin=yes \
--with-baratinoo=no \
--with-kali=no \
--with-ivona=no \
--with-pico=yes \
--with-pulse=yes \
--with-libao=yes \
--with-alsa=yes \
--with-oss=no \
--with-nas=no \
--with-default-audio-method=libao
make install DESTDIR=$PKG || return 1
#(cd $PKG/etc/speech-dispatcher/modules
#sed "s/EspeakMbrola 0/EspeakMbrola 1/" espeak-ng.conf > bof
#mv bof espeak-ng.conf
#)
rm -f $PKG/etc/speech-dispatcher/espeak-ng.conf*
noconf="
baratinoo.conf
cicero.conf
dtk-generic.conf
epos-generic.conf
espeak-generic.conf
espeak-mbrola-generic.conf
espeak-ng-mbrola-generic.conf
espeak.conf
festival.conf
ivona.conf
kali.conf
llia_phon-generic.conf
mary-generic-disabled.conf
swift-generic.conf"
for i in $noconf; do
  rm -f $PKG/etc/speech-dispatcher/modules/$i
done
for i in sd_cicero sd_festival; do
	rm -f $PKG/usr/lib64/speech-dispatcher-modules/$i
done
mkdir -p $PKG/usr/doc/$pkgname-$pkgver
  for i in README.style.md README.md README.overview.md; do
echo "processing $i"
	BASE_PATH=${MD_PATH%.md}
	HTML_PATH=$startdir/pkg/usr/doc/$pkgname-$pkgver/${i%.md}.html
	pandoc -s -f gfm -t html5 -o $HTML_PATH $i
	rm $i
  done
( cd $SRC/$pkgname-$pkgver/doc
for i in ssip.texi spd-say.texi speech-dispatcher.texi speech-dispatcher-cs.texi; do
echo "processing $i"
	texi2any --html --no-headers --no-split $i
done
echo "files to be copied to  $PKG/usr/doc/$pkgname-$pkgver"
ls *.html figures $PKG/usr/doc/$pkgname-$pkgver
cp -r *.html figures $PKG/usr/doc/$pkgname-$pkgver
)
mkdir -p $PKG/usr/bin
cp $SRC/spd-list $PKG/usr/bin
chmod 755 -R $PKG/usr/bin
mkdir -p $PKG/etc/speech-dispatcher/modules
cp -a $SRC/rhvoice.conf $PKG/etc/speech-dispatcher/modules
cp -a $SRC/$pkgname-$pkgver/config/modules/flite-generic.conf $PKG/etc/speech-dispatcher/modules
mkdir -p $PKG/usr/share/sounds/sound-icons
mkdir -p $PKG/usr/doc/sound-icons-0.1
( cd $SRC/sound-icons-0.1
cp -a README COPYING $PKG/usr/doc/sound-icons-0.1
rm README COPYING
cp -a * $PKG/usr/share/sounds/sound-icons
)
}
