# Packager = Tuxcore <dev@tuxcore.org> 
pkgbase=speech-dispatcher
pkgname=(speech-dispatcher libspeechd)
pkgver=0.11.5
pkgrel=2
arch=('x86_64')
pkgdesc="High-level device independent layer for speech synthesis interface"
url='http://www.freebsoft.org/speechd'
license=('GPL2' 'FDL')
makedepends=('glib2' 'intltool' 'espeak-ng' 'libtool' 'python-pyxdg' 'dotconf' 'libpulse' 'libao')
source=("https://github.com/brailcom/speechd/releases/download/${pkgver}/speech-dispatcher-${pkgver}.tar.gz")
sha512sums=('d6d880bce0ae5bc2a5d519ef7740c689ae8b4b0bb658379762810e4beae3e465a429fbe19f7c490e89db0ea6a36aedd4b2287ac9251b90059b5c2cb3c0dd8a28')

build() {
  cd ${pkgname}-${pkgver}

  ./configure --prefix=/usr --sysconfdir=/etc \
    --disable-static \
    --libexecdir=/usr/lib/speech-dispatcher/ \
    --with-ibmtts=no --with-kali=no --with-baratinoo=no \
    --with-voxin=no --without-flite
  make
}

package_speech-dispatcher() {
  depends=("libspeechd=$pkgver-$pkgrel" 'python-pyxdg' 'dotconf' 'libpulse' 'libao')
  optdepends=('festival: Speech output using Festival'
              'espeak-ng: Speech output using ESpeak-ng'
              'pulseaudio: PulseAudio support')
  backup=('etc/speech-dispatcher/clients/emacs.conf'
          'etc/speech-dispatcher/modules/dtk-generic.conf'
          'etc/speech-dispatcher/modules/epos-generic.conf'
          'etc/speech-dispatcher/modules/espeak-ng.conf'
          'etc/speech-dispatcher/modules/espeak-ng-mbrola.conf'
          'etc/speech-dispatcher/modules/espeak-ng-mbrola-generic.conf'
          'etc/speech-dispatcher/modules/festival.conf'
          'etc/speech-dispatcher/modules/llia_phon-generic.conf'
          'etc/speech-dispatcher/modules/mary-generic.conf'
          'etc/speech-dispatcher/modules/swift-generic.conf'
          'etc/speech-dispatcher/speechd.conf')

  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install

  rm "${pkgdir}/etc/speech-dispatcher/modules/cicero.conf"
  rm "${pkgdir}/etc/speech-dispatcher/modules/espeak.conf"
  rm "${pkgdir}/etc/speech-dispatcher/modules/espeak-mbrola-generic.conf"
  rm "${pkgdir}/etc/speech-dispatcher/modules/flite.conf"
  rm "${pkgdir}/usr/lib/speech-dispatcher/speech-dispatcher-modules/sd_cicero"

  sed -i 's|includedir=.*|includedir=${prefix}/include/speech-dispatcher|g' "${pkgdir}/usr/lib/pkgconfig/speech-dispatcher.pc"

  mkdir -p "${srcdir}"/libspeechd/usr/lib
  mv "${pkgdir}"/usr/include "${srcdir}"/libspeechd/usr
  mv "${pkgdir}"/usr/lib/libspeechd*so* "${srcdir}"/libspeechd/usr/lib
  mv "${pkgdir}/usr/lib/pkgconfig" "${srcdir}/libspeechd/usr/lib"
}

package_libspeechd() {
  depends=('glib2' 'libtool')
  mkdir -p "${pkgdir}"/usr/lib

  mv "${srcdir}"/libspeechd/usr/include "${pkgdir}"/usr
  mv "${srcdir}"/libspeechd/usr/lib/* "${pkgdir}"/usr/lib
}
