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

perl5.branches      5.28 5.30 5.32 5.34
perl5.setup         TermExtract 4.11
categories-append   textproc japanese
maintainers         nomaintainer

description         a Perl module to extract technical terms from texts
long_description    ${name} is ${description}.

homepage            http://gensen.dl.itc.u-tokyo.ac.jp/termextract.html
platforms           darwin
license             Permissive

master_sites        http://gensen.dl.itc.u-tokyo.ac.jp/soft/
checksums           rmd160  3e0a959facb94021f6c02deb87759097773c2ce5 \
                    sha256  5810ac304cd646efd39b5a4db2b52090fb7f300160589373afc091dbacd3285b

distname            ${perl5.module}-[strsed ${perl5.moduleversion} {g/\./_/}]

depends_build       port:nkf

if {${perl5.major} != ""} {
    post-extract {
        # create TermExtract/JapanesePlainText.pm and SampleScripts/UNIX/ex_JPT.pl for UTF-8.
        copy ${worksrcpath}/TermExtract/JapanesePlainTextEUC.pm \
             ${worksrcpath}/TermExtract/JapanesePlainText.pm
        copy ${worksrcpath}/SampleScripts/UNIX/ex_JPTE.pl \
             ${worksrcpath}/SampleScripts/UNIX/ex_JPT.pl
    }
    
    patchfiles-append patch-utf8.diff

    post-patch {
        # convert SampleScripts/UNIX/ex_{chasen,mecab,JPT}.pl for UTF-8.
        foreach f {ex_chasen.pl ex_mecab.pl ex_JPT.pl} {
            system -W ${worksrcpath}/SampleScripts/UNIX "nkf --in-place -w ${f}"
        }
        # fix perl path.
        foreach f [glob ${worksrcpath}/TermExtract/*] {
            reinplace -locale C "s|/usr/local/bin/perl|${perl5.bin}|g" ${f}
        }
    }

    post-destroot {
        # install sample scripts.
        set scripts_dir ${destroot}${prefix}/share/termextract
        copy ${worksrcpath}/SampleScripts/UNIX ${scripts_dir}
        foreach f [glob ${scripts_dir}/*] {
            reinplace -locale C "s|/usr/local/bin/perl|${perl5.bin}|g" ${f}
            file attributes ${f} -permissions 0755
        }
        # install documents.
        xinstall -d ${destroot}${prefix}/share/doc
        set doc_dir ${destroot}${prefix}/share/doc/termextract
        copy ${worksrcpath}/HTML ${doc_dir}
        foreach f [glob ${doc_dir}/*] {
            system -W ${scripts_dir} "nkf --in-place -w ${f}"
            reinplace -locale C \
                "s|<head>|<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />|" \
                ${f}
        }
    }
    livecheck.type      none
} else {
    livecheck.type      regex
    livecheck.url       ${homepage}
    livecheck.version   [strsed ${perl5.moduleversion} {g/\./_/}]
    livecheck.regex     ${perl5.module}-(\[0-9_\]+)\\.
}
