SUMMARY="Edinburgh speech tools library"
SUMMARY_tools="Edinburgh Speech Tools"

DESCRIPTION="The Edinburgh speech tools library is a collection of C++ classes \
that aide in developing machine-synthesized voices. Developed by the University \
of Edinburgh, it is used in Festival, a text-to-speech engine developed by \
the University of Edinburgh as well.
"
HOMEPAGE="http://www.cstr.ed.ac.uk/projects/speech_tools/"
SOURCE_URI="http://www.festvox.org/packed/festival/${portVersion}/speech_tools-${portVersion}-release.tar.gz"
CHECKSUM_SHA256="fbc2482c443919aa79d2e599d6a5faee4e793df55a79ef377f1dc7e8ba237010"
SOURCE_DIR="speech_tools"
REVISION="2"

# Although individually many files have different licenses, as a whole this
# license covers all the files.
LICENSE="
	Edinburgh Speech Tools
	"
COPYRIGHT="
	1986 University of Toronto
	1987, 1993 The Regents of the University of California
	1992, 1995 Markus Mummert
	1992 Rich Salz
	1992 Simmule Turner
	1994-2014 University of Edinburgh, UK
	1997-1998 Richard Tobin
	1999-2003 Language Technologies Institute, Carnegie Mellon University
	"

ARCHITECTURES="x86 x86_64"
if [ $effectiveTargetArchitecture != x86_gcc2 ]; then
    # x86_gcc2 is fine as primary target architecture as long as we're building
    # for a different secondary architecture.
    ARCHITECTURES="$ARCHITECTURES x86_gcc2"
else
    ARCHITECTURES="$ARCHITECTURES !x86_gcc2"
fi
SECONDARY_ARCHITECTURES="x86 !x86_gcc2"

PROVIDES="
	speech_tools$secondaryArchSuffix = $portVersion
	lib:libestbase$secondaryArchSuffix = $portVersion compat >= 2
	lib:libestools$secondaryArchSuffix = $portVersion compat >= 2
	lib:libeststring$secondaryArchSuffix = $portVersion compat >= 2
	"
PROVIDES_devel="
	speech_tools${secondaryArchSuffix}_devel = $portVersion
	devel:libestbase$secondaryArchSuffix = $portVersion compat >= 2
	devel:libestools$secondaryArchSuffix = $portVersion compat >= 2
	devel:libeststring$secondaryArchSuffix = $portVersion compat >= 2
	"
PROGS=" bcat ch_lab ch_track ch_utt ch_wave design_filter dp \
	na_play na_record ngram_build ngram_test ols \
	ols_test pda pitchmark scfg_make \
	scfg_parse scfg_test scfg_train sig2fv sigfilter spectgen \
	tilt_analysis tilt_synthesis viterbi wagon wagon_test \
	wfst_build wfst_run wfst_train xml_parser
	"
SCRIPTS="
	make_wagon_desc
	raw_to_xgraph
	resynth
	"
PROVIDES_tools="
	speech_tools${secondaryArchSuffix}_tools = $portVersion
	cmd:simple_pitchmark = $portVersion
	"
for p in $PROGS $SCRIPTS; do
	PROVIDES_tools="
		$PROVIDES_tools
		cmd:$p = $portVersion
		"
done
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgcc_s$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	"
REQUIRES_devel="
	haiku${secondaryArchSuffix}_devel
	speech_tools$secondaryArchSuffix == $portVersion base
	devel:libncurses$secondaryArchSuffix
	"
REQUIRES_tools="
	haiku$secondaryArchSuffix
	speech_tools$secondaryArchSuffix == $portVersion base
	cmd:perl
	lib:libgcc_s$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	"
BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libncurses$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:mkdepend
	"

PATCHES="speech_tools-${portVersion}.patchset"

BUILD()
{
	runConfigure ./configure
	# There are some problems with concurrency.
	make
}

INSTALL()
{
	cmdBinDir=$prefix/bin
	mkdir -p $cmdBinDir
	(cd main && cp $PROGS $cmdBinDir)
	for s in $SCRIPTS; do
		sed 's,__PERL__,/bin/perl,g' <scripts/${s}.* >$cmdBinDir/$s
		chmod +x $cmdBinDir/$s
	done
	sed 's,__PERL__,/bin/perl,g'             \
		<scripts/pm.prl                  \
		>$cmdBinDir/simple-pitchmark
	chmod +x $cmdBinDir/simple-pitchmark

	mkdir -p $libDir
	# Install everything to lib/ and let prepareInstalledDevelLibs handle
	# devel libs, etc.
	cp lib/*.a lib/*.so lib/*.so.* $libDir

	# Installs possibly internal headers as well, as debian installs them
	includeDir=$includeDir/speech_tools
	mkdir -p              $includeDir/
	cp -a include/*       $includeDir/
	rm -rf	$includeDir/Makefile \
		$includeDir/*/Makefile \
		$includeDir/win32
	cp -a base_class/*.h  $includeDir/
	mkdir -p              $includeDir/base_class/
	cp -a base_class/*.cc $includeDir/base_class/

	# Install configurations as festival need them. Yes it's ugly but it's
	# the only way to do it. (Debian does this too.)
	privDir=$developLibDir/$portName
	mkdir -p			$privDir/lib/siod
	cp -a make.include config	$privDir
	cp -a lib/siod/*.scm		$privDir/lib/siod

	prepareInstalledDevelLibs \
		libestbase \
		libestools \
		libeststring

	# Evil linking for Festival
	for i in $developLibDir/libest*.a \
	         $developLibDir/libest*.so; do
		ln -s "$i" "$privDir/lib/`basename $i`"
	done
	ln -s "$includeDir" "$privDir/include"

	packageEntries devel \
		$developDir
	packageEntries tools \
		$cmdBinDir
}
