# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           conflicts_build 1.0
PortGroup           github 1.0
PortGroup           legacysupport 1.1

github.setup        dectalk dectalk 2023-10-30
github.tarball_from archive
revision            3
categories          audio
license             Restrictive
maintainers         {makr @mohd-akram} openmaintainer

description         90s/00s DECtalk text-to-speech application

long_description    {*}${description}

checksums           rmd160  9909e84cd8f736584013e3307a102d5d9d3b2d3d \
                    sha256  511c845e453917eea3a353cdbe8e0401360d8992dcfadfe2e9b4b83fde168f7e \
                    size    40565428

# Next release will have an option to disable it.
# https://github.com/dectalk/dectalk/issues/62
conflicts_build     pulseaudio

depends_build       path:bin/pkg-config:pkgconfig

depends_lib         path:lib/pkgconfig/gtk+-2.0.pc:gtk2

# xdg-open to open help
depends_run         port:xdg-utils

worksrcdir          ${distname}/src

post-extract {
    # DOS to UNIX line endings so we can patch properly.
    fs-traverse file ${worksrcpath} {
        switch [file extension ${file}] {
            .c -
            .h -
            .in {
                reinplace "s|\r||g" ${file}
            }
        }
    }
}

patchfiles          patch-configure.diff \
                    patch-fix-gspeak.diff \
                    patch-fix-windic.diff \
                    patch-paths.diff

# Backports from upstream, drop with next update.
# https://github.com/dectalk/dectalk/pull/59
# https://github.com/dectalk/dectalk/issues/60
patchfiles-append   e7e967e3a8cbba7cf913a955e4dbcf55bf092aed.patch \
                    de1acb589a7855b97cab0ebcce4d686cdf617552.patch \
                    e5de12d458603a5dc2dd4febc539041025c70ebe.patch \
                    678b1f64f3e442827bd7d561479d43bf63eaee81.patch \
                    dd2f40b7f90f0eb942bc3cf7fcbc68a07c1ec6ce.patch

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15
# Standard ways to pass flags to the build fail.
if {${os.platform} eq "darwin" && ${os.major} <= 15} {
    patchfiles-append   patch-link-legacysupport.diff

    # https://github.com/dectalk/dectalk/issues/61
    # https://github.com/dectalk/dectalk/issues/62
    # Notice, this does not disable ppc, but fixes it.
    patchfiles-append   patch-drop-ppc-special-case.diff
}

# error: redefinition of typedef ‘U16’
# error: redefinition of typedef ‘SHORT’
compiler.blacklist-append \
                    *gcc-4.0 *gcc-4.2

# The build picks a random cc otherwise at linkage.
# Should come after blacklist.
build.env-append    CC=${configure.cc}

post-destroot {
    delete ${destroot}/usr/bin
    delete ${destroot}${prefix}/src/DECtalk/gspeak

    move ${destroot}${prefix}/say ${destroot}${prefix}/bin/dtsay
    move \
        {*}[glob ${destroot}${prefix}/tools/*] \
        ${destroot}${prefix}/aclock \
        ${destroot}${prefix}/dtmemory \
        ${destroot}${prefix}/gspeak \
        ${destroot}${prefix}/windic \
        ${destroot}${prefix}/bin/

    move {*}[glob ${destroot}${prefix}/doc/DECtalk/man/man1/*] \
        ${destroot}${prefix}/share/man/man1/
    move {*}[glob ${destroot}${prefix}/doc/DECtalk/man/man3/*] \
        ${destroot}${prefix}/share/man/man3/

    move ${destroot}${prefix}/share/man/man1/say.1 \
        ${destroot}${prefix}/share/man/man1/dtsay.1
    reinplace "s/say/dtsay/g" ${destroot}${prefix}/share/man/man1/dtsay.1

    xinstall -d ${destroot}${prefix}/share/doc/
    move ${destroot}${prefix}/doc/DECtalk ${destroot}${prefix}/share/doc/${name}
    move ${destroot}${prefix}/DECtalk.conf ${destroot}${prefix}/README \
        ${destroot}${prefix}/share/doc/${name}
    move ${destroot}${prefix}/src/DECtalk/dtsamples \
        ${destroot}${prefix}/share/doc/${name}/samples

    xinstall -d ${destroot}${prefix}/share/${name}
    move ${destroot}${prefix}/bitmaps ${destroot}${prefix}/dic \
        ${destroot}${prefix}/share/${name}

    # These aren't built
    delete \
        ${destroot}${prefix}/share/man/man1/emacspeak.1 \
        ${destroot}${prefix}/share/man/man1/speak.1 \
        ${destroot}${prefix}/share/man/man1/windict.1
}

post-activate {
    if {![file exists ${prefix}/etc/DECtalk.conf]} {
        copy ${prefix}/share/doc/${name}/DECtalk.conf ${prefix}/etc/
    }
}
