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

name                extractopinion
version             1.2
revision            7
categories          textproc japanese
maintainers         nomaintainer

description         an opinion extraction tool for Japanese texts
long_description    ${name} is ${description}.

homepage            http://alaginrc.nict.go.jp/opinion/index.html
license             {BSD LGPL GPL}

master_sites        http://alaginrc.nict.go.jp/opinion/src/
checksums           rmd160  abbfb97605e4316349f279332d3785af3c39d9a0 \
                    sha256  09c0a2ca339bc5b50afccecbf0b130aec9d15445155ee36fa6605a02952db3cb \
                    size    9323586

patchfiles          patch-extract.sh.diff \
                    patch-makemdl.sh.diff \
                    patch-crftrain.sh.diff \
                    patch-lib_tsv.pm.diff \
                    patch-perl.diff

perl5.branches      5.34

depends_lib         port:crfpp \
                    port:libiconv \
                    port:gawk \
                    port:p${perl5.major}-text-csv_xs \
                    port:juman6 \
                    port:knp3

use_configure       no

variant universal   {}

pre-build {
    copy ${filespath}/Makefile ${worksrcpath}
}

post-patch {
    foreach script {extract.sh makemdl.sh lib/in2tsv.pl lib/tsv2out.pl \
                    makemodel/csv/csv2tsv.pl makemodel/csv/csv2tsv.sh} {
        reinplace "s|@PERL@|${perl5.bin}|" ${worksrcpath}/${script}
    }
}

build.args          CC=${configure.cc} CFLAGS="${configure.cflags} [get_canonical_archflags]"

destroot {
    foreach script {_extract _train extract makemdl} {
        reinplace -locale C "s|dir=`cd \$\(dirname \$0\) && pwd`|dir=${prefix}/share/${distname}|" \
            ${worksrcpath}/${script}.sh
    }
    reinplace -locale C "s|dir=|#dir=|" ${worksrcpath}/conf.sh
    foreach script {pol/out2tsv pol/par2dat pol/tsv2par \
                        src/makefv src/otag2tsv src/out2tsv src/tsv2tag src/tsvconv \
                        typ/makefv typ/out2tsv typ/tsvconv \
                        xpr/otag2tsv xpr/tsv2tag} {
        reinplace -locale C "s|/usr/bin/gawk|${prefix}/bin/gawk|" ${worksrcpath}/${script}.awk
    }
    copy ${worksrcpath}/extract.sh ${destroot}${prefix}/bin/extractopinion.sh
    copy ${worksrcpath}/makemdl.sh ${destroot}${prefix}/bin/extractopinion-makemdl.sh
    copy ${worksrcpath}            ${destroot}${prefix}/share
}

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
