# -*- 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        chokkan crfsuite 961809adc379148892022276fc9367dfcb2b680f
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             0.12.2
categories          math textproc
maintainers         nomaintainer

description         A fast implementation of Conditional Random Fields (CRFs)
long_description    CRFsuite is an implementation of Conditional Random Fields (CRFs) \
                    for labeling sequential data.

homepage            http://www.chokkan.org/software/crfsuite/
license             BSD

checksums           rmd160  ba5e127e3d8e5d1bb2a344e7e96259bb328f9bb7 \
                    sha256  8931f215e6f9b230cc2dc440fcd890c37afa3b1df3e8da512c7e74cafba8f0c5 \
                    size    244953

depends_build       port:libtool  \
                    port:autoconf \
                    port:automake
depends_lib         port:liblbfgs

patchfiles          patch-autogen.sh.diff \
                    patch-configure.in.diff \
                    patch-bench.diff

pre-configure {
    system -W ${worksrcpath} "./autogen.sh"
}

configure.args      --with-liblbfgs=${prefix}

# https://github.com/chokkan/crfsuite/issues/126
if {${configure.build_arch} ni [list i386 x86_64]} {
    configure.args-append \
                    --disable-sse2
}

post-destroot {
    # install additional documents.
    set dest_doc ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${dest_doc}
    xinstall -m 644 -W ${worksrcpath} \
        AUTHORS COPYING ChangeLog README \
        ${dest_doc}
    # install example scripts.
    xinstall -d ${destroot}${prefix}/share/examples
    set ex                 ${prefix}/share/examples/${name}
    copy ${worksrcpath}/example ${destroot}/${ex}
    # install benchmark scripts.
    set bench ${ex}/bench
    copy ${worksrcpath}/bench ${destroot}/${bench}
    foreach py {bench_crfpp.py bench_crfsgd.py bench_crfsuite.py bench_wapiti.py collect.py} {
        reinplace "s|@PREFIX@|${prefix}|g" ${destroot}/${bench}/${py}
        reinplace "s|@BENCH@|${bench}|g"   ${destroot}/${bench}/${py}
    }
    reinplace "s|@TEMPLATE_CRFPP@|${prefix}/share/examples/crfpp/chunking/template|g" \
        ${destroot}/${bench}/bench_crfpp.py
    reinplace "s|@TEMPLATE_CRFPP@|${prefix}/share/examples/sgd/crf/template|g" \
        ${destroot}/${bench}/bench_crfsgd.py
    reinplace "s|@TEMPLATE_WAPITI@|${prefix}/share/examples/wapiti/chpattern.txt|g" \
        ${destroot}/${bench}/bench_wapiti.py
}

# Note:
# To run benchmark scripts in ${prefix}/share/examples/${name}/bench,
# please install the following ports: wapiti, sgd, crfpp, mallet.
