##
##  festival.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package versions
%define       V_festival      1.96
%define       V_speech_tools  1.2.96
%define       V_ogireslpc     2.2
%define       V_ogilexicon    2.2
%define       V_ogivoiceas    2.3
%define       V_ogivoicemwm5  2.3
%define       V_ogivoiceaec   2.3
%define       V_ogivoicejph   2.3
%define       V_ogivoicetll   2.3
%define       V_ogivoicerab   2.1

#   package information
Name:         festival
Summary:      Speech Synthesis System
URL:          http://www.cstr.ed.ac.uk/projects/festival/
Vendor:       University of Edinburgh
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Audio
License:      X11-style
Version:      %{V_festival}
Release:      20080323

#   package options
%option       with_ogi  no

#   list of sources
Source0:      http://festvox.org/packed/festival/%{V_festival}/festival-%{V_festival}-beta.tar.gz
Source1:      http://festvox.org/packed/festival/%{V_festival}/speech_tools-%{V_speech_tools}-beta.tar.gz
Source2:      http://festvox.org/packed/festival/%{V_festival}/festlex_CMU.tar.gz
Source3:      http://festvox.org/packed/festival/%{V_festival}/festlex_POSLEX.tar.gz
Source4:      http://festvox.org/packed/festival/%{V_festival}/festlex_OALD.tar.gz
Source5:      http://festvox.org/packed/festival/%{V_festival}/festvox_kallpc16k.tar.gz
Source6:      http://festvox.org/packed/festival/%{V_festival}/festvox_kedlpc16k.tar.gz
Source7:      http://festvox.org/packed/festival/%{V_festival}/festvox_kedlpc8k.tar.gz
Source8:      http://festvox.org/packed/festival/%{V_festival}/festvox_cmu_us_awb_arctic_hts.tar.gz
Source9:      http://festvox.org/packed/festival/%{V_festival}/festvox_cmu_us_bdl_arctic_hts.tar.gz
Source10:     http://festvox.org/packed/festival/%{V_festival}/festvox_cmu_us_jmk_arctic_hts.tar.gz
Source11:     http://festvox.org/packed/festival/%{V_festival}/festvox_cmu_us_slt_arctic_hts.tar.gz
Source12:     http://www.cslu.ogi.edu/tts/download/data/OGIresLPC-%{V_ogireslpc}.tar.gz
Source13:     http://www.cslu.ogi.edu/tts/download/data/OGIlexicon-%{V_ogilexicon}.tar.gz
Source14:     http://www.cslu.ogi.edu/tts/download/data/voice_as_di_%{V_ogivoiceas}.tar.gz
Source15:     http://www.cslu.ogi.edu/tts/download/data/voice_mwm5_di_%{V_ogivoicemwm5}.tar.gz
Source16:     http://www.cslu.ogi.edu/tts/download/data/voice_aec_di_%{V_ogivoiceaec}.tar.gz
Source17:     http://www.cslu.ogi.edu/tts/download/data/voice_jph_di_%{V_ogivoicejph}.tar.gz
Source18:     http://www.cslu.ogi.edu/tts/download/data/voice_tll_di_%{V_ogivoicetll}.tar.gz
Source19:     http://www.cslu.ogi.edu/tts/download/data/voice_ogirab_di_%{V_ogivoicerab}.tar.gz
Source20:     rc.festival
Source21:     festival-init.scm
Source22:     festival-vars.scm
Patch0:       festival.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, gcc, gcc::with_cxx = yes
PreReq:       OpenPKG, openpkg >= 20160101, opensp

%description
    Festival offers a general framework for building speech synthesis
    systems as well as including examples of various modules. As a whole
    it offers full text to speech through a number APIs. Festival is
    multi-lingual though English is the most advanced language. The
    system is written in C++ and uses the Edinburgh Speech Tools Library
    (EST) for low level architecture and has a Scheme (SIOD) based
    command interpreter for control.

%track
    prog festival = {
        version   = %{version}
        url       = http://festvox.org/packed/festival/
        regex     = (1\.\d+|2\.\d+)/
    }

%prep
    %setup -q -c
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %setup -q -T -D -a 3
    %setup -q -T -D -a 4
    %setup -q -T -D -a 5
    %setup -q -T -D -a 6
    %setup -q -T -D -a 7
    %setup -q -T -D -a 8
    %setup -q -T -D -a 9
    %setup -q -T -D -a 10
    %setup -q -T -D -a 11
%if "%{with_ogi}" == "yes"
    %setup -q -T -D -a 12
    %setup -q -T -D -a 13
    %setup -q -T -D -a 14
    %setup -q -T -D -a 15
    %setup -q -T -D -a 16
    %setup -q -T -D -a 17
    %setup -q -T -D -a 18
    %setup -q -T -D -a 19
%endif
    %patch -p0

%build
    #   expand variables in patched sources
    %{l_shtool} subst %{l_value -s -a} \
        festival/lib/init.scm \
        festival/lib/tts.scm \
        festival/lib/voices.scm

    #   optionally activate OGI extension
%if "%{with_ogi}" == "yes"
    ( echo "ALSO_INCLUDE += OGIcommon OGIeffect OGIinsert OGIdbase OGIresLPC"
    ) >>festival/config/config.in
    %{l_shtool} subst \
        -e 's;^\(OPTIONAL.*\);\1 OGIcommon OGIeffect OGIinsert OGIdbase OGIresLPC;' \
        festival/src/modules/Makefile
%endif

    #   support additional platforms
    cp  speech_tools/config/systems/ix86_FreeBSD.mak \
        speech_tools/config/systems/unknown_FreeBSD.mak
    cp  speech_tools/config/systems/ix86_SunOS5.mak \
        speech_tools/config/systems/unknown_SunOS5.mak
    cp  festival/config/systems/ix86_FreeBSD.mak \
        festival/config/systems/unknown_FreeBSD.mak
    cp  festival/config/systems/ix86_SunOS5.mak \
        festival/config/systems/unknown_SunOS5.mak

    #   build speech tools
    (   cd speech_tools
        CC="%{l_cc}" \
        CXX="%{l_cxx}" \
        CFLAGS="%{l_cflags -O}" \
        CXXFLAGS="%{l_cxxflags -O}" \
        CPPFLAGS="%{l_cppflags}" \
        LDFLAGS="%{l_ldflags}" \
        ./configure \
            --prefix=%{l_prefix}
        %{l_make} %{l_mflags}
    ) || exit $?

    #   build festival toolkit
    (   cd festival
        ( echo "FTLIBDIR=%{l_prefix}/lib/festival"
        ) >>config/config.in
        CC="%{l_cc}" \
        CXX="%{l_cxx}" \
        CFLAGS="%{l_cflags -O}" \
        CXXFLAGS="%{l_cxxflags -O}" \
        CPPFLAGS="%{l_cppflags}" \
        LDFLAGS="%{l_ldflags}" \
        ./configure \
            --prefix=%{l_prefix}
        %{l_make} %{l_mflags}
    ) || exit $?

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/festival \
        $RPM_BUILD_ROOT%{l_prefix}/lib/festival \
        $RPM_BUILD_ROOT%{l_prefix}/var/festival

    #   install program files
    %{l_shtool} install -c -m 755 \
        festival/lib/etc/*/audsp \
        $RPM_BUILD_ROOT%{l_prefix}/bin/festival_audsp
    %{l_shtool} install -c -m 755 \
        festival/src/main/festival \
        festival/src/main/festival_client \
        $RPM_BUILD_ROOT%{l_prefix}/bin/
    %{l_shtool} install -c -m 755 \
        -e 's;\(exec \).*\(/bin/festival --script\);\1%{l_prefix}\2;' \
        festival/examples/saytime \
        festival/examples/text2pos \
        festival/examples/text2wave \
        $RPM_BUILD_ROOT%{l_prefix}/bin/
    %{l_shtool} install -c -m 644 \
        festival/doc/festival.1 \
        festival/doc/festival_client.1 \
        festival/doc/text2wave.1 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1/

    #   install library files
    chmod -R u+w,a+r,og-w festival/lib
    find festival/lib -type d -print | xargs chmod 755
    mv festival/lib/voices/us/* festival/lib/voices/english/
    rmdir festival/lib/voices/us
    cp -rp festival/lib/* $RPM_BUILD_ROOT%{l_prefix}/lib/festival/
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/festival/etc

    #   install default site configuration
    %{l_shtool} install -c -m 644 \
        %{SOURCE festival-vars.scm} \
        %{SOURCE festival-init.scm} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/festival/

    #   install run-command script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.festival} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/festival/*' \
        '%attr(-,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/festival'

%files -f files

%clean

%post
    #   after upgrade, restart service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} festival status 2>/dev/null`
    [ ".$festival_active" = .yes ] && %{l_rc} festival restart
    exit 0

%preun
    #   before erase, stop service and remove log files
    [ $1 -eq 0 ] || exit 0
    %{l_rc} festival stop 2>/dev/null
    rm -f $RPM_INSTALL_PREFIX/var/festival/* >/dev/null 2>&1 || true
    exit 0

