# Build recipe for espeak.
#
# Copyright (c) 2018 Thiago Seus, <thiago.seus@yahoo.com.br>.
# Copyright (c) 2020 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=espeak
version=1.48.04
release=2

# Define a category for the output of the package name
pkgcategory=tools

tarname=${program}-${version}-source.zip

# Remote source(s)
fetch="https://downloads.sourceforge.net/project/espeak/espeak/espeak-${version%.*}/$tarname"

description="
Speech Synthesizer.

eSpeak is a compact, multi-language, text-to-speech synthesizer.
"

homepage=https://espeak.sourceforge.net
license=GPLv3+

# Source documentation
docs="ChangeLog.txt License.txt ReadMe docs/"
docsdir="${docdir}/${program}-${version}"

# The package has a custom source directory
srcdir=${program}-${version}-source

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir/src"

    # Use the PortAudio (sound interface library) version 19
    ln -sf portaudio19.h portaudio.h

    make -j${jobs} CXXFLAGS="$QICXXFLAGS -Wno-narrowing" LDFLAGS="$QILDFLAGS" \
     PREFIX=/usr LIBDIR=/usr/lib${libSuffix}

    make -j${jobs} PREFIX=/usr LIBDIR=/usr/lib${libSuffix} \
     DESTDIR="$destdir" install

    cd ..

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p -r $docs "${destdir}/$docsdir"

    # Rename docs/ directory for the package
    mv "${destdir}/$docsdirdocs" "${destdir}/$docsdirhtml"
}

