# -*- 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           github 1.0

github.setup        julius-speech julius 4.6 v
revision            0
checksums           rmd160  0f54727b58b85e31b7ae0d9f7068ab3f7ef19f6a \
                    sha256  74447d7adb3bd119adae7915ba9422b7da553556f979ac4ee53a262d94d47b47 \
                    size    9472943 \

categories          audio japanese
maintainers         nomaintainer
license             BSD

description         Large Vocabulary Continuous Speech Recognition (LVCSR) Engine

long_description    Julius is an open-source high-performance large vocabulary \
                    continuous speech recognition (LVCSR) decoder software for \
                    speech-related researchers and developers. \
                    Based on word N-gram and triphone context-dependent HMM, \
                    it can perform almost real-time decoding on most current \
                    PCs with small amount of memory.

github.tarball_from archive

depends_lib         port:libiconv \
                    port:zlib

# Note: '--enable-words-int' should be declared ahead of '--with-mictype'.
variant words_int description {Use integer for word ID to extend vocabulary limit} {
    configure.pre_args-append  --enable-words-int
}

if {${os.platform} eq "darwin" && ${os.major} >= 10} {
    depends_lib-append      port:portaudio
    configure.args-append   --with-mictype=portaudio
}

destroot.destdir        prefix=${destroot}${prefix}

set docdir ${prefix}/share/doc/${name}

post-destroot {
    xinstall -d ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath} \
        00readme-ja.txt \
        00readme.txt \
        LICENSE \
        Release-ja.txt \
        Release.txt \
        Sample.jconf \
        ${destroot}${docdir}
}

default_variants    +kit

set kit_name        dictation-kit
set kit_version     4.3.1
set dictation_kit   ${kit_name}-v${kit_version}-osx
set kit_distfile    ${dictation_kit}-0130.tgz

variant kit description {Add dictation kit} {
    checksums-prepend   ${distfiles}
    distfiles-append    ${kit_distfile}:kit
    master_sites-append sourceforge_jp:julius/60416/:kit
    checksums-append    ${kit_distfile} \
                        rmd160  2db607e470a8f2516a9cd0b9a1b8925523b62e9d \
                        sha256  2ff46d1bd4d8e7690bd568d2973978081460e661085f6b4c2a0a630234a911c1 \
                        size    260745034

    global confs scripts libdir libexecdir
    set confs           [list am-dnn.jconf am-gmm.jconf dnnclient.conf main.jconf]
    set scripts         [list run-dnn.sh run-gmm.sh run.sh]
    set libdir          ${prefix}/lib/${name}
    set libexecdir      ${prefix}/libexec/${name}

    post-patch {
        system -W ${workpath}/${dictation_kit} "patch < ${filespath}/patch-run-dnn.sh.diff"
        reinplace -W ${workpath}/${dictation_kit} -locale C "s| model/| ${libdir}/model/|g" {*}${confs} run-dnn.sh
        reinplace -W ${workpath}/${dictation_kit} -locale C -E "s|\\./bin/|${prefix}/bin/|g;s| (\[^\[:space:\]\]+\\.j?conf)| ${libdir}/\\1|g" {*}${scripts}
    }

    post-destroot {
        # copy model files.
        xinstall -d ${destroot}${libdir}
        copy ${workpath}/${dictation_kit}/model ${destroot}${libdir}
        # copy configuration files.
        xinstall -m 0644 -W ${workpath}/${dictation_kit} {*}${confs} ${destroot}${libdir}
        # copy executable files.
        xinstall -d ${destroot}${libexecdir}
        xinstall -m 0755 -W ${workpath}/${dictation_kit} {*}${scripts} ${destroot}${libexecdir}
        xinstall -m 0744 -W ${workpath}/${dictation_kit}/bin \
            dnnclient-gpu.py \
            dnnclient.py \
            ${destroot}${prefix}/bin
        copy ${workpath}/${dictation_kit}/bin/scoring ${destroot}${libexecdir}
        # copy additional documents of the dictation kit.
        set kit_docdir ${prefix}/share/doc/${name}/${kit_name}
        xinstall -d ${destroot}${kit_docdir}
        xinstall -m 0644 -W ${workpath}/${dictation_kit} \
            00readme.txt \
            HOWTO-dnn.txt \
            HOWTO.txt \
            LICENSE.txt \
            TROUBLE.txt \
            ${destroot}${kit_docdir}
        # copy manuals.
        copy ${workpath}/${dictation_kit}/doc/manuals    ${destroot}${docdir}
        copy ${workpath}/${dictation_kit}/doc/manuals-ja ${destroot}${docdir}
    }
}
