# -*- 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 89831 2012-02-12 03:25:35Z hum@macports.org $

PortSystem          1.0

name                mecab-base
version             0.993
categories          textproc japanese
platforms           darwin
maintainers         gmail.com:rsky0711 hum openmaintainer
license             GPL-2 LGPL-2.1 BSD

homepage            http://mecab.sourceforge.net/
description         yet another part-of-speech and morphological analyzer
long_description    The base analyzer of MeCab, ${description}.

dist_subdir         mecab
distname            mecab-${version}

master_sites        googlecode:mecab
checksums           rmd160  639b8a278ab4387b4760453400db95034428d3d1 \
                    sha256  d0c454956bec38e68ad16969ef353729a93b51b578f2e8247b16628e16f63426

depends_lib         port:libiconv

patchfiles          patch-configure.diff

configure.args      --mandir=${prefix}/share/man \
                    --with-libiconv-prefix=${prefix}

test.run            yes
test.target         check

set dest_mecab      ${destroot}${prefix}/share/mecab
set dest_doc        ${dest_mecab}/doc
set dest_example    ${dest_mecab}/example

post-destroot {
    # set the default dictionary path to sysdic.
    reinplace s|ipadic|sysdic| ${destroot}${prefix}/etc/mecabrc

    # install doc and example.
    file mkdir ${dest_doc}
    eval xinstall -m 644 [glob ${worksrcpath}/doc/*.html] ${dest_doc}
    eval xinstall -m 644 [glob ${worksrcpath}/doc/*.png]  ${dest_doc}
    eval xinstall -m 644 [glob ${worksrcpath}/doc/*.css]  ${dest_doc}
    copy ${worksrcpath}/doc/doxygen ${dest_doc}
    copy ${worksrcpath}/doc/en      ${dest_doc}
    copy ${worksrcpath}/example     ${dest_example}
}

# deactivate any old mecab port.
pre-activate {
    if {[file exists ${prefix}/bin/mecab]
        && ![catch {set vers [lindex [registry_active mecab] 0]}]
        && ([vercmp [lindex $vers 1] 0.98] < 0 ||
            [vercmp [lindex $vers 1] 0.98] == 0
            && [vercmp [lindex $vers 2] 1] < 1)} {
        registry_deactivate mecab "" [list ports_nodepcheck 1]
    }
}

platform darwin 8 {
    configure.env-append    MACOSX_DEPLOYMENT_TARGET=10.4
}

variant utf8only description {Build with UTF-8 only} {
    configure.args-append   --enable-utf8-only
}

variant dartsclone description {Use darts-clone instead of darts} {
    post-patch {
        # darts.h is taken from http://darts-clone.googlecode.com/files/darts-clone-0.32g.tar.gz.
        copy -force ${filespath}/darts.h ${worksrcpath}/src
    }
}

livecheck.type      regex
livecheck.url       http://code.google.com/p/mecab/downloads/list
livecheck.regex     {mecab-([\d\.]+)\.tar}
