# -*- 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
# $Id: Portfile 116675 2014-02-02 15:16:51Z hum@macports.org $

PortSystem          1.0

name                julius
version             4.3.1
revision            1
categories          audio japanese
platforms           darwin
maintainers         hum openmaintainer
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.

homepage            http://julius.sourceforge.jp/
master_sites        sourceforge_jp:julius/60273/
checksums           ${distname}${extract.suffix} \
                    rmd160  6c43a6f7ecf650b80c98c7f51f1869a874dc4222 \
                    sha256  4bf77c7b91f4bb0686c375c70bd4f2077e7de7db44f60716af9f3660f65a6253

patchfiles          patch-configure.diff \
                    patch-Makefile.in.diff

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.target-append  install.man
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 \
        ChangeLog \
        LICENSE.txt \
        Release-ja.txt \
        Release.txt \
        Sample.jconf \
        ${destroot}${docdir}
}

default_variants    +kit

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

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

    post-patch {
        system -W ${workpath}/${dictation_kit} "patch < ${filespath}/patch-run-dnn.sh.diff"
    }

    post-destroot {
        # copy model files.
        set libdir ${prefix}/lib/${name}
        xinstall -d ${destroot}${libdir}
        copy ${workpath}/${dictation_kit}/model ${destroot}${libdir}
        # copy configuration files and set paths.
        foreach f {am-dnn.jconf am-gmm.jconf dnnclient.conf main.jconf} {
            xinstall -m 644 ${workpath}/${dictation_kit}/${f} ${destroot}${libdir}
            reinplace -locale C "s| model/| ${libdir}/model/|g" ${destroot}${libdir}/${f}
        }
        # copy executable files and set paths.
        set libexecdir ${prefix}/libexec/${name}
        xinstall -d ${destroot}${libexecdir}
        foreach f {run-dnn.sh run-gmm.sh run.sh} {
            xinstall -m 755 ${workpath}/${dictation_kit}/${f} ${destroot}${libexecdir}
            reinplace -locale C "s|\\./bin/|${prefix}/bin/|g" ${destroot}${libexecdir}/${f}
            reinplace -locale C "s| model/| ${libdir}/model/|g" ${destroot}${libexecdir}/${f}
            reinplace -locale C -E "s| (\[^\[:space:\]\]+\\.j?conf)| ${libdir}/\\1|g" \
                ${destroot}${libexecdir}/${f}
        }
        xinstall -m 744 -W ${workpath}/${dictation_kit}/bin \
            dnnclient-gpu.py \
            dnnclient.py \
            ${destroot}${prefix}/bin
        copy ${workpath}/${dictation_kit}/bin/scoring ${destroot}${libexecdir}
        # copy additioanl documents of the dictation kit.
        set kit_docdir ${prefix}/share/doc/${name}/${kit_name}
        xinstall -d ${destroot}${kit_docdir}
        xinstall -m 644 -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}
    }
}

livecheck.type      regex
livecheck.url       http://sourceforge.jp/projects/${name}/releases/rss
livecheck.regex     <title>${name}.* - (\[0-9.a-z\-\]+)</title>
