# festival, http://www.cstr.ed.ac.uk/projects/festival/

name=festival
version=1.95
release=1
source=(http://www.cstr.ed.ac.uk/downloads/$name/$version/$name-$version-beta.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festlex_CMU.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festlex_OALD.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festlex_POSLEX.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festvox_don.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festvox_ellpc11k.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festvox_kallpc16k.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festvox_kedlpc16k.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festvox_rablpc16k.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festvox_us1.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festvox_us2.tar.gz \
http://www.cstr.ed.ac.uk/downloads/$name/$version/festvox_us3.tar.gz \
http://www.cstr.ed.ac.uk/downloads/festival/1.95/speech_tools-1.2.95-beta.tar.gz)

build() {
	# create directory hierarchies
	mkdir -p $PKG/usr/bin \
		$PKG/usr/man/man1 \
		$PKG/usr/include/{festival,EST} \
		$PKG/usr/share/festival \
		$PKG/usr/share/speech_tools \
		$PKG/usr/lib
	
	# configure & compile speech_tools
	cd speech_tools
	./configure --prefix=/usr
	make

	# install speech_tools
	mkdir -p $PKG/usr/share/speech_tools/{bin,siod,stats/wagon}
	mkdir -p $PKG/usr/share/speech_tools/grammar/{scfg,wfst}
	cp -a include/* $PKG/usr/include/EST
	cp -a config $PKG/usr/share/speech_tools
	install siod/siod.mak $PKG/usr/share/speech_tools/siod
	install lib/siod/*.scm $PKG/usr/share/speech_tools/siod
	install stats/ols.mak $PKG/usr/share/speech_tools/stats
	install stats/wagon/wagon.mak $PKG/usr/share/speech_tools/stats/wagon
	install grammar/scfg/scfg.mak $PKG/usr/share/speech_tools/grammar/scfg
	install grammar/wfst/wfst.mak $PKG/usr/share/speech_tools/grammar/wfst
	install -m 755 lib/lib* $PKG/usr/lib
	install `find bin -type f -perm +1` $PKG/usr/share/speech_tools/bin

	for file in `find $PKG/usr/include/EST -type f`; do
		sed -i -e 's/\"\(.*h\)\"/\<EST\/\1\>/g' $file
	done
	sed -i -e 's/\<EST\//&rxp\//g' $PKG/usr/include/EST/rxp/rxp.h 
	(cd $PKG/usr/include; \
	 for file in EST/rxp/*; do \
		ln -s $file . ; \
	 done)
	(cd $PKG/usr/share/speech_tools; ln -s ../../include/EST include)

	# configure & compile festival
	cd ../$name
	./configure --prefix=/usr
	make

	# install festival
	install -m 755 bin/festival_server* bin/text2wave $PKG/usr/bin
	install -m 755 src/main/{festival,festival_client} $PKG/usr/bin
	install -m 755 src/lib/libFestival.a $PKG/usr/lib
	install -m 644 src/include/*.h $PKG/usr/include/festival
	install -m 644 doc/*.1 $PKG/usr/man/man1
	cp -r lib config examples $PKG/usr/share/festival
	mv -f $PKG/usr/share/festival/lib/etc/unknown_Linux/audsp $PKG/usr/bin
	(cd $PKG/usr/share/festival; ln -s ../../bin .)
	
	find $PKG/usr/share/festival -name Makefile -exec rm \{\} \;
	find $PKG/usr/include -name Makefile -exec rm \{\} \;
	rm -rf $PKG/usr/share/festival/lib/etc
	rm -rf $PKG/usr/include/EST/win32

	sed -i -e 's,/projects/festival/lib,/usr/share/festival,g' $PKG/usr/share/festival/lib/lexicons.scm
	
	for file in $PKG/usr/bin/{festival_server,festival_server_control,text2wave}; do
		sed -i -e "s|$SRC|/usr/share|g" $file
	done

	chown root:root -R $PKG
}
