# -*- 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 107036 2013-06-15 12:20:52Z hum@macports.org $

PortSystem          1.0
PortGroup           perl5 1.0

perl5.branches      5.8 5.10 5.12 5.14 5.16
perl5.setup         TermExtract 4.10
categories-append   textproc japanese
maintainers         hum openmaintainer

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  8c4138fca3ba68a799e45d199d6f3c7dec1e95aa \
                    sha256  f07172277c913061810b82360586ba09eafaa80c2494c46ed625b401972e1f98

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_\]+)\\.
}
