# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=flite
pkgver=2.0.0
pkgrel=0
pkgdesc="Small, fast speech synthesis engine (text-to-speech)"
url="http://www.speech.cs.cmu.edu/flite/"
arch="all"
license="MIT"
depends=
depends_dev=
makedepends="$depends_dev"
install=""
subpackages="$pkgname-dev"
source="http://www.festvox.org/flite/packed/flite-${pkgver%.*}/flite-$pkgver-release.tar.bz2"

_builddir="$srcdir"/flite-$pkgver-release
prepare() {
	local i
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
}

build() {
	cd "$_builddir"
	CFLAGS="$CFLAGS -fPIC" ./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--enable-shared \
		--localstatedir=/var \
		|| return 1
	# work around parallel build issue
	make -C include
	make -C src
	make -C lang
	make -C tools
	make -j1 || return 1
}

package() {
	cd "$_builddir"
	make install INSTALLBINDIR="$pkgdir"/usr/bin \
		INSTALLLIBDIR="$pkgdir"/usr/lib \
		INSTALLINCDIR="$pkgdir"/usr/include/flite \
		|| return 1
	# remove relative rpaths
	scanelf -R -r --fix "$pkgdir" || return 1
	mkdir -p "$pkgdir"/usr/lib/pkgconfig
	cat > "$pkgdir"/usr/lib/pkgconfig/flite.pc <<EOF
prefix=/usr
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include

Name: flite
Description: a text to speech library
Requires:
Version: 2.0.0
Libs: -L\${libdir} -lflite -lflite_cmu_grapheme_lang -lflite_cmu_grapheme_lex -lflite_cmu_indic_lang -lflite_cmu_indic_lex -lflite_cmulex -lflite_cmu_time_awb -lflite_cmu_us_awb -lflite_cmu_us_kal16 -lflite_cmu_us_kal -lflite_cmu_us_rms -lflite_cmu_us_slt -lflite_usenglish
Libs.private: -lm
Cflags: -I\${includedir}/flite/
EOF
}

md5sums="645db96ffc296cbb6d37f231cc1cc6b2  flite-2.0.0-release.tar.bz2"
sha256sums="678c3860fd539402b5d1699b921239072af6acb4e72dc4720494112807cae411  flite-2.0.0-release.tar.bz2"
sha512sums="e2b353721d0316fbd7948f90f9c9561d080eebd50e8dd0449a9c803ffbdb060a469385fadd63f535ade8d627cba37928d8e72ac61d5bcf98f73ca5ebb66549f8  flite-2.0.0-release.tar.bz2"
